tile based skeleton

Started by
3 comments, last by Maxamor 17 years, 10 months ago
Hi, I need advice about class "architecture" for a basic tile based game. I imagined the following, but I need some expert to tell me if this could be a good design and what can be improved (no AI* is required). That is: could you tell me which methods should I add? Class dataLoader - method: loadData Class Map - method: buildMap(mapArray); - method: getMapHeight; - method: getMapWidth; Class Tile - method setTile; - method getTile; Class Character: - method setCharacter; - method walk(direction); Thanks :-)
Advertisement
If your character is bigger/smaller than the tiles and/or doesn't move a tile at a time, you'll want to have a four corners collision routine to see if your player is colliding with a wall.
Instead of having a "Character" class, it might be better to have an "Entity" class, and then derive "Character" from it. This will mean that if you want to implement an object that's not stuck to a tile, you could implement a "Object" class to also derive from Entity.

Another thing to consider is will your Tile class represent an individual tile in your map, or a representation of a tile type? If it's a tile type, you'll want to declare Tile as a struct instead as it should be a value and not an object.
Rob Loach [Website] [Projects] [Contact]
Hi, first of all thanks.
I forgot to mention I planned to do this with JAVA.

@Ravuya

The character would have the same size of the tile and would move cover an entire tile with one move. I imagined the character class checking for collision in the walk method (is it a bad idea?).

@Rob Loach

The Tile class would create instances of tiles, it would be a tile-type "factory" too.
Ok for the Entity.
Question for Rob:

I'm wiring a 2d tile-based game in C#. I'm currently implementing my tiles as structs. Can you elaborate more on the reason one would use structs instead of classes for Tiles?

Wouldn't having an array of pointers to classes be better than an array of copies of structs?

If I'm understanding this wrong, let me know.

This topic is closed to new replies.

Advertisement