Monday, 27 May 2013

How does the Goomba know it has been jumped on?

How does the Goomba know it has been jumped on?

I'm developing a 2D tile game engine in LibGDX and I'm asking myself how to structure the whole thing. One of the key questions right now is how to implement Player-Tile interaction similar to this particular example:
https://www.youtube.com/watch?v=Yyv5Tt5iUFc (only first seconds relevant)
We see a Player instance, a switch on a tile and something that reacts to the switch being pressed (the Door).
Basically my Question ist: What is this switch in "solution space"/Java OOP Terms? How to implement it? How to let it interact with the player?
I thought alot and used Google for several hours but still didn't find any sufficient answer. Maybe I was searching with wrong words or fiddling through bad sources but I found a working solution to the problem myself which I am not very proud of since it seems stupid to me:
The map is made up of tiles where each cell has it's own properties (you can do that easily in Tiled). One of these properties is called "material". Each cell has a position in tile units and since one cell is 16x16 pixels it's position in pixels is tile units*16. If the cell's property material value is eg. "SWITCH" then there has to exist another property which other cell this switch will manipulate if stepped on. If the cell's property material value is "DOOR" there exists another property where this door will lead to. These tiles are called EventTiles. An EventTile is an Object that holds attributes like position, alive (for animation purposes), steppedOn, animation sprites etc. and methods like update() which basically does something with this EventTile like checking whether it's alive should be set to false and a method called init() w

No comments:

Post a Comment