Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Jumping Ball
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Paul




PostPosted: 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 Wink


ex.t
 Description:

Download
 Filename:  ex.t
 Filesize:  1.89 KB
 Downloaded:  309 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: 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:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: