To create the player machine, you will add a new method to the game
class:
CreatePlayer
.Method CreatePlayer:Int ()
The player is an animated image made up from three frames. If you study the images closely, you will see that the tracks are animated.
player
field.player = eng.CreateAnimImage(atlas,0,128,64,64,3, plStPos[0],plStPos[1])
1
.player.SetAnimTime(1)
To check if the player machine runs into crates or walls, we will need two collision zone boxes.
64
pixels in front of the player machine.Local obj:=eng.CreateZoneBox(10,10,plStPos[0],plStPos[1]-64.0)
grpPlayer
.obj.SetParent(player) obj.SetColGroup(grpPlayer)
You will need another collision zone so you can still check if there is a wall when the machine pushes a crate.
128
pixels in front of the player, and set its collision group to grpPlayer2
.Local obj2:=eng.CreateZoneBox(10,10,plStPos[0],plStPos[1]-128.0) obj2.SetParent(player) obj2.SetColGroup(grpPlayer2)
Return 0 End
This method we have just created will load the animated image frames for the player's machine and create the collision zone boxes. By default, these have the bounding box flag set to them, so fantomEngine will use a bounding box to mark collision check to determine whether a collision has happened.
The maps for At The Docks are made of single tiles with a size of 64x64
pixels. To store the layout of these maps inside a text file, we will use a simple system of rows and columns of IDs, which will reassemble the map layout. These IDs have the following meanings:
|
Wall |
2 |
Crate |
|
Floor |
|
Target platform |
|
Initial start position of the player |
The IDs 2
and 5
will not only create a crate or set the player's start position, but also create a floor tile. The following, is what the first level looks like in the text file:
1;1;1;1;1;1;1;1;1;1;1 1;3;3;3;3;3;3;3;3;3;1 1;3;3;3;3;3;2;3;3;3;1 1;4;1;3;3;1;1;3;3;3;1 1;3;1;2;3;3;4;3;5;3;1 1;3;3;3;3;3;3;3;3;3;1 1;3;3;3;3;3;3;3;3;3;1 1;1;1;1;1;1;1;1;1;1;1
Here is what it will look like in the game:
Please note that the levels of the game will be composed of 11 columns in 8 rows.