With all the game play elements set in place, it is time to get the application started by using the following steps:
Create a new local function called
gameActivate()
and insertgameIsActive = true
. Place the function above themoveChar()
function:local gameActivate = function() gameIsActive = true end
Initialize all the game actions by making a new function called
gameStart()
:local gameStart = function()
Start the physics property and set the gravity for the falling object:
physics.start( true ) physics.setGravity( 0, 9.8 )
Activate all the functions instantiated. Add an event listener for the
charObject
, using the"accelerometer"
event for themoveChar()
function:drawBackground() createChar() eggTimer() hud() gameActivate() Runtime:addEventListener("accelerometer", moveChar) end
Instantiate the
gameStart()
function and return thegameGroup
group:gameStart() return gameGroup