Using tiles for more than just maps?

Started by
1 comment, last by game of thought 11 years, 7 months ago
I wanted to see what you thought of my idea for a tile engine. Would it be possible to make the individual tiles instances of a worldwide tile class?

Eg say you have a map with walls and floor, these both inherit from the base tile class and do certain things like load their picture and run a separate collision sub routine within the class to check if the characters Or enemies etc have hit it and then perhaps have collision logic within the class ( so like you hit a wall the collision logic would be not to allow you to move through the wall).

Would this put to much strain on system resources or would it be difficult to implement. If there is also an already made engine with something like this already implemented please let me know.

Thank you for your time
Advertisement
its not a good idea to keep a copy of the sprite that each tile represent instead you want to keep just a index of the tiles, what you should do its create a class that works like an atlas and load all the sprites once so you keep just 1 copy of the img, also its not a good idea to test collision against all the currents tiles in the map.

for example if you are going to make the map SIZEX and SIZEY and lets say that you have N tiles images stored in an class call obj.

the class obj could load all the imgs and keep them in a vector or an array for example.

vector<obj> images;

the map is an array of for example short map[SIZEX*SIZEY];

each slot of the array will represent an index to the atlas images array,

lets say that the first tile is grass ID 0 second dirt ID 1 and stone ID 2

the map should be {0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,2,2,2,1,1,1,0,0...

at the moment of rendering the map you will just get the current index in the map and get the image from the atlas with that index.

regarding collision as a said not a good idea to test all the map

read this topic, i alrdy posted something related to collision

http://www.gamedev.net/topic/630073-map-coordinates/
Thanks

This topic is closed to new replies.

Advertisement