Im making a space inavaders clone for my A level NEA project.
I have got to the point where I want to spawn waves of aliens, I know i have to use a table for this but I am unsure how, is there a resource I can learn from in order to be able to do this?
Following on from this, i would be unsure as to how to detect when the waves hits the side borders of the screen.
Using a table is a really good idea, we can probably use something like a 2d array in order to hold our aliens.
local aliens = { -- save Ids of the aliens here
{ }, -- row one
{ }, -- row two
-- etc
}
Within the rows themselves, I would store the aliens in order of positions where index 1 = the left most alien and index [x] (I’ll use 10 for simplicity) represents the right most alien.
Since the goal with the aliens is to move them all together for the most part, you should be able to simply check the left and right most alien x position.
local leftPosition = 5
local rightPosition = 1075
-- comment: alien size needs to be incorporated into the left and right positions as well
for _,row in ipairs(aliens) do
if #row > 0 then -- check to make sure that there are items in the table
if go.get_position(row[1]).x =< leftPosition then
-- move down and start moving right
elseif go.get_position(row[#row]).x >= rightPosition then
-- move down and start moving left
end
end
end
Use of table.remove() can be used to shift down the positions so that we are only looking at the left and right most aliens
Here’s another forum post regarding tiles, since this is somewhat similar since it’s talking about coordinates