The world-level interactions between the player, asteroids, and lasers are effectively complete at this point. The remaining tasks are for the game to track those elements that are not part of the world representation; accomplishments and challenges.
To manage scores, first we'll need to set it when a game begins.
Open
game.lua
and find theenterScene
handler, set the starting value for player score, and dispatch a game event:Runtime:addEventListener('touch', self) self.Score = 0 self:dispatchEvent{name = 'Score'; value = self.Score} self:Start()
To trigger changes in the score, the game needs to track
Destroy
events for rocks, which it can receive from the world:self:dispatchEvent{name = 'Score'; value = self.Score} self.World:addEventListener('Destroy', self) self:Start()
Before moving on, keep registration balanced by removing the listener in the
exitScene
handler:function scene:exitScene( event ) Runtime:removeEventListener...