Hacker News new | past | comments | ask | show | jobs | submit login
Space Invaders from Scratch (nicktasios.nl)
212 points by Grieverheart on May 27, 2018 | hide | past | favorite | 40 comments



Writing a Space Invaders clone is such a rewarding task! :)

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


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.


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.


A Javascript based one: https://codesandbox.io/s/2px9y0p480


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

The gif-backed DemoMode is also very cool.


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...


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


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


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


And here's mine: 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.


I had to play until killing all the aliens at least once!


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


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


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...


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


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

http://www.computerarcheology.com/Arcade/SpaceInvaders/


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


Interresting, but the OpenGL setup is not necessary?


Why not?


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.


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)


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


Yes with SDL Surfaces.


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


SDL2 is pretty popular these days


One of my goals is to reuse parts of the engine for future projects where hardware acceleration might be used.


Exactly!


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.


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.


Html Canvas is easy and accessible for anybody, a safe choice. If you look for something native and accelerated, the best thing I found is Tigr https://bitbucket.org/rmitton/tigr/src

I really miss 486 days, when all you needed to paint pixels on screen full speed was 2 ASM instructions and writing to video memory. Full freedom and creativity without any technical barrier.


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

http://www.nand2tetris.org/

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


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...


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.


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.


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


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


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


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.


But what language was that written in? I always assumed it was logo because it's turtles all the way down.


Maybe I'll write a Haskell tutorial...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: