Time for action – supporting map transitions

  1. Add a new helper method to the Helper Methods region of the Player class:
    private void checkLevelTransition()
    {
        Vector2 centerCell = TileMap.GetCellByPixel(WorldCenter);
        if (TileMap.CellCodeValue(centerCell).StartsWith("T_"))
        {
            string[] code = TileMap.CellCodeValue(centerCell).Split('_');
         
            if (code.Length != 4)
              return;
    
            LevelManager.LoadLevel(int.Parse(code[1]));
    
            WorldLocation = new Vector2(
                int.Parse(code[2]) * TileMap.TileWidth,
                int.Parse(code[3]) * TileMap.TileHeight);
           
            LevelManager.RespawnLocation = WorldLocation;
    
            velocity = Vector2.Zero;
        }
    }
  2. Modify the Update() method of the Player class to add a check for pressing the Up key or pressing Up on the gamepad to check the current square for an available ...

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.