forums

TNT Basic Forums > Programming Q&A
Tile collision (woo-hoo)
< Last Thread     Next Thread >
Author
Thread        Post A Reply

02-23-2002 03:26

Posted by:
Chris

Find more posts by Chris

I have found that this list serves it's purpose best in sometimes not answering questions:) It forces me to go fix my own darn code. So, here is a map tile collision jump n' run section (no bells or whistles, but it works and it works pretty dam fast at 50+ fps).

There's only one problem, the tile collision seems to fail on the leftmost tile of a platform. Is this a programming error on my part, or a bug in TNT basic? Well, I plan to post this to the bugs forum and let them take a look, but if anyone discovers why that happens please let me know. Otherwise, hope this helps someone with even less game programming experience than me.

'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
global int spacePressed = 0

DrawMap()

while not mouse button
DrawCharacter()

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 space and spacePressed = 0
pJumping = 1
myVelocity = 24
spacePressed = 1
end if

'while pJumping = 1
if pJumping = 1
'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
spacePressed = 0
end if
end if
'wend
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
spacePressed = 0
end if
end if


end proc

02-23-2002 10:04

Posted by:
ERaZer

Find more posts by ERaZer

I'm using something similar of that in the Saucer Wars-Alpha- example. You can check it(Saucer Wars) out at: ftp.glacial.com/TNT/Douglas/

02-23-2002 20:57

Posted by:
Tabasco Sauce

Click Here to Email Tabasco Sauce   Find more posts by Tabasco Sauce

Saucer Wars

I also found it at that new web site:

http://www.basicallyreal.com/

Go to the "Examples" page and you will find it along with some other file having some 3D stuff.

02-24-2002 01:08

Posted by:
Chris

Find more posts by Chris

RE: Saucer Wars

Looked at it last night - nice. I particularly enjoy the firing options and the bouncing shrapnel is a great touch. When are you going to add an option to play against seven computer players, for those of us who don't have friends that stay up past 11?

I looked at the source but did not see anything that might help with my own code. Part of that may have been that it was a little difficult to follow :) I don't suppose you would take a moment and upload a really well commented section of your collision detection code? Anyway, thanks again.

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.