NEW PROJECT – Space Invaders

Category: | Posted on:January 27, 2025
space invaders

Space Invaders is a bare-bones facsimile of the classic arcade game of the same name.

Objective

I wanted to take what I learned from the Asteroids Tutorial in my last project and iterate without the training wheels this time. Space Invaders has more lateral movement from the player and hostiles than in Asteroids, and has an additional interactable object in the form of shields between the player and the hostiles that require sphere-to-rectangle collisions.

Development

Establishing the canvas scene, controls, end screen, and missile-to-object collisions were very similar to the setup from asteroids, so I got that out of the way first. This time the hostile objects have projectiles of their own, so that was another object array to contend with. All four objects involved the same kind of spherical graphics, so the collisions were relatively simple. The sphere-to-rectangle collisions were uncharted territory and more complicated.

The aliens and shields are drawn from arrays that detect the width of the window and draw a number of objects based on the horizontal space available, so the game scales to the browser.

Hurdles

Getting the aliens to move in a tick sequence rather than gliding smoothly across the screen was more challenging than it needed to be. I ended up inadvertently making the first half of the other arcade game Centipede and forked my project at that point so I could use it as another practice game later. Ultimately, I needed to zero out the velocity all together and add/subtract position values on an interval timer. I was just over-thinking it.

The sphere-to-rectangle collisions were another sticking point, and I needed to cheat with the math a little. Because the shield objects have a width property, I needed to detect collisions with missiles all along the length. The logic of that threw me so I looked up a reference.

Takeaways


I need to take my time more when it comes to establishing formulas. I probably could have figured out the rectangle collisions on my own in a session or two if I’d had the patience. Part of my doing this is to code more readily without leaning on docs, forums, and chatbots as much. I did better overall than in the Asteroids game, though. There is enough overlap in some of the general principles of structuring little games like this that I’m starting to understand what’s needed. Draw the canvas, establish the animation loop, populate with objects that have positions, boundaries, and velocities, update objects in the animation loop, manipulate them with event listeners and timers, clean them up when they go off-screen, etc.

I ended up with some nice reusable functions for handling both sphere-to-sphere and sphere-to-rectangle collisions that I can carry over to my centipede game.

I might come back and add one more quality of life feature where the shields re-center after they are hit with a laser. I just need to detect if the hit is to the left or right of center, then shift the x position left or right accordingly.

Related Logs


  • WIP – Machine Shop Simulator

    January 27, 2026

    Machine Shop Simulator is a prototype management sim game for the browser built with React and the HTML Canvas API. It is a facsimile of a CNC machine shop. Objectives Development 1/27/2026 – This is finally at a point where it’s shareable, even if it isn’t done. I’d call it halfway there as a proof […]

    Continue Reading
  • NEW PROJECT – Javascript Arcade

    January 14, 2026

    Javascript Arcade is a stylized hub for the JS Canvas projects I’ve been working on. Objective I’m re-working my portfolio and needed more casual project to fill it out. The individual arcade games are pretty similar structurally, so it made sense to wrap them up together into a more formalized package for presentation purposes. There;s […]

    Continue Reading
  • NEW PROJECT – Centipede

    February 13, 2025

    CentipedeĀ is a bare-bones facsimile of the classic arcade game of the same name. Objective Continuing my exploration of Game Development with the Javascript Canvas API, I moved onto Centipede mostly by accident. Once again I avoided tutorials in order to try and work through the logic myself. The key goal with this game was handling […]

    Continue Reading