I’ve put in hours of research and programming to fix this specific problem to no avail so I’m seeking advice.
The game has a defense game where player gets three lives. If all the lives are exhausted, then an overlay should take immediate effect to indicate the player that it’s game over. There are two modules that are in play with the sequence: game and life modules.
The game module is where the overlay takes place once it receives an action indicating that the player died, and that information comes from the life module which contains the following function to track lives:
local H = {} local w = display.contentWidth H.lives = 3 return function H.loselife() H.lives = H.lives - 1 if H.lives \>= 1 then H.bars[1]:removeSelf() elseif H.lives == 0 then H.bars:removeSelf() end return H.lives end return H
Now this module is imported in the game module prior to composer scene methods. I have attempted a myriad of approach to establish communication between the two modules such that gameover is called when lives are exhausted. So, I won’t add the code demonstrating that since there’s simply too many I tried, but I will basically explain gist of some attempts:
-
Correct me whether this is valid, but I figured this could be handled with a custom event handler. So, I considered creating a scene method scene:gameover( event ) in the game module, and have it listen to a custom event dispatcher which is sent from life module. I tried this theory with various implementation of this theory, but I simply don’t know how to go from the dispatcher to the scene method.
-
I considered putting the game over overlay in the life.lua but I fear that it would compromise the purpose of the life module since it would require composer, but I don’t want the game module to involve composer.
Any suggestions would be greatly appreciated.
- Dan.