Time for action — creating the data structure

Let's start modifying the game class.

  1. Add a field to our engine class, the instance of the fantomEngine's ftEngine class.
    Field eng:engine
    
  2. Next, we have fields to store different ftObject instances, which need to be accessible at any time.
    Field obj:ftObject 'A general object
    Field player:ftObject 'Holds the player ship object
    Field shield:ftObject 'the Shield of the player
    
  3. To store different text information, we will need some objects for these as well.
    Field txtScore:ftObject 'Stores the game store info text
    Field txtLifes:ftObject 'The text info about the lifes left
    Field txtLevel:ftObject 'Shows which level we are in
    Field txtComets:ftObject 'Info about how many comets are left
    Field txtHighScore:ftObject[10] 'Score list(array) with 10 entries
    
  4. Add a field that will hold the instance for our bitmap font.
    Field font1:ftFont
    
  5. Now, we need several ftLayer class instances.
    Field layerBackGround:ftLayer 'Groups all background stars
    Field layerGame:ftLayer 'All game objects are stored here
    Field layerUI:ftLayer 'Holds the info text objects
    Field layerFX:ftLayer 'ParticleFX objects
    Field layerTitle:ftLayer 'the title screen
    Field layerScore:ftLayer 'The high-score list
    
  6. The last objects are the sound effects. Add one ftSound instance for the explosion, and one for a shot.
    Field sndExplo:ftSound
    Field sndShot:ftSound
    
  7. For the sprite sheet, we will have one atlas as an image.
    Field atlas:Image
    
  8. Next, we have fields to store game logic related information.
    Field cometCount:Int 'How many comets are active
    Field levelNumber:Int 'The level number
    Field score:Int 'Game score
    Field lifes:Int 'Player lifes left
    Field gameMode:Int = gmMenu 'Mode the game is in
    

    The last fields we will add are related to the delta timing feature of our game.

  9. To measure the delta time for each frame, we need a field to measure the difference in milliseconds from the last time measured, and a field for the last time measured.
    Field lastTime:Int
    Field deltaTime:Int
    

    To finish off the data structure and to make the game logic easier to read, we will add some constants.

  10. Add constants for the initial title menu, the game in play, and when it is over to show the high score list.
    Const gmMenu:Int = 1
    Const gmPlay:Int = 2
    Const gmGameOver:Int = 3
    Const gmScoreList:Int = 4
    
  11. Next, we need three constants for the different sizes of the comets.
    Const cmSmall:Int = 0
    Const cmMiddle:Int = 1
    Const cmLarge:Int = 2
    
  12. During collision check, we need to have identifier objects for different collision groups.
    Const grpShot:Int = 1
    Const grpComet:Int = 2
    Const grpPlayer:Int = 3
    Const grpShield:Int = 6
    
  13. The last constants will be IDs for the object timer events.
    Const tmObjRemove:Int = 2
    Const tmShieldTime:Int = 3
    

That's all for now. And later too!

Save your script, and build it to see if any error shows up.

What just happened?

We have added different data fields to store information and objects of the game. Also, we have added different constants that make the script more readable.

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

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