O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — creating a StartNewGame method

  1. Add the StartNewGame method to the game class.
    Method StartNewGame:Int()
    
  2. Set the game relevant fields to their initial values.
    cometCount = 0
    lifes = 3
    score = 0
    levelNumber = 1
    
  3. Deactivate the layers layerTitle and layerScore.
    layerTitle.SetActive(False)
    layerScore.SetActive(False)
    
  4. Position the player ship in the middle of the virtual canvas.
    player.SetPos(eng.canvasWidth/2,eng.canvasHeight/2)
    
  5. Set its angle and speed to 0.
    player.SetAngle(0.0)
    player.SetSpeed(0)
    
  6. Activate the player ship and activate its shield.
    player.SetActive(True)
    ActivateShield()
    
  7. Spawn 4 new large comets by calling SpawnComets.
    SpawnComets(4)
    
  8. Set the game mode to gmPlay and close the method.
    gameMode = gmPlay
    Return 0
    End
    

What just ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required