Time for action — creating the data structure

  1. To store the relevant fields, we will create fields again in our main class, called game.
  2. The game class already has fields for the instance of the engine class and a field that will store if the app is suspended or not.
    Class game Extends App
    Field eng:engine
    Field isSuspended:Bool = False
    
  3. Next, add fields to store text objects for storing the game score, Game Over text, and the FPS indicator.
    Field txtScore:ftObject
    Field txtGameOver:ftObject
    Field txtFPS:ftObject
    
  4. Our game ball will be a separate object and so are the fonts, which we will be using for our in-game text objects.
    Field ball:ftObject
    Field font1:ftFont
    
  5. Later on, we will create two classes for particle emitters and the enemies that will hunt you down in the game. To store these, we will use lists.
  6. Add fields for lists based on the Enemy class and the ParticleEmitter class.
    Field enemyList:=New List<Enemy>
    Field emitterList:=New List<ParticleEmitter>
    
  7. Now, add the layers that we need—one for the background, one for the game, and one for the title screen.
    Field layerBackGround:ftLayer
    Field layerGame:ftLayer
    Field layerTitle:ftLayer
    
  8. The sound effects have to be stored. We need three of them.
    Field sndHit:ftSound
    Field sndSelect:ftSound
    Field sndExplo:ftSound
    
  9. Now, add fields to store the sprite sheet (atlas) and the game mode, which controls the flow of the update procedure.
    Field atlas:Image
    Field gameMode:Int = gmMenu
    
  10. To make life more convenient through less typing, we will need fields to store the canvas width and height.
    Field cw:Float
    Field ch:Float
    
  11. Some more fields are needed to store the current frames per second, the score, tile count, level number, and lives left in the game.
    Field fps:Float
    Field score:Int = 0
    Field tileCount:Int = 0
    Field levelNum:Int = 0
    Field lifes:Int = 0
    
  12. These are the data fields, but like always, we will add some constants to the game.
    • First, add constants for the game mode.
    Const gmMenu:Int = 1
    Const gmPlay:Int = 2
    Const gmGameOver:Int = 3
    
    • To identify objects during the game, we need some group identifiers.
    Const grpEnemy:Int = 1
    Const grpBall:Int = 2
    Const grpTile:Int = 3
    
    • The three buttons in our game will need some IDs too.
    Const btnPlay:Int = 10
    Const btnExit:Int = 13
    Const btnBack:Int = 14
    
    • The last constants that we need to add are some transition IDs: one for particles and one for the Game Over text.
    Const tidParticle:Int = 20
    Const tidGameOver:Int = 21
    '---------------------------
    'Method OnCreate:Int()
    

Great, the data section is filled with everything that is needed.

What just happened?

As soon you include media files in your project, you need a data folder. We created the folder structure that is needed. Then we added various constants and variables.

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

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