Hi all,
As you would’ve guessed, I’m almost completely new to Corona, and the Lua language, and I’m in a bit of a fiddle.
My first endeavour as a new, young, and furiously ambitious Mobile developer is to make a complex (hope you see the sarcasm) shooter, where the player shoots from the top of the screen at randomly colorised circles coming at you from the bottom of the screen. So far, I’ve coded the turret to reposition itself on the x axis at the point where you tap (no shooting yet). Also, I’ve made the circles begin to appear at random intervals at the bottom of the screen and move upwards. I also attempted to destroy them once they reached the top. But it’s all spotted with errors and I really need some help. First of all, please have a look at the following:
function listener ( event )
local enemy = display.newCircle( math.random( display.contentWidth ), display.contentHeight, 20 )
enemy:setFillColor ( math.random( 255 ),math.random( 255 ),math.random( 255 ) )
transition.to( enemy,{time = math.random( 3000,6000 ),x=enemy.x,y=0} )
return enemy
end
local enemies = timer.performWithDelay( math.random( 1000,3000 ),listener,0 )
function check ( event )
for count = 1,#enemies do
if enemies[count].y == 0 then
print (“destroy”)
end
end
end
Runtime:addEventListener( “eventFrame”,check )
I’m trying to spawn the enemies with the listener function called by timer.performWithDelay() and store all of them in the table called “enemies” simultaneously. Then, I’ve tried to go through the table and check if any of the enemies have reached the top, the print destroy, which isn’t working at all. What have I done wrong, or what should I do better? By the way, I worked most of this out intuitively.
Thanks and regards,
Adrian aka Adgeofgalaxy
Young coder