Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Jumping Ball
Author Message
Paul

Posted: Fri Oct 29, 2004 3:14 pm   Post subject: Jumping Ball

A person in my class was trying to get a ball to jump with gravity and shit, so I made this in 15-20 min. Not great coding, but yea... w/e. The gravity is set to -0.2 right now, you can change it for observation. But basically when u jump (ctrl) it gives the ball an initial velocity, and gravity is acting on the ball at all times anyhow. I've gotten a crude bottom side collision detection in. But I'm too lazy to expand on this. If anyone can improve/ exand on this code, I'd like to see the results or w/e. But this was basically a demonstration to my classmate. Just press control to jump

ex.t
Description:
Filename:  ex.t
Filesize:  1.89 KB

Cervantes

Posted: Fri Oct 29, 2004 6:03 pm   Post subject: (No subject)

nice work paul. Pretty good, for such a short time.
Here's a simple function I wrote for collision detection, again, using whatdotcolour.

 code: function ground_collision (x1 : int, y1 : int, obj_width : int, check_under_obj : int, ground_colour : int) : boolean         for xcheck : x1 .. x1 + obj_width %from the left edge of the pic to the right edge         for ycheck : y1 + check_under_obj .. y1             if whatdotcolour (xcheck, ycheck) = ground_colour then                 result true             end if         end for     end for         result false end ground_collision

check_under_obj is intended to be the y velocity of the object, which, since you're checking to see if it hit the ground, should be a negative value.

also, since you're ball doesn't fall down when he moves off of the ground (he doesn't fall when he runs off a cliff), you could do something like the following:
use the above function in an if statement such as:
 code: if ground_collision (parameters, blah, blah, blah) = false then     jump := true end if

this causes the jump sequence to be initiated, and causes gravity to come into play. The only thing is that you'd have to move ballv := 8 into the if chars (key_ctrl) statement:

 code: if chars (KEY_CTRL) then         jump := true         ballv := 8     end if

Cheers!
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 2 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: