forums

TNT Basic Forums > Programming Q&A
Jump n' run/Platformer question
< Last Thread     Next Thread >
Author
Thread        Post A Reply

02-21-2002 15:11

Posted by:
Chris

Find more posts by Chris

So, I've got the basic navigation for a jump n' run platform game mostly written (still need falling...) but I could use some input on the landing part of things:)

The left and right behaviors are based on the tile collision routine from the Maps discussion Mark and I were having in this forum. The jumping code works well, but when the character lands he bounces down through the tile he's landing on and I have to set his position to the top of the tile. That wouldn't be so bad, except you can see him drop into the tile and then pop back up. Any recommendations on how to have him just stop dead on the tile he's supposed to land on?

I'm posting the source for this part of the game here, but if someone can tell me where to post the actual file, I'd be happy to. This navigation scheme might help anyone working ona similar type of game (show them what not to do, perhaps...). Anyway, here's the code:

'decare some variables - character starting pos, frequently used measures, some switch variables...
Global int char_x = 32, char_y = 416
global int charWidth = 32
global int speed_x = 4, speed_y = 2
global int pMoving = 0, pJumping = 0
global int myVelocity = 0
global int myFalling = 0

'draw the map
DrawMap()

while not mouse button
DrawCharacter()

' this bit jumps the character
if space and pJumping = 0
pJumping = 1
myVelocity = 24
end if

draw frame
wend

procedure drawCharacter()

sprite 0, char_x, char_y , 1

if right
int newRightMostX = char_x + (charWidth-speed_x) + speed_x
int tileX = newRightMostX/32
int tile = map tile (tileX, char_y/32, 0)

if tile <> 1
char_x = char_x + speed_x
end if
end if

if left
int newRightMostX = char_x - speed_x
int tileX = newRightMostX/32
int tile = map tile (tileX, char_y/32, 0)

if tile <> 1
char_x = char_x - speed_x
end if
end if

if pJumping = 1
'if character going up, use this code
if myVelocity > 0
int newUpMostY = char_y - myVelocity
int tileY = newUpMostY/32
int tileX = char_x/32
int tile = map tile (tileX, tileY, 0)

else
'character going down so use this...
int newUpMostY = char_y - myVelocity
int tileY = newUpMostY/32
int tileX = char_x/32
int tile = map tile (tileX, tileY, 0)

end if

if tile <> 1
' the tile's not a wall so keep going...

char_y = char_y - myVelocity
if myVelocity > -14
myVelocity = myVelocity - 2
else
' set terminal velocity
myVelocity = -14
end if
else
'set character y coord to top of tile he lands on
char_y = tileY * 32 - charWidth
pJumping = 0
myVelocity = 0

end if
end if
end proc

02-21-2002 19:57

Posted by:
James Rhodes

Click Here to Email James Rhodes   Find more posts by James Rhodes

posting of examples

Not a problem... If you have commented your source well, which it appears you have, just email it to:

examples@basicallyreal.com

and I will post it on the site for everyone to download.

Regards,
James

http://www.basicallyreal.com/

02-22-2002 01:36

Posted by:
Chris

Find more posts by Chris

Posting of examples

Thanks for the invite James, but I would rather get the bugs worked out of the code prior to submitting it for download outside a troubleshooting forum like this one. Your site is coming along nicely though.

So, here's the code again, a bit further along. I figured out how to get the character to stop when he hits the ground (or platform) and even got the falling behiavior put together quite easily. Of course, that has introduced further problems. Now, when the character jumps and hits the bottom of a platform, as long as you hold space bar down (continue jumping) he can "hang on to" the bottom of the platform and move back and forth. Any suggestions on how to make the jump behavior non-repeatable? I tried the semi-automatic gun code from the forum, but no luck.

The second issue, and this may be a programming problem or possible a bug - when the character is moving left along the top of a platform he drops through the second half of the leftmost tile. It's like there is no collsion detected at all. Mark, any thoughts on that?

Again, and help is appreciated. Thanks. New code follows...

'decare some variables
Global int char_x = 32, char_y = 416
global int charWidth = 32
global int speed_x = 4, speed_y = 2
global int pMoving = 0, pJumping = 0
global int myVelocity = 0
global int pFalling = 1

while not mouse button
DrawCharacter()

' this bit jumps the character
if space and pJumping = 0
pJumping = 1
myVelocity = 24
pFalling = 0
end if

draw frame
wend

procedure drawCharacter()

sprite 0, char_x, char_y , 1

' move to the right
if right
int newRightMostX = char_x + (charWidth-speed_X) + speed_x
int tileX = newRightMostX/32
int tile = map tile (tileX, char_y/32, 0)

if tile <> 1
char_x = char_x + speed_x
end if
end if

' move to the left
if left
int newLeftMostX = char_x - speed_x
int tileX = newLeftMostX/32
int tile = map tile (tileX, char_y/32, 0)

if tile <> 1
char_x = char_x - speed_x
end if
end if

if pJumping = 1 and pFalling = 0
'if we're moving upwards
if myVelocity > 0
int newUpMostY = char_y - myVelocity
int tileY = newUpMostY/32
int tileX = char_x/32
int tile = map tile (tileX, tileY, 0)

if tile <> 1
'long as we don't hit a wall we keep moving

char_y = char_y - myVelocity
myVelocity = myVelocity - 2

else
'we hit something on the way up, so set our y coord to the bottom of that tile
char_y = tileY * 32 + charWidth
pJumping = 0
myVelocity = 0
pFalling = 1
end if

else
'we're moving downwards
int newUpMostY = char_y + charWidth - myVelocity
int tileY = newUpMostY/32
int tileX = char_x/32
int tile = map tile (tileX, tileY, 0)

if tile <> 1
'long as we don't hit a wall we keep moving

char_y = char_y - myVelocity
if myVelocity > -20
'decrement the velocity each time
myVelocity = myVelocity - 2

else
'set the termial velocity
myVelocity = -20
end if
else
'we hit something on the way down, so set our y coord to the top of that tile
char_y = tileY * 32 - charWidth
pJumping = 0
myVelocity = 0
end if
end if
end if

' if the character is walking but not jumping he needs to fall off of edges...
' this is basically the second half of the jumping behavior applied constantly, velocity starts at 0
if pJumping = 0
int newUpMostY = char_y + charWidth - myVelocity
int tileY = newUpMostY/32
int tileX = char_x/32
int tile = map tile (tileX, tileY, 0)

if tile <> 1
char_y = char_y - myVelocity
if myVelocity > -20
myVelocity = myVelocity - 2
else
myVelocity = -20
end if
else
char_y = tileY * 32 - charWidth
end if
end if

end proc

02-22-2002 07:06

Posted by:
James Rhodes

Click Here to Email James Rhodes   Find more posts by James Rhodes

re: web site

Thanks... :)

It has been a lot of work setting this up, but it is going to be worth it in the long run. Plus it's fun! hehehe

TNT Basic has a lot of potential and I think everyone is agreement that this is one the best BASIC programming packages out there. If Mark and John can get it up to the level AMOS (on the Amiga) was at, they are going to have a killer product. I want to see that happen...

No problem regarding your code - just send when you are ready.

Regards,
James

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.