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 the data structure

To store data in Treasure chest, we will add some fields to the game class.

  1. First, start with two FLOAT variables, which will hold the size of the canvas.
    Class game Extends App
    Field eng:engine
    Field isSuspended:Bool = False
    Field cw:Float
    Field ch:Float
    
  2. Next, add a field to store the mode of the game. Initialize it with a constant, which we will define shortly.
    Field gameMode:Int = gmTitle
    
  3. During the game, we need to measure how much time is left. For this, we need a field for minutes and one for seconds.
    Field minutes:Int
    Field seconds:Int
    
  4. When a game begins, we need to store the time in milliseconds, to check when it will end.
    Field endTime:Int
    
  5. Add a field for the game score.
    Field score:Int = 0
    
  6. The ...

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