Climbing Ladders
Last updated
Last updated
This walkthrough covers the concepts of climbing ladders. When climbing a ladder, the platformer Player is able to move vertically by pressing up or down on the analog stick or d-pad. Ladders and vines are used to provide access to areas normally not reachable by jumping alone.
The sample project can be downloaded from GitHub: https://github.com/vchelaru/FlatRedBall/tree/NetStandard/Samples/Platformer/LadderDemo
This walkthrough refers to LadderDemo as this demo and the demo.
This walkthrough covers a number of concepts for climbing ladders:
Defining ladder platformer values to control climbing speed
Defining ladders in the TMX file
Controlling whether currently climbing or not according to ladder collision and input
Limiting the climbing height
The Player entity defines a set of movement values for climbing called Climbing.
When this is set as the CurrentMovement, the player has direct control over vertical movement. When climbing up and down, the Climbing Speed is set as the player's Y velocity. As we will see later in the walkthrough, these values are explicitly set when the player presses Up to grab the ladder. Notice that the Player has a non-zero Max Speed under the Horizontal Movement section. This means that the player can move horizontally on the ladder. Some games like Super Mario world allow horizontal movement on ladders. Other games like Mega Man X only allow vertical movement on ladders. This game allows vertical movement, but changing the value to 0 results in no horizontal movement.
Ladders are placed in the TMX file as tiles. The following image shows just the GameplayLayer with ladders.
Notice that the ladder tiles define the maximum height that the player can climb.
The code for this is defined below, but we can add extra climb height by adding additional tiles to the map. Keep in mind the GameplayLayer tiles do not need to match the visual layer exactly.
These ladders tiles use the Ladder type.
This allows the creation of a LadderCollision TileShapeCollection.
Platformer Entities do not (currently) support automatic switching to climbing movement values. The demo includes custom code to enable switching to climbing. The main logic controlling the movement values is in the Player.cs CustomActivity method.