
Space Invaders from Scratch - Grieverheart
http://nicktasios.nl/posts/space-invaders-from-scratch-part-1.html
======
nils-m-holm
Writing a Space Invaders clone is such a rewarding task! :)

Here's mine (using Xlib):
[https://www.t3x.org/xt3x/index.html](https://www.t3x.org/xt3x/index.html)

~~~
CodeWriter23
Space Invaders was something I wrote in BASIC as a side project while in high
school. Then with each new language I needed to learn, I wrote Space Invaders
in that language to get me up to speed quickly.

~~~
jamiek88
Me too!

BBC basic, had an acorn electron at home with _nearly_ the same BASIC
installed so I could work on it outside of school but getting the timings
right for both machines was hard.

Ended up with two versions selected at runtime.

Me and my best pal at school both wrote versions when we weren’t collaborating
on tools to hack the Econet system!

Great times.

------
scottlu2
A Javascript based one:
[https://codesandbox.io/s/2px9y0p480](https://codesandbox.io/s/2px9y0p480)

~~~
ivan_ah
Nice! 2k lines of js, but it's all there and quite readable.

The gif-backed DemoMode is also very cool.

------
bigiain
Heh - I remember doing this in ascii-art on an Osbourne CP/M machine, first in
Basic and later in Z80 assembler. I used the wiring diagram in the owner
manual (!!!) to work out how to make a joystick I could plug into the parallel
port. I was maybe 13 at the time...

~~~
DEADBEEFC0FFEE
Increasing few people know what the hell your on about. Parallel port, you
were lucky. 15 pin analogue for me.

~~~
mar77i
15 pin analogue? Luxury. I had to manually wire a piece of wire to a microchip
to attach a joystick made of dinosaur bone.

------
krapp
Since everyone is showing off theirs here is my half-assed attempt:
[https://bitbucket.org/kennethrapp/spaceinvaders](https://bitbucket.org/kennethrapp/spaceinvaders)

~~~
aerique
And here's mine: [https://aerique.itch.io/alien-
conquerors](https://aerique.itch.io/alien-conquerors)

It was written in Haxe and compiled to Flash. Doesn't really work anymore in
most browsers. I should find the source and recompile as HTML5.

~~~
dirkc
I _had_ to play until killing all the aliens at least once!

~~~
aerique
Haha, nice to hear it still works and well done!

------
anoakie
I implemented Space Invaders from scratch, but in a roundabout way... By
writing a well documented 8080a emulator that can play dumps of the arcade
roms: [https://github.com/anoakie/siemu](https://github.com/anoakie/siemu)

------
nyrulez
This brings back some fond memories. I once made a 3D OpenGL clone of space
invaders for a graphics course (Windows only). It made a bunch of changes and
was actually playable and reasonably challenging...don't know if it even works
today

[http://www.cs.northwestern.edu/~agupta/_projects/space_invad...](http://www.cs.northwestern.edu/~agupta/_projects/space_invaders/index.html)

~~~
opencl
It runs fine on W10, just needs vsync forced on to play at a reasonable speed.

------
AnotherHustler
If you want to be OCD about it - here's how the original arcade game worked...

[http://www.computerarcheology.com/Arcade/SpaceInvaders/](http://www.computerarcheology.com/Arcade/SpaceInvaders/)

------
sehugg
Here's my version targeted for the original 8080 hardware, in C:
[http://8bitworkshop.com/v2.1.1/?platform=mw8080bw&file=game2...](http://8bitworkshop.com/v2.1.1/?platform=mw8080bw&file=game2.c)

------
weeber
Interresting, but the OpenGL setup is not necessary?

~~~
MikkoFinell
Why not?

~~~
grenoire
The author is handling sprite rendering entirely on the CPU, he's only using
OpenGL to put a bitmap on the window. Little bit unnecessary.

~~~
flohofwoe
GLFW+GL provides a portable way to do this though. Otherwise you'd need to
mess with platform-specific window systems.

(something like minifb would be a more minimal option though:
[https://github.com/emoon/minifb](https://github.com/emoon/minifb))

~~~
Narishma
SDL is more than enough for something simple like this. You don't need to mess
with OpenGL.

~~~
weeber
Yes with SDL Surfaces.

~~~
krapp
Textures would be better. Surfaces are raw data, but textures are optimized
for the individual hardware.

------
aquova
A little bit off topic, but what are the best libraries for drawing simple
graphics like this? I've been looking into making a small graphics project and
I'm not sure which is the best to use. It only needs to draw basic shapes like
ellipses, or rectangles, or just specific pixels. I've been looking into SDL2,
as that seems relatively popular and portable, but I'm curious to see if
there's any other libraries that are recommended.

~~~
sfifs
While this may seem heretical to many, why not consider SVG or HTML5 canvas?
Widely supported, Ultra portable and very readable code unless you are looking
for stuff that needs fancy acceleration.

------
vardump
"From scratch" made me expect something like "From NAND to Tetris".

[http://www.nand2tetris.org/](http://www.nand2tetris.org/)

Or Space Invaders not on modern hardware, or at least on an emulated 8-bit
system.

------
zorkw4rg
now that unreadable shader trick might be neat and all, but since GLSL
supports if statements why not use this and make it readable? There certainly
won't be any performance issues with rendering a single triangle, but I
suppose people want to feel clever?

[https://rauwendaal.net/2014/06/14/rendering-a-screen-
coverin...](https://rauwendaal.net/2014/06/14/rendering-a-screen-covering-
triangle-in-opengl/)

~~~
Grieverheart
Hi zorkw4rg. Thanks for having a look at the tutorials. What makes the vertex
shader not readable in your opinion? If you substitute the different values
gl_VertexID can take (0,1,2), it's not hard to calculate the values of
gl_Position.

~~~
zorkw4rg
Its certainly not hard to calculate but a if this index then this vertex
coordinates, and so on, seems significantly simpler than having to calculate
anything at all? It sure what be more verbose though.

------
dexterdog
He seems to have skipped over the creation of the universe step at the
beginning.

~~~
crooked-v
Well, we still don't know what programming language the universe runs on, so
properly documenting that part would be a bit tricky.

~~~
chii
I'm fairly certain that mathematics is the language that the universe is
written in...

~~~
tabtab
No, we use math to model it, but whether our models are "perfect" may be very
difficult to ever know. Since we cannot model every atom, we don't know
whether the differences between our model and reality are because our models
are wrong or if we simply have imperfect inputs (starting positions) in them.

