Time for action – supporting map transitions
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; } }
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 transition. Place this after the check for pressing the Space bar or A button to jump:if (keyState.IsKeyDown(Keys.Up) || gamePad...