Time for action – handling codes
Add the
checkCurrentCellCode()
helper method to theLevelManager
class:#Region "Helper Methods" Private Sub checkCurrentCellCode() Dim code As String = TileMap.CellCodeValue( TileMap.GetCellByPixel(_player.WorldCenter)) If code = "DEAD" Then _player.Kill() End If End Sub #End Region
Call
checkCurrentCellCode()
as the first task performed inside theIf Not _player.Dead
statement in theUpdate()
method of theLevelManager
: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 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.