Time for action — creating the player

To create the player machine, you will add a new method to the game class:

  1. Now, add a new method called 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.

  2. Load the animated image into the player field.
    player = eng.CreateAnimImage(atlas,0,128,64,64,3, plStPos[0],plStPos[1])
    
  3. Set the animation speed for each frame to 1.
    player.SetAnimTime(1)
    

    To check if the player machine runs into crates or walls, we will need two collision zone boxes.

  4. Create a new collision zone box, that is, place 64 pixels in front of the player machine.
    Local obj:=eng.CreateZoneBox(10,10,plStPos[0],plStPos[1]-64.0)
    
  5. Set the parent of the box to the player. Also set the collision group to 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.

  6. Now, create another collision zone box, but this time 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)
    
  7. Close the method.
    Return 0
    End
    

What just happened?

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 level maps—loading the tiles

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:

1

Wall

2

Crate

3

Floor

4

Target platform

5

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:

The level maps—loading the tiles

Please note that the levels of the game will be composed of 11 columns in 8 rows.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.27.171