# Space Invaders Waves Spawning

**URL:** <https://forum.defold.com/t/space-invaders-waves-spawning/68013>\
**Category:** Questions\
**Created:** [April 5, 2021, 8:53am UTC](https://forum.defold.com/t/space-invaders-waves-spawning/68013 "2021-04-05T08:53:58Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![kingerman88](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/kingerman88/32/22126_2.png) [@kingerman88](https://forum.defold.com/u/kingerman88)\
**Post date:** [April 5, 2021, 1:35pm UTC](https://forum.defold.com/t/space-invaders-waves-spawning/68013/2 "2021-04-05T13:35:20Z")

</div>

> [@ZatoPulse](#):
>
> 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

Using a table is a really good idea, we can probably use something like a 2d array in order to hold our aliens.

```lua
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 (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.

```lua
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 😛

> [@How to Get a Tiles Coordinates? (SOLVED)](https://forum.defold.com/t/how-to-get-a-tiles-coordinates-solved/54341):
>
> How do I use tilemap.get\_tile to access a tiles x,y coordinates? I’m using a loop to create a grid of tiles and at the same time would like to log each of the tiles coordinates into a table. I feel like this is very basic but I’m struggling. Basically how do I access a tiles coordinates? I’m used to using game objects that have transforms that can be easily accessed but this just seems backwards, lol.

---

_[View the full topic](https://forum.defold.com/t/space-invaders-waves-spawning/68013)._
