To store the data, we will enhance the game
class with some fields and constants, as follows:
Class game Extends App Field eng:engine Field isSuspended:Bool = False Field txtScore:ftObject Field txtScoreC:ftObject
Field txtYouWin:ftObject Field txtYouLoose:ftObject
Field player:ftObject Field enemy:ftObject
Field font1:ftFont
Field layerBackground:ftLayer Field layerGame:ftLayer Field layerClouds:ftLayer Field layerInfo:ftLayer Field layerTitle:ftLayer
Field sndHit:ftSound Field sndExplo:ftSound Field sndShoot:ftSound Field sndEngine:ftSound
atlas
, which will hold the reference to the sprite sheet.Field atlas:Image
gameMode
It will be initialized with the constant gmMenu
, which we will add shortly.Field gameMode:Int = gmMenu
Field score:Int = 0 Field scoreC:Int = 0
Field hits:Int = 0 Field hitsC:Int = 0
Field cw:Float = 0.0 Field ch:Float = 0.0
Field canShoot:Bool=True
You are done adding fields. Now, add some constants. Constants make your code more readable, and they are easier to remember, as compared to numbers.
Const gmMenu:Int = 1 Const gmPlay:Int = 2 Const gmGameOver:Int = 3
Player, Enemy
, and a group for the bullet shots.Const grpPlayer:Int = 1 Const grpEnemy:Int = 2 Const grpShot:Int = 3
Const triDelete:Int = 6
Const tmDelete:Int = 15 Const tmCanShoot:Int = 16 Method OnCreate:Int() SetUpdateRate(60)