Time for action — detailing the OnCreate process

The OnCreate method is the only method we can set into stone now. Cool!

  1. Set UpdateRate to 60 frames per second.
    Method OnCreate:Int()
    SetUpdateRate(60)
    
  2. Now, read the dimensions of the canvas, your visible area. You will store this information inside the previously defined variables.
    cWidth = DeviceWidth()
    cHeight = DeviceHeight()
    
  3. Before the method is closed, we will call a new method called SetupGame. In this method, we will set up the starting values of a new game. Putting this inside a method will enable us to call this part again, once the game is over.
    SetupGame()
    Return True
    End
    
  4. Now, create a new method called SetupGame. Some previously defined variable will be used and set to values appropriate for a new game.
    Method SetupGame:Int()
    totalBombsDestroyed = 0
    levelNumber = 1
    score = 0
    
  5. Later on, we will add some more stuff, but for now, we leave it like that. Close the method.
    Return True
    End
    

What just happened?

Again, save the file. It is a good time to build the RocketCommander.monkey file to see if you have any errors inside your code. If you run the code, you should see a nice dark blue empty screen.

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

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