• Advertisement

Archived

This topic is now archived and is closed to further replies.

Objects... yes I know this is common question...

This topic is 5152 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

well, I have a problem :D I''m making a 2D ISOMETRIC game, and my question is how to store objects, and how to display them. lets say I have a tree, and I want him to be in Tile[x][y] but the picture file is larger then 1 tile, and the area that is blocked is 1 tile... so how should I do this, how should I know which tiles to block for each object, and where is the origin of the picture should be?

Share this post


Link to post
Share on other sites
Advertisement
Make a TreePart class, which can be contained within a Tile (along with all the other Tile contents, like information about the terrain, items etc.). TreePart instances would have to contain information about what part of the tree image should be drawn in that Tile.

To check for the character bumping into a tree, check if there are any TreeParts in that Tile.

To add a tree to the map, you need to add all the appropriate TreeParts to the right cells. Assuming you have a rectangular image (m by n tile) and square tiles, this is just a matter of a couple nested loops, something like:

for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
theMap[i+woffset][j+hoffset].add(new TreePart(i, j));
}
}

Share this post


Link to post
Share on other sites
If you treat your tree/objects like any other sprite, i.e. a player or npc, then it will have it''s own collision area. If your sprites are all derived from a single sprite class then this is where inheritance will help out immensly. The way I do it is each one of my tiles has a linked list of sprites on it and since my tiles are stored in a 2d array, I can limit my collision check to the objects within a 2-3 tile radius of the sprite trying to move without much hassle. Another option for things like trees is to use a series of tree tiles that just don''t allow player movement on them at all where the base of the tree is not walkable and use an overlay for the top of the tree to create the illusion of a solid object. I am pretty sure that this is how most older 2d games handled tree like objects but it can be a hassle in the level design stages of things.


Evillive2
E-Mail

Share this post


Link to post
Share on other sites
The simplest way is to just allow your tree sprite to be larger than one tile and simply draw the tree last. This way the NPC will be able to walk behind the top of the tree but not through the base - as the base of the tree is actual tree tile location and this tile will have a flag that describes that NPC''s can not walk into it (like a wall). By allowing NPC''s to walk behind objects you are increasing the depth of your graphics and its a very easy technique to do.

http://www-cs-students.stanford.edu/~amitp/Articles/Tiletech.html

This article solves your problem and also explains using linked lists in map creation which is a great format to use if you havent experimented with it already. The article is written for a top-down 2D game (I think Ultima VI is referenced) but the techniques will port to 2D isometric.

Share this post


Link to post
Share on other sites

  • Advertisement