Time for action – setting up the variables

Let's get started with introducing the variables we'll be using to create our game. There will be a combination of display objects and integers to keep count; we also need to preload the main sound effects used during game play. Follow the steps to declare all the required variables:

  1. Hide the status bar and add in the display.newGroup() group called gameGroup:
        display.setStatusBar( display.HiddenStatusBar )
        local gameGroup = display.newGroup()
  2. Include the external modules in the game:
        local physics = require "physics"
  3. Add in the display objects:
        local background
        local ground
        local charObject
        local friedEgg
        local scoreText
        local eggText
        local livesText
        local shade
        local gameOverScreen
  4. Add in the variables:
        local gameIsActive = false
        local startDrop -- Timer object
        local gameLives = 3
        local gameScore = 0
        local eggCount = 0
        local mRand = math.random
  5. Create the egg boundaries and density:
        local eggDensity = 1.0
        local eggShape = { -12,-13, 12,-13, 12,13, -12,13 }
        local panShape = { 15,-13, 65,-13, 65,13, 15,13 }
  6. Setup the accelerometer and audio:
        system.setAccelerometerInterval( 100 )
        local eggCaughtSound = audio.loadSound( "friedEgg.wav" )
        local gameOverSound = audio.loadSound( "gameOver.wav" )

We continued creating a similar set up of our variables, like we did in the Panda Star Catcher game. It's more efficient to organize them by separating groups, display objects, audio, and so on.

Many of the variables displayed have designated integers that fulfill the goals of game play. This includes values such as gameLives = 3 and eggCount = 0.

Accelerometer events work best within the main scope of the game. It enables you to view the full real estate of the game environment, without having to interact with touches on the screen. Necessary touch events would make sense for user interface buttons such as pause, menu, play, and so on.