They came from outer space - retro shoot-em up

Hi all.

I’ve been meaning to learn Lua and Defold for some time now, but only recently had the time. And what better way to learn a game engine, than to re-create a well known game in it… and voilà, “They came from outer space”.

It’s a Space Invaders clone, complete with walls, a weapon upgrade pickup, 10 levels, and a hopefully proper menu/settings dialog/pause menu/end of game screen.

The game supports mobile controls as well and makes an attempt to detect whether you are running on mobile or tablet to display them. It is displayed in portrait mode in low resolution (270x640), in accordance with the retro feel.

Things I learned - had trouble with:
As I said, the game was made as an attempt to learn Defold and Lua. It took me around two weeks to make and I surely learnt a lot. Here are some things I noticed:

  • Trigger collisions: many times not firing, because I forgot to set masks to both colliding objects
  • Implementing a pause feature is more complicated than expected (you need a collection proxy, you need to dispatch a set_time_step message, you need to separately handle logic not covered by time step)
  • Understanding messaging: Finding the proper url to post a message is a bit hit and miss, but I ended up having message targets “subscribe” to their caller by sending a message to capture their url.
    What was more difficult was understanding how to architecture the logic when implementing the aliens behavior; in Space Invaders, once an alien reaches the left or right of the screen, direction is reversed and all aliens move down. If only the alien in question had to change direction and move down, implementation would have been very easy - I would just have to add tis bejavior in the update function. However, since all aliens need to move down and to the opposite horizontal direction, I thought that I could:
    a. create a manager game object, with an alien factory
    b. at level start, the manager spawns aliens in their proper positions and keeps a table with their ids
    c. in the alien script, if it reaches the edge, it posts a message (“edge_reached”) back to the manager
    d. if the manager receives this message, it loops through all aliens, moves them down and changes their direction
    This approach didn’t work, I guess because the order of operations was undetermined. All aliens of a column sent the “edge_reached” message and their position was changed in both the alien update function and the manager function that handles the “edge_reached” message.
    I ended up creating a container “enemies” object that took the aliens spawning responsibility from manager and handled moving the aliens in its update function, so the actual alien game object just handled collisions and firing.
    This thing seems a bit unnecessary complicated, so I probably haven’t understood something here.
  • Destructible walls: I ended up making the walls from small parts, so I could handle collisions and partial destruction. This certainly works, but is expensive (18 colliders for each wall) and it leaves you wondering how such a future was implemented almost 46 years ago by the Taito programmers. Food for thought really, since programming was such a different beast back then.

Try it in your browser:

Credits for the assets used: