Time for action — detailing the OnLayerTransition method

For this, we need to detail the OnLayerTransition method of the engine class, as follows:

  1. First, we check if the transition ID is equal to g.tidNextLevel.
    Method OnLayerTransition:Int(transId:Int, obj:ftLayer)
    If transId = g.tidNextLevel Then
    
  2. Then, reset the alpha value of the layer back to 1.0. That means it would be fully visible.
    g.layerGame.SetAlpha(1.0)
    
  3. Next, check whether the current level number is smaller than 4 (we have only four levels).
    If g.levelNum < 4 Then
    
  4. Raise the current level number and load a new level.
    g.levelNum+=1
    g.LoadLevel()
    
  5. Switch the game mode back to g.gmPlay.
    g.gameMode = g.gmPlay
    
  6. If the last level is already reached, activate the title layer.
    Else
    g.layerTitle.SetActive(True)
    
  7. Set the game mode to g.gmMenu and close off the two If checks.
    g.gameMode = g.gmMenu
    Endif
    Endif
    Return 0
    End
    

What just happened?

We have detailed the OnLayerTransition method of the engine class. We can now switch to a new level or jump back to the title layer when the last level has been finished.

That is all for now. We have a running game with most elements present. We can switch to new levels and control the player and the winning conditions.

There are a few things left for you to do, and the next part will tell you what they are.

Have a go hero — enhancing At The Docks

Some parts in this game were left out on purpose for you to implement on your own. For example, sounds. While the machine is moving, you can play back some nice heavy machinery sounds. You could also add sounds for when a crate hits a target or you bump into a wall.

Another thing to add is some kind of high-score mechanism. Give points based on how fast the player finishes a level. For this, you need to measure time. Another neat gimmick would be that if you bump the machine too many times into a wall, it breaks and the player loses.

You see, there is still enough room for you to enhance the game.

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

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