forums

TNT Basic Forums > Programming Q&A
Collision with Tiles
< Last Thread     Next Thread >
Author
Thread        Post A Reply

12-15-2001 20:46

Posted by:
Belsebub

Find more posts by Belsebub

I'm making a simple platform scrolling game(Ya know, Mario), and I'm trying to implement collision handeling with tiles but I'm having problems with that. Could someone make an example(just a sprite that you can control and collision handeling with tiles(simple)) or post some code for this?

12-20-2001 19:39

Posted by:
Jon

Click Here to Email Jon   Find more posts by Jon

Re: Collision with Tiles

Here is the code I am using. It only lets you stand on stuff, and doesn't stop you from passing through things. The code to do that stuff should be very similar though.


'---What is Char Standing On?-----

int ytemp=yCharPos/32
if yCharPos-(ytemp*32) <= yCharVel
if Map Tile((xRelPos-8)/32,yCharPos/32,0) or Map Tile((xRelPos+8)/32,yCharPos/32,0)'If Standing on something
CharStand=Map Tile(xRelPos/32,yCharPos/32,0)-11 'What is char standing on
if CharStand<0 or CharStand>kTileTypeNum
CharStand=0'Don't allow tile types that don't exist
if not (left or right) and abs(xCharVel)<1.0 then xCharVel=0 'In case standing on edge
end if
yCharPos=ytemp*32 'Make sure char is standing on TOP of tile
end if
end if


Hope that helps (and didn't come out all funky from the email). Let me know if you need me to clarify something.

Thanks,
Jon

12-20-2001 23:03

Posted by:
Jon

Click Here to Email Jon   Find more posts by Jon

Re: Collision with Tiles

Here is the code I am using. It only lets you stand on stuff, and doesn't stop you from passing through things. The code to do that stuff should be very similar though.


'---What is Char Standing On?-----

int ytemp=yCharPos/32
if yCharPos-(ytemp*32) <= yCharVel
if Map Tile((xRelPos-8)/32,yCharPos/32,0) or Map Tile((xRelPos+8)/32,yCharPos/32,0)'If Standing on something
CharStand=Map Tile(xRelPos/32,yCharPos/32,0)-11 'What is char standing on
if CharStand<0 or CharStand>kTileTypeNum
CharStand=0'Don't allow tile types that don't exist
if not (left or right) and abs(xCharVel)<1.0 then xCharVel=0 'In case standing on edge
end if
yCharPos=ytemp*32 'Make sure char is standing on TOP of tile
end if
end if


Hope that helps (and didn't come out all funky from the email). Let me know if you need me to clarify something.

Thanks,
Jon

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.