forums

TNT Basic Forums > Programming Q&A
Collisions, collisions, collision...
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-12-2002 13:57

Posted by:
ERaZer

Click Here to Email ERaZer   Find more posts by ERaZer

I think its good that you wrote a tutorial on collisions, but sprite collisions in TNTBasic is pretty easy to use... And I'm having trouble doing good tile collision, it just turns out like crap. Couldn't someone write a tile collision tutorial or just post some useful code?

01-12-2002 14:28

Posted by:
Jim D

Click Here to Email Jim D   Find more posts by Jim D

tile collisions

Hi EraZer, I don't know if this will help you any but it is how I have approached tile collisions. It might not be much help if you're making a platform game, but who knows. I don't have any succint code examples, but basically what I have done is take advantage of tile layers.

In the level editor, I have made two layers for each map. The first is a regular layer with tiles for grass, dirt, etc. I use this layer to make the appearance of the level. This is the only layer that I draw using 'draw map section.' (note the layer parameter of that command)
The second layer, however, is my 'passability' layer. I just have one tile in it, which I place wherever the character should be blocked from going. (I'm making a top-down kind of adventure game). What I do is trace walls and other solid objects in the appearance level with this tile in the passability level, which is never actually drawn - just in memory when the map is loaded.

Then, when I move my character around, I always check the passability layer using the Map Tile command before actually moving to make sure that there are no obstructions. (Actually I suppose you could have multiple tiles in the passibility layer, indicated varying degrees of passability - like marshes, mountains, etc). The first layer is numbered 0, the second numbered 1, and so on, I believe.

Does that make sense? Sorry I don't have any good code examples. I'm not exactly sure if this is what you mean by tile collisions, but hopefully it will help out somehow.

01-13-2002 00:14

Posted by:
Mark Tully

Find more posts by Mark Tully

Tile info methods

I see what you're doing with the 2 layered maps there Jim, that's a good idea.

Another approach that just occurred to would be to have an array of tile passabilities in your program, indexed by the tile number.

Eg.
int gTilePassability[kMaxNumberOfDifferentTiles]

Fill this array out at your program initialisation stage for all the different tiles in your game, use a special value (say 0) to mean non passible, 10 to mean totally passable and values inbetween to mean grades inbetween (for marshes etc).

In your game you can then access this so:

passability=gTilePassability[Map Tile(x,y,0)]

This way you only have to edit one layer in your map so you won't have to keep your passability later in sync with the map layer. This might save time and make it easier to edit.

Hope this helps!

Mark

01-13-2002 02:15

Posted by:
Jim

Click Here to Email Jim   Find more posts by Jim

That's a good idea too, it's probably more efficient as well.

Just out of curiosity, what else can be done with map layers? I suppose I could figure out other uses, but I'm just wondering if there was some specific purpose they were implemented for.

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.