I have been messing with positioning in grid like formations like the classics Space invaders, Galaxian etc.
I am able to create a table of the same instance and position it in a grid formation with a simple for loop.
I have stripped out all irrelevant code.
What I am looking at now is how to change the image on second,third,fourth and fifth rows for a different image, they will have all the same attributes as each other…
I was thinking having a table within a table but I cant really find anything on the net pointing me in the correct direction.
Anyone here give me a pointer please?
[lua]
– enemy.lua –
function enemys:init(xloc, yloc)
self.image = display.newImage(“images/Enemy2.png”)
self.image:setReferencePoint( CenterReferencePoint )
self.image.x = xloc
self.image.y = yloc
self.image.name = “enemy”
self.movement = 0.5
function enemys:start()
Runtime:addEventListener( “enterFrame”, self )
self.image:addEventListener( “collision”, self )
end
function enemys.enterFrame(self, event)
self.image.x = self.image.x + self.movement
end
[/lua]
[lua]
– main.lua –
local enemys = require(“modules.enemy”)
for j = 1, 5 do
for i = 1, 11 do
allEnemys[#allEnemys + 1] = enemys:new()
allEnemys[#allEnemys]:init(i * 60, j* 70 +70)
allEnemys[#allEnemys]:start()
end
end
[/lua]