This set of tutorials covers how to change a Player's movement values in response to colliding with various ground types (such as ice). It also covers how to implement swimming, and how to transition between in and out of water movement. Multiple terrain types and water movement are common in many platformers super as Super Mario World.
This tutorial begins with an empty project and will create a project with a Player which changes its movement values according to collision with different ShapeCollections. [subpages depth="1"]
The default Platformer project creates a game with a level (Level1). We will modify this level to create ice and water tiles.
We can open Level1Map.tmx to add additional tiles.
Level1Map.tmx should appear in the Tiled app. To make sure that no tiles from other maps are being used, be sure to close other TMX files in Tiled.
Default maps include a tileset named TiledIcons. Most of these icons have no built-in functionality, so they can be used to add custom behavior to your game. In this case we will use the ice and water tiles which are part of the tileset.
We can paint these tiles, along with more solid collision tiles, to create a test level with ice and water.
We have a level where the player can collide with the solid ground, but ice and water do not yet affect the Player's movement.
The next tutorial shows how to add collision and change the player's movement values on ice and in water.
This tutorial shows how to add ice and water collision. We'll be setting up the TileShapeCollections for these two types of tiles, and creating collision relationships to control the interaction between the Player and these tiles.
As shown in the previous tutorial, the Player already collides with the solid collision. This is automatically added by the New Project Wizard, so we don't have to do any setup for ground collision. We'll add ice collision first. To do this:
Click GameScreen
Select the Quick Actions tab and click the Add Object to Game Screen button
Select TileShapeCollection
Enter the name IceCollision
Click OK
Select the newly-created IceCollision object
Click the TileShapeCollection Properties tab
Click the From Type option
Change the Source TMX File/Object to Map
Change the Type to IceCollision
We'll repeat the process above to create water collision:
Click GameScreen
Select the Quick Actions tab and click the Add Object to Game Screen button
Select TileShapeCollection
Enter the name WaterCollision
Click OK
Select the newly-created WaterCollision object
Click the TileShapeCollection Properties tab
Click the From Type option
Change the Source TMX File/Object to Map
Change the Type to Water
Now our game has two new collision relationships: IceCollision and WaterCollision. This means that when our game runs, collision shapes are created based on the water and ice tiles, but we haven't yet told the game how to handle collisions between the Player and these collision relationships. First, we'll set up collisions between the Player and IceCollision:
Drag+drop PlayerList onto IceCollision
The newly-created PlayerVsIceCollision is automatically set up to use Platformer Solid Collision physics, so we don't need to make any changes. We also need to create collision between PlayerList and WaterCollision, but this time we need to disable Platformer Solid Collision since the Player should be able to fall into the water. To do this, drag+drop PlayerList onto WaterCollision and select No Physics.
Now if we run our game we can collide with the ice tiles and fall through water.
Now our game has ice and water TileShapeCollections and collision relationships. You may have noticed that the ice currently acts identical to solid collision (bricks). The next tutorial will create new platformer variables for moving on ice and swimming in water, and will switch between them in response to collision.
This tutorial, like many other tutorials, begins with an empty Glue project. I'll call mine PlatformerMovement.
Keep the Open New Project Wizard option checked.
Once the project finishes loading, Project Setup Wizard appears. Select the Standard Platformer option.
Now our project is ready to go. If we run the game we have a standard platformer project.
As of the last tutorial our game has three tile shape collections:
SolidCollision - the bricks that make up most of the level
IceCollision - floating blocks of ice which should be slippery
WaterCollision - an area of the level where the player should be able to swim
This tutorial shows how to create new platformer values for ice and water, and how to change between them depending on collision type.
Before we change which platformer values are used based on collision, we first need to define the platformer values for the different movement types. As mentioned before, we will have the following platformer values:
Ground - already defined by default
Air - already defined by default
Ice - will apply when user collides with the ice TileShapeCollection
Water - will apply when the user collides with the water TileShapeCollection
To add a new movement value:
Click the Player entity
Click the Entity Input Movement tab
Click the Add Control Values button
Set the following values:
Movement Type = Ice
Max Speed = 160
Speed Up/Down = true (click radio button)
Speed Up Time = 1
Slow Down Time = 1
Jump Speed = 270
Hold to Jump Higher = true (click checkbox)
Max Jump Hold Time = .17
Repeat the process above to create a water movement. Click Add Control Values again, and set the following values:
Movement Type = Water
Max Speed = 120
Speed Up/Down = true (click radio button)
Speed Up Time = 1.3
Speed Down Time = 0.5
Jump Speed = 120
Hold to Jump Higher = true (click checkbox)
Max Jump Hold Time = 0.3
Gravity = 210
Max Falling Speed = 90
Now that we have Ice and Water movement defined, we can write code in the Player class to set the movement values according to what the player has collided with. To do this:
Open the project in Visual Studio
Open Player.cs
Add the following code to CustomActivity:
Now our Player will change movement values when moving on ice and solid ground.
This concludes the platformer movement value tutorials where we use multiple TileShapeCollections to change the movement values for the player between regular ground/air movement, ice, and water movement.