5 minute read

This project is open source and available on GitHub. You may reference it and learn from it (whether that means what to do or what not to do) or just look at my poor C. The original Space Invaders game and all associated trademarks etc remain property of their respective owners.

But Why Though

I enjoy programming. I’ve been doing this in one form or another for about twenty years now, starting all the way back in high school with Counter-Strike: Source mods. It’s fun and exercises the logical part of my brain. As much as I enjoy working the “old” way, I’m realistic about the future and have had to adopt an AI-first mindset in my work (which includes data analytics and internal tooling). With everyone else slopping out very pretty things that “wow” senior management regardless of whether they actually make any sense, the reality is that if you don’t adapt then you absolutely will eventually be left behind.

Pro: I move super fast, it’s very flashy, and everyone loves the output.

Con: It’s boring and almost completely unsatisfying. That’s a big one for me because I find it extremely hard to stay motivated and produce output without satisfaction in what I’m doing.

I also found myself losing my edge and ability to do some of this stuff manually without automatically reaching for the easy path. It’s a similar feeling to when I stopped reading long-form content (books, even long articles) for 5+ years in my 20s and realized that my attention span had atrophied a lot. I tried to read a short book on an interesting topic and could barely get through a few pages before my mind would wander.

I managed to train that back and have returned to reading 40-60 books every year for the fifth year in a row in 2026. So I figure I’ll take a similar “back to basics” approach.

So what to do…

I wanted to find the balance between moving back to the basics and actually having to think while also not making this so challenging that it would be demotivating. I knew that I wanted to go lower level because even before AI the vast majority of my programming was in Python, Java, and the occasional Kotlin or (shudder) JavaScript. So I figured that C and Raylib would be a good approach in abstracting away juuust enough to retain simplicity but remove a lot of the crutches that I’m used to. Recreating straightforward retro games is a good way to keep the focus on programming and problem solving rather than design and art, so the project goal is a recreation of the classic Space Invaders. I won’t be keeping 1:1 to the original (cloning exact art and so on) but the overall gameplay is the same.

Dealing with C

Never really wrote anything in C before this. Headers are a mild annoyance and I’m not a fan of the whole Makefile thing, but it’s not that bad.

Simplicity is nice, and it’s part of why I went with C. The language is just… basic and small. Writing everything in a data-oriented procedural manner is nice compared to the OOP overload. It takes some adjusting though. I caught myself several times designing subconsciously for an objects mindset and realizing I’ve backed myself into a corner needing a redesign.

I also purposely am not using or even exploring any of the common external libraries (other than obviously Raylib) to maintain the artificial constraint for a simplistic approach. No AI development, of course, as that would defeat the purpose. I think I did ask ChatGPT once to track down some bizarre behavior that unsurprisingly traced back to updating a struct copy rather than the original. I’ve done that at least a dozen times.

But I’ve only segfaulted twice, so there’s that.

My Bad Art & Animations in Raylib

Well that’s one thing that’s never going to change, but luckily for this game it really doesn’t matter. Hard to have your art be insufficient when your aliens are supposed to be blocky and have only two animation frames.

My goofy basic aliens.

Animations are pretty straightforward. Things that animate (really just aliens and their projectiles) have simple two-frame sprites and the representative struct for each tracks a frame index which wraps to zero. Drawing is a call to DrawTextureRec which selects a sub-rectangle of the texture (multiple the frame number by the width and there you go if the frames are arranged horizontally). Very simple to implement and manage. Since aliens have multiple possible textures, each Alien struct also holds a pointer to one of the three loaded textures.

// The alien data is aware of its current frame and
// a reference to the correct texture (3 options)
typedef struct Alien {
    Rectangle rect;
    bool alive;
    int value;
    Texture2D *texture;
    int frame;
} Alien;
// Drawing an alien using the correct frame
Alien alien = aliens[i][j];
if (!alien.alive)
{
    continue;
}
// frames are stored in one png. each frame is 32px 
// wide, so use the frame counter to offset 
// from the left
DrawTextureRec(
    *(alien.texture), 
    (Rectangle){
        .x = 32*alien.frame,
        .y = 0.0f, 
        .width = 32.0f,
        .height = 32.0f
    }, 
    (Vector2){
        .x = alien.rect.x, 
        .y = alien.rect.y
    }, 
    WHITE
);

Progress

So far I have a moving player ship that can fire projectiles and be destroyed, a grid of aliens that moves back and forth across the screen, dropping down when it hits an edge, and randomly selected aliens can drop dangerous squiggles onto the player. The bunkers are present with destructible block segments. Scoring and game over conditions are in place for player losing, but not yet for destroying all aliens and resetting to the next level.

The game so far, with most core functionalities in place. Click to view larger images.

What’s Left

As of this writing I’ve spent probably ten hours on the project, a significant portion of which was me tripping over silly things like updating copies of structs and wondering why things aren’t happening. But sitting down and working on this with zero clutter, just VSCode, a terminal, and the Raylib documentation cheatsheet has been quite nice. I feel myself tapping back into the logic and critical thinking that is absent from feeding the slop machine.

I have a few things to finish up, namely:

  • There’s no sound. I should at least include the iconic alien movement boops, player firing and destruction sounds, maybe find some CC0 retro background track to loop.
  • Alien grid scaling is definitely off. The gaps are too large and it results in a pretty short game since the grid moves downward so frequently.
  • I probably will include something similar to the red ship, but change it up a little. Maybe it will appear at any vertical level above the alien grid rather than always at the top, for example.
  • Animations for destroying aliens, maybe

Tags: ,

Categories:

Updated: