Show HN: Space Invaders in C
Interesting metrics, you'd expect C to do a lot better in the line-count department than assembly.<p>I tried building it on Ubuntu, if you follow the instructions the SDL library include files will end up in a directory called SDL so you have to include SDL/SDL.h and even then the build fails with lots of SDL related definitions missing (SDL_Window for instance).<p>That's because you really should be doing<p><pre><code>  sudo apt-get install libsdl2-dev
</code></pre>
Then change the include file line to<p><pre><code>  #include <SDL2/SDL.h>
</code></pre>
and type:<p><pre><code>  make
</code></pre>
The roms can be found here:<p><a href="http://www.freevintagegames.com/MAME/invaders.php" rel="nofollow">http://www.freevintagegames.com/MAME/invaders.php</a><p>After downloading you'll have to rename the files because the names will all be uppercase:<p><pre><code>  cd inv1
  mv INVADERS.E invaders.e
  mv INVADERS.F invaders.f
  mv INVADERS.G invaders.g
  mv INVADERS.H invaders.h
  cd ..
</code></pre>
Now the game should work:<p><pre><code>  ./bin/si78c
</code></pre>
Some minor nitpicks about the code:<p>- bracket your ifs and place the starting { on the same line as if/while, or one day you'll sit there staring at the screen for 8 hours trying to figure out why your code no longer works due to an accidentally deleted line.<p>So:<p><pre><code>  while (num < 64)
    {
        int has = SDL_PollEvent(&event_buffer[num]);
        if (!has) break;
        num++;
    }
</code></pre>
becomes:<p><pre><code>  while (num < 64) {
    if (SDL_PollEvent(&event_buffer[num])) {
      break;
    }
    num++;
  }

</code></pre>
Neat project!