Time for action - handling codes

  1. 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
    
  2. Call checkCurrentCellCode() as the first task performed inside the if (!player.Dead) statement in the Update() method of the LevelManager class:
    checkCurrentCellCode();
    
  3. 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 where the player's WorldCenter point is located. This allows the player to get close to deadly things without actually dying, but one pixel too far will trigger the square.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.236.174