Skip to main content
gamedev.net
🔒 Locked

Tile Game Objects HELP!

Started by arwez Oct 2, 2000 at 4:07 PM 4 replies 200+ views
Original Post
arwez
arwez
Ok, I finally found out that I need to learn how to make objects in a tile based game. How do I define an object and how do I detect collisions with the objects and the map? I did it like this, but not sure if it''s the best: typedef struct { int tileid; RECT boundrect; }tileobj; tileobj [10][10]; char map[10][10]; so while I blt I read in the rects and ids into the tileobj array. I blt using the map array. And to detect collision I go if IntersectRect(tileobj[2][2].boundrect,playerrect) { player stop moving; } This only detects collision for one tile and it seems I''m gonna need a lot of if statements to detect collisions for a whole map! Please give me suggestions and source code. I need to know the basics of objects and coords. I am very confused as to what to do. THX!
mr_jrt
mr_jrt
If you're not too worried about the complications that WILL come soon enough, I worked for ages on the principle of:

        
typedef struct _Tile
{
int ID;
}Tile;

typedef struct _Player
{
int X;
int Y;
}Player;


Tile World[30][30];
Player Link; //Yes, from Zelda

...
if (Key_Left && (World[Player.X - 1][Player.Y].ID != BLOCKAGE))
Player.X--;
if (Key_Right && (World[Player.X + 1][Player.Y].ID != BLOCKAGE))
Player.X++;
if (Key_Up && (World[Player.X][Player.Y--].ID != BLOCKAGE))
Player.Y--;
if (Key_Down && (World[Player.X][Player.Y++].ID != BLOCKAGE))
Player.Y++;
...

and so on.

This will work fineas long as the player move a whole tile at a time (e.g. if the tiles are 32 pixels square, the player needs to move 32 pixels a go). Don't worry about bounding boxes until you need to have the player move smoothly over the tiles, but that comes after you can work with tiled principles happily.

Hope this helps you.



Waassaap!!

Edited by - mr_jrt on October 2, 2000 10:40:20 PM
Waassaap!!
mr_jrt
mr_jrt
It didn't get too far with it, I was using it as an applied way of learning c++/directx. I got to point where I just couldn't put off having to add monsters into the game, but beacuse I hadn't designed the game from the outset with them in mind it was a real mess, and I realised I had to re-write most of the game from scratch to bring it up to standard so it was all coherent. So I took the opportunity to start from scratch.

I can send you the .zip of the zelda game if you want so you can have a look, but I'm working on the new directx game engine/wrapper at the moment (so far I've got a versitile virtual controller input system that can map button assignments, a completely transparent win32 core, and a graphics class that can do all sorts of clever stuff), I'm optimising it now actually.

Good luck with your programming.

Waassaap!!

Edited by - mr_jrt on October 3, 2000 8:36:20 AM
Waassaap!!
CyCloNe
CyCloNe
arwez,

I would recommend you check out the Gauntlet Style Project on GameDev if you want help on all things tile-based. You can download parts of the engine which cover a whole load of topics. Trust me the code helped me understand a lot of things.
arwez
arwez
wow thx all, keep the suggestions coming

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.