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.

2D All the way! / Jumping Sprite in 2D Game

Author
Message
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 23rd Mar 2005 06:19 Edited at: 27th Mar 2005 00:15
(I changed the code since I've been working on it)
Help! I'm trying to make a 2D scrolling game and have things under control for the most part except I don't know how to make a sprite jump. Also, when I'm able to jump, how do you make a mario-type attack were the enemies are destroyed only when you hit the top of them.
Here's my code:

sync on
sync rate 40
a=4
b=100
c=500
d=345
x=0
y=0
load sound "world1.wav",2
load image "level1w1.bmp",1
load image "squid3.bmp",2
load image "robosquid.bmp",3
load image "healthbar.bmp",5
load image "squidhealth.bmp",4
load image "gameover.bmp",6
Sprite 1,x,y,1
Size Sprite 1,2500,500
Set Sprite 1,1,1
Sprite 3,500,345,3
Size Sprite 3,100,110
Set Sprite 3,1,1
Sprite 2,50,345,2
Size Sprite 2,100,110
Set Sprite 2,1,1
Sprite 4,0,0,4
Size Sprite 4,80,90
Set Sprite 4,1,1
Sprite 5,75,27,5
Size Sprite 5,b,30
Set Sprite 5,1,1
SET CURSOR 560,2
print "Lives="
SET CURSOR 610,2
print a
play sound 2
loop sound 2
Do
Sprite 2,50,d,2
Size Sprite 2,100,110
Set Sprite 2,1,1
If x>0:x=0:endif
If b=0
Sprite 6,270,190,6
Size Sprite 6,100,30
Set Sprite 6,1,1
stop sound 2
Sleep 3000
GOTO Label2
ENDIF
if sprite hit(2,3) > 0
dec b,10
Sprite 5,75,27,5
Size Sprite 5,b,30
Set Sprite 5,1,1
ENDIF
if sprite y(2) > sprite y(3)
hide sprite 3
ENDIF
if upkey()=1 then d=300
if downkey()=1 then y=y+0
if leftkey()=1 then x=x+3
if leftkey()=1 then c=c+3
if rightkey()=1 then x=x-3
if rightkey()=1 then c=c-3
Sprite 1,x,y,1
Size Sprite 1,2500,500
Set Sprite 1,1,1
Sprite 3,c,345,3
Size Sprite 3,100,110
Set Sprite 3,1,1
sync
loop

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 23rd Mar 2005 06:35
Oh and how do you make an enemy move?

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
Kentaree
23
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 23rd Mar 2005 17:40
Right, I see a problem with your code immediatly, and that is that your jump routine is in a for loop. This means that when you jump, nothing else that the game usually does will happen until the jump is finished, which might look very weird.

I'd advise you to check whether a jump is going on, and if so, in each loop, decrease the y value a bit.

With regards to collision, if you know where the enemy sprite is, you can compare your character's x and y position to it in a jump. If the x coordinate is close to the enemy's and the y coordinate is higher than the enemy's by the height of your character, you're on top of it, and so the enemy dies.

To make the actual sprite jump, you reposition it using a different y position.

So where you'd have sprite spriteNo, x, y, imageNo
you'd change the value of y to position the sprite vertically.

Desktop: AMD Athlon XP2800+,Radeon 9800 128MB, 1GB DDR RAM
Laptop: AMD Athlon 64M 3000+,Mobility Radeon 9700 128MB, 512MB DDR RAM
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 26th Mar 2005 10:16 Edited at: 27th Mar 2005 00:17
I can reposition it but it just stays up at the y position. =( Also, how do you make enemy sprites move on their own?

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
Nigel _Okgo
21
Years of Service
User Offline
Joined: 30th May 2005
Location:
Posted: 30th May 2005 08:21
in reply to how do you make a mario jump attack?
to keep it simple, use code like this say for example the enemy is

mx for the x position and my for the y position here is what you do,
and it may be faster than standard sprite collision detection....

also explained here, jumping collision detection....

perhaps your main character is x position and y position....

if jump=0 your charcater's y position on screen is static....
if jump=1 then your character is jumping up so many pixels so you set a timer to about 20 and make jump=2 again,
then your character falls again,
if inkey$()=" " then jump=1
rem (Pressed Space bar Jump activated)
if jump=1 and tmr<20 then tmr=tmr+1:y=y-4:if tmr=20 then jump=2
if jump=2 and tmr>0 then tmr=tmr-1:y=y+4:if tmr=0 then jump=0

if x>mx-20 and x<mx+20 and y>my-40 and y<my and jump=2 then goto (the jumped on enemy collision line) goto splat for example!

experiment with the amount of pixels though may take some testing for accurate collision but it should work....
so if your y position is greater tha

Login to post a reply

Server time is: 2026-07-14 00:27:29
Your offset time is: 2026-07-14 00:27:29