Wednesday, October 10, 2012

Tile Models

When I implemented my basic collision detection algorithm, I had no good way of determining which tiles were blocked and which were free. So, as a temporary hack, I used the existence of one of the layers being marked 'on' to indicate that the player should not be able to move through the tile.  Of course, this is a bad idea because it couples layer configuration to model configuration--it doesn't let me put anything in that layer without that tile becoming blocked.

An alternate solution would be to instead figure out the model based on the graphics used for the tiles. For example, grass would be marked as non-blocking while rock walls would be 'blocking'. However, this is still too much coupling, since it makes things like invisible barriers--or perhaps walls you can walk through--impossible.

So, I decided to completely decouple tile models from graphics. I added a separate Model property to Tiles, which is controlled via a context menu (and copy-paste) in the editor. Currently there are only 3 model types--Empty, Solid, and Triangle (any of which can be rotated, but currently it only makes sense for Triangle).



The following video shows me walking around with no models, running the editor and adding some models, and finally walking around with the models properly set for the rock structure on the left.





No comments:

Post a Comment