Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / 2D Sprite Jumping

Author
Message
fizgog
21
Years of Service
User Offline
Joined: 3rd Oct 2002
Location:
Posted: 29th Jul 2003 21:27
How to make a sprite jump

keys :- cursors = left and right, space = jump, ESC quit
Gosila
20
Years of Service
User Offline
Joined: 30th Jul 2003
Location:
Posted: 31st Jul 2003 06:29
Hey, this is john from Uruguay (AKA Gosila).
This is the way I use:

1)Get the sprite frames (images) like you want to do.

2)Before your main game loop set some variables like:
player_x=100
player_y=100
vx(velocity on X axis)=0
vy(velocity on Y axis)=0
ay(acceleration on Y axis)=0

3)In your main game loop, assign a key to the jump action, and make something like this:

"if keystate(let's say 21, wich is "Y" key)=1 then vy=-10:ay=1"

then, you'll need to make a label called (let's say) Update_Var:
and there you'll have to put these lines:

"x=x+vx"
"vy=vy+ay"
"y=y+vy"

so, on your main game loop, before you check the keys to see if player wants to move or jump, you make a GOSUB to that Update_Var

before that GOSUB line, you'll have to put an IF line like this:

"IF vy>10 then vy=0:ay=0"

and then you'll have to put your sprite image according to x, and y.
like:

"SPRITE 1,x,y,frame"

The animation on your jump could be made according to the values of "vy", so if you have 4 frames of animation to jump, you should do something like this:

before the sprite line, make some IF sentences like:
IF vy=-10 or vy=-9 or vy=-8 then frame=something...
IF vy=-7 or vy=-6 or vy=-5then frame=something...
IF vy=-4 or vy=-3 or vy=-2then frame=something...
and so...

I hope this helped, if it does, let me know at:john_repetto_666@msn.com

Login to post a reply

Server time is: 2024-04-24 11:17:55
Your offset time is: 2024-04-24 11:17:55