Skip to main content
gamedev.net
🔒 Locked

tile based game

Started by eon85 5 replies 1.4k views
Original Post
eon85
eon85
im creating a tile based game for my final year collage project and i was wondering a couple of things. 1.would it it best to use a class for each tile? 2.should each map which is made of loads of tiles be hard coded? and if not what would a practical way of creating a map? this project has to coded myself and so the use of a game engine is out.thanks for your help in advance.
ToohrVyk
ToohrVyk
1° Not really. Individual tiles seldom have properties of their own that are worth abstracting in base classes. I would suggest that you use a single class for all the static objects (tiles) in your world, and specific classes for special objects (player, enemies, items, hazards), including the tile(s) on which these objects reside.

2° You can create a tile editor fairly easily in any language, either in-game or as a separate program. Simply create a way to store the map in a file and the functions to save/load it, and you'll be set.

Depending on what your map looks like you might include different capabilities in your editor: Warcraft 3 tiles alter all nearby tiles when you place them (because you can't have grass next to water, you need a cliff in-between), Starcraft tiles are even worse (since they simulate a 3/4 isometric onlook), but RPGMaker tiles are placed as batched which are drawn to be assembled together.
Quasimodem
Quasimodem
More thoughts -
1. My game has a base Tile class from which all in-game objects extend; the player, the background, enemies, rocks, trees, etc are all Tiles. This makes all objects equally scriptable, everything can be moved, scaled, pushed, pulled, rotated, color changed, etc without special consideration. If you do need special behavior for a certain object, you can overwrite the base function and away you go! Inheritance is extremely powerful.

2. Definitely don't hardcode your maps. Come up with some format to store them in; XML works great though is easy to hack, some binary format might be better. For example, my scripting engine can add objects to the world and set all their properties, so I do store my maps in XML (yes, easy to hack) and then when I want to load them, I use an XSL stylesheet to transform them into a script file, which I then execute. VIOLA, instantly loaded map!
eon85
eon85
Quote:
Original post by ToohrVyk
1° Not really. Individual tiles seldom have properties of their own that are worth abstracting in base classes. I would suggest that you use a single class for all the static objects (tiles) in your world, and specific classes for special objects (player, enemies, items, hazards), including the tile(s) on which these objects reside.


so lets say im trying to create a tile with the player on it this would require two different sprites one for the landscape and another for the player how would you go about overlaying the sprites?
eon85
eon85
Quote:
Original post by Quasimodem
2. Definitely don't hardcode your maps. Come up with some format to store them in; XML works great though is easy to hack, some binary format might be better. For example, my scripting engine can add objects to the world and set all their properties, so I do store my maps in XML (yes, easy to hack) and then when I want to load them, I use an XSL stylesheet to transform them into a script file, which I then execute. VIOLA, instantly loaded map!


how exactly? do you store locations of all items/hazards/npcs/tile type in the xml sheet and then load into a grid which is displayed?
rasher_b2
rasher_b2
Quote:
Original post by eon85
Quote:
Original post by ToohrVyk
1° Not really. Individual tiles seldom have properties of their own that are worth abstracting in base classes. I would suggest that you use a single class for all the static objects (tiles) in your world, and specific classes for special objects (player, enemies, items, hazards), including the tile(s) on which these objects reside.


so lets say im trying to create a tile with the player on it this would require two different sprites one for the landscape and another for the player how would you go about overlaying the sprites?


Your tiles and your player should all be seperate entities so to draw the player over any tile it's just a matter of having your code paint all the tiles and then paint the player sprite after them.
Quasimodem
Quasimodem
Quote:
Original post by eon85

how exactly? do you store locations of all items/hazards/npcs/tile type in the xml sheet and then load into a grid which is displayed?


Yup, you got it! I decided to not use a grid at all, my background is simply a big bitmap and each Tile stores its own coordinates within that background. So, my save file format looks something like:

<world texture="background.bmp">
<tile name="player" x="10" y="10" texture="player.bmp"/>
<tile name="monster" x="100" y="100" texture="monster.bmp" onBump="fight.script"/>
<tile name="treasure_chest" x="200" y="500" texture="chest.bmp" onGet="get_treasure.script"/>
</world>

There are vastly more complicated and efficient ways of doing things but goddamn I figure, when you are flying solo you'd better keep it simple or you will spend a year writing the Perfect Save Format and that is a Sucky Game.

Topic Locked

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

Sign in to reply to this topic.