Time for action — creating the data structure

The following modifications have to be made to the game class:

  1. Insert the eng field, which will store the instance of the engine class.
    Field eng:engine
    
  2. Now, add a general object called obj. We will use this field during game setup.
    Field obj:ftObject
    
  3. To display some text in the game, we need one object for the game score and one to display the FPS value we have talked about previously.
    Field txtScore:ftObject
    Field txtFPS:ftObject
    
  4. We will use a bitmap font in the game and store this font inside the font1 object.
    Field font1:ftFont
    
  5. Next, add the three layers for the background, the game itself, and the title screen.
    Field layerBackGround:ftLayer
    Field layerGame:ftLayer
    Field layerTitle:ftLayer
    
  6. For the only sound effect in the game , we need a sound object called sndBing.
    Field sndBing:ftSound
    
  7. Now, add the atlas field to store the sprite sheet for the atom elements.
    Field atlas:Image
    
  8. Usually a game has a score and so does Chain Reaction.
    Field score:Int = 0
    
  9. To store the frames per second value, add a field called fps.
    Field fps:Int=0
    
  10. Now, add the gameMode field, which will be initialized with the gmMenu constant that we will add very soon.
    Field gameMode:Int = gmMenu
    
  11. Add various points inside the game; we will need to store a time value, and for this, we need two fields.
    Field lastTime:Int
    Field deltaTime:Int
    
  12. To store the collision count, which will also be used as an object ID later on, we need the collCount field.
    Field collCount:Int=0
    
  13. When the game is suspended, we will set a field to true so that we can act on it later on.
    Field isSuspended:Bool = False
    
  14. These are all fields that the game Chain Reaction needs. Now, let's add some constants.
  15. In the game, we need only two game mode constants—one for being inside the menu (title screen) and one for gameplay.
    Const gmMenu:Int = 1
    Const gmPlay:Int = 2
    
  16. To do proper collision checks, we will need two object groups—one for the atom elements and one for circle collision objects.
    Const grpAtom:Int = 3
    Const grpCircle:Int = 4
    

    In the game, we will use the timer feature of fantomEngine to change some values on an object. For this, we need a timer ID.

  17. Add the tmObjSwitch timer ID.
    Const tmObjSwitch:Int = 5
    
  18. The last constants we add are for our three buttons in the game.
    Const btnPlay:Int = 10
    Const btnReset:Int = 11
    Const btnExit:Int = 12
    

What just happened?

Fields store game-relevant variable data that can change over time. Constants are values that don't change and make your game code more readable.

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

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