Time for action – handling codes
- Add the
checkCurrentCellCode()
helper method to the LevelManager class:#region Helper Methods private static void checkCurrentCellCode() { string code = TileMap.CellCodeValue( TileMap.GetCellByPixel(player.WorldCenter)); if (code == "DEAD") { player.Kill(); } } #endregion
- Call
checkCurrentCellCode()
as the first task performed inside theif (!player.Dead)
statement in theUpdate()
method of the LevelManager class:checkCurrentCellCode();
- Launch the game and run to the right until you reach an area where there are floor blocks missing, forming a pit. Jump into the pit, and your character will die when he reaches the lowest level of the pit.
What just happened?
We simply read the code value from the map for the cell ...
Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.