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

Username:   Password: 
 RegisterRegister   
 Make a Char Jump
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MiX-MaztA-M8riX




PostPosted: Thu Jan 19, 2006 10:47 pm   Post subject: Make a Char Jump

Hey, sorry for the slew of posts, but I'm in a real time crunch with the whole Final Project thing.

ok, so I'm doing a side scroller type project, and I want to make my jump a lot more than just

code:

for iy : y .. y+50
Draw.FillBox (x,iy,x+15,iy,255)
end for

for decreasing iy : y + 50 .. y
Draw.FillBox (x,iy,x+15,iy,255)
end for


Chances are that doesnt even work, but you get my point. I'm trying to figure out a way to make it more, mathematically calculated. The only catch is I have no idea how to use angles in turing, if anyone out there can explain how to jump normally instead of crappy diagonals all the time. They look horrible, and I want to avoid them at all costs. So please, any help would be greatly appreciated.

Cheers!
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Jan 19, 2006 10:56 pm   Post subject: (No subject)

Forces! Vertical acceleration upwards from the jump against vertical acceleration downwards due to gravity.

Though in essance you end up with a -(x^2) type of graph.

code:

-(x^2 - (time/2) ) + maxHeight

where maxHeight is the maximum height your character will reach and time is the duration spend in the air
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
codemage




PostPosted: Fri Jan 20, 2006 10:33 am   Post subject: (No subject)

You probably won't be able to do it with for loops.

In your main loop
when you jump,
- disable jumping
- add a specefied height to your y location
then keep adding that value (minus gravity)
eventually that value will become negative (since you're subtracting gravity from it each time)
....even more eventually, your character will hit the ground, at which point
- you stop adding the height variable to your character
- you re-enable the jump key
MiX-MaztA-M8riX




PostPosted: Fri Jan 20, 2006 2:26 pm   Post subject: (No subject)

Hey Tony, I'm not sure if that was supposed to make complete sence or not, but I'm not sure I'm getting that. Also, what's with the use of time? I'm not too firmiliar with it.
Drakain Zeil




PostPosted: Fri Jan 20, 2006 4:33 pm   Post subject: (No subject)

There's all sorts of things you can do for gravity. Also, I posted a tutorial on angles just yesterday.

So, for example, you could increment a dot by a value of:

increment value by (Distance(A,B))

But that will move A slower towards B, so, instead, try something like inverting that:

decrement value by (Distance (A,C))
Where C would be a point opposite to that value, perhaps some where up in the sky. This would make objects get slower as they go towards the sky, and speed up as they go back down again.

Also, for true physics, you can use the d=v*t formula (distance, speed, time), and change the V value as acceleration dictates, t as time goes on, and d just becomes the product of the two, so use that value to change distance.

Btw. Gravity acceleration is on average 9.8 m/s on earth, which doesn't mean much on your screen unless you have something you can relate to a meter. (And again, if you don't, just use that first thing I said)

Actually... now that I think about it... years ago I made a pong game in flash, and the paddles got slower as they closed in on the mouse position, what I did for that is:

Get closer to the pointer, by subtracting (pointer - paddel), then divide that distance by 5, to make a nice "speed gradient"
Cervantes




PostPosted: Fri Jan 20, 2006 4:56 pm   Post subject: (No subject)

There's a lot of code in this jumping thread that you will probably find useful.
MiX-MaztA-M8riX




PostPosted: Fri Jan 20, 2006 5:27 pm   Post subject: (No subject)

Thanks for the info!, and for the Link Cervantes! Oh, and btw, thats the best Avatar ever Wink

Rock On The Penny! Laughing
MiX-MaztA-M8riX




PostPosted: Fri Jan 20, 2006 9:49 pm   Post subject: (No subject)

Ok, more troubles! I followed some of your help (what I understood) but I can't seem to get my dude to sotp, you can 'fly' just by holding the jump button. So is there a way to disable the input of a button (or something along the lines of that) until he lands? cheers!
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Jan 21, 2006 10:54 am   Post subject: (No subject)

Only allow the object to jump if there is some ground below him. You'll need to do some collision detection to determine if he's on the ground.
MiX-MaztA-M8riX




PostPosted: Sat Jan 21, 2006 3:42 pm   Post subject: (No subject)

code:

process Jump
    if jump = true and whatdotcolor (round (x), round (y - 2)) not= 255
            then
        for i : 1 .. 20
            y += Grav
        end for
        jump := false
    end if
end Jump


Something like that, cuz it doesnt seem to work? O_o
Tony




PostPosted: Sat Jan 21, 2006 10:02 pm   Post subject: (No subject)

Quote:

for i : 1 .. 20
y += Grav
end for

you're going nowhere but up from there Confused And it's in a process Naughty

you need a variable for vertical acceleration. When your character jumps, vertical acceleration is set to the power it jumps with, each time through the loop gravity is added to acceleration variable, so if gravity is 10 and power is 20, it will take gravity 2 steps to catch up and start pulling you down:

step | v_acc | height
-----+--------+--------
0 20 0 // jump from the ground
1 10 20
2 0 30 //
3 -10 30 // top of the arch
4 -20 20
5 -30 0 // back on the ground
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: