Hi guys,
I’m new to corona sdks and lua. So today I tried making this funny app for my friend his birthday, but I can’t seem to figure 1 thing out. It’s basically a whack the mole game and every time the mole is tapped it disappears (no problems so far), but when I tap the mole, I’d also like to make another mole appear and tappable and this proces over and over again.
This is the code, I tried to label everything
------------ Start Game App --------------- -- Coordinations -- local centerX = display.contentCenterX local centerY = display.contentCenterY -- Forward References -- local startGame local spawnEnemy1 local enemy local tapStart local safkes = 0 local scoreTxt local safke = audio.loadSound("Snd/safke.wav") -- Global style display.setDefault( "background", 40, 300, 40 ) display.setStatusBar( display.HiddenStatusBar ) -- Menu Screen -- local function startMenu() -- Start Button startBtn = display.newImage("Img/Start.png") startBtn.x = centerX startBtn.y = centerY startBtn.alpha = 0 -- Transition transition.fadeIn( startBtn, onStart ) -- Transition Away From Menu startBtn:addEventListener( "tap", tapStart ) end -- Game Start -- function startGame() spawnEnemy1() enemy:addEventListener( "tap", destroyEnemy ) scoreTxt = display.newText("safkes: 0", 0, 0, "Helvetica", 25 ) scoreTxt.anchorX = 1 scoreTxt.anchorY = 0.5 scoreTxt.x = centerX / 0.85 scoreTxt.y = display.screenOriginY + 15 scoreTxt:setTextColor( 0, 0, 0 ) end -- Game Funtions -- function spawnEnemy1() enemy = display.newImage("Img/Enemy.png") enemy.y = math.random( display.contentHeight ) if math.random(2) == 1 then enemy.x = math.random ( -100, -10) else enemy.x = math.random ( display.contentWidth + 10, display.contentWidth + 100 ) end enemy: scale( .5, .5) transition.to( enemy, { time = 1000, x = math.random( display.contentWidth ), y = math.random( display.contentHeight ) } ) end -- Event Funtions -- function tapStart (event) display.remove(startBtn) -- Transition To the Game startGame() end function destroyEnemy(event) display.remove(enemy) safkes = safkes + 1 scoreTxt.text = "safkes: " .. safkes audio.play(safke) end startMenu()
So yeah, the code as it is at the moment looks fine in my opinion, just that last part of the game isn’t working out