Time for action – supporting map transitions
Add a new helper method to the
Helper Methods
region of thePlayer
class:Private Sub checkLevelTransition() Dim centerCell As Vector2 = TileMap.GetCellByPixel(WorldCenter) If TileMap.CellCodeValue(centerCell).StartsWith("T_") Then Dim code() As String code = TileMap.CellCodeValue(centerCell).Split(CChar("_")) If code.Length <> 4 Then Return End If LevelManager.LoadLevel(Integer.Parse(code(1))) WorldLocation = new Vector2( Integer.Parse(code(2)) * TileMap.TileWidth, Integer.Parse(code(3)) * TileMap.TileHeight) LevelManager.RespawnLocation = WorldLocation Velocity = Vector2.Zero End If End Sub
Modify the
Update()
method of thePlayer
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...