7 ms·
Space Invaders from Scratch
- nils-m-holm 8y agoWriting 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 8y agoSpace 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 8y agoMe 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.
- weeber 8y agoInterresting, but the OpenGL setup is not necessary?
- MikkoFinell 8y agoWhy not?
- grenoire 8y agoThe 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 8y agoGLFW+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)
- newnewpdro 8y agoSDL2 is pretty popular these days
- Narishma 8y agoSDL is more than enough for something simple like this. You don't need to mess with OpenGL.
- weeber 8y agoExactly!
- Grieverheart 8y agoOne of my goals is to reuse parts of the engine for future projects where hardware acceleration might be used.
- scottlu2 8y agoA Javascript based one: https://codesandbox.io/s/2px9y0p480 https://codesandbox.io/s/2px9y0p480
- ivan_ah 8y agoNice! 2k lines of js, but it's all there and quite readable. The gif-backed DemoMode is also very cool.
- nyrulez 8y agoThis 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_invaders/index.html http://www.cs.northwestern.edu/~agupta/_projects/space_invad...
- opencl 8y agoIt runs fine on W10, just needs vsync forced on to play at a reasonable speed.
- anoakie 8y agoI 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
- dexterdog 8y agoHe seems to have skipped over the creation of the universe step at the beginning.
- crooked-v 8y agoWell, we still don't know what programming language the universe runs on, so properly documenting that part would be a bit tricky.
- chii 8y agoI'm fairly certain that mathematics is the language that the universe is written in...
- dexterdog 8y agoBut what language was that written in? I always assumed it was logo because it's turtles all the way down.
- tabtab 8y agoNo, 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.
- Grieverheart 8y agoMaybe I'll write a Haskell tutorial...
- sehugg 8y agoHere's my version targeted for the original 8080 hardware, in C: http://8bitworkshop.com/v2.1.1/?platform=mw8080bw&file=game2.c http://8bitworkshop.com/v2.1.1/?platform=mw8080bw&file=game2...
- aquova 8y agoA 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 8y agoWhile 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.
- feiss 8y agoHtml 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 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.
- bigiain 8y agoHeh - 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 8y agoIncreasing few people know what the hell your on about. Parallel port, you were lucky. 15 pin analogue for me.
- mar77i 8y ago15 pin analogue? Luxury. I had to manually wire a piece of wire to a microchip to attach a joystick made of dinosaur bone.
- krapp 8y agoSince everyone is showing off theirs here is my half-assed attempt: https://bitbucket.org/kennethrapp/spaceinvaders https://bitbucket.org/kennethrapp/spaceinvaders
- aerique 8y agoAnd 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.
- AnotherHustler 8y agoIf 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/
- vardump 8y ago"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 8y agonow 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-covering-triangle-in-opengl/ https://rauwendaal.net/2014/06/14/rendering-a-screen-coverin...
- Grieverheart 8y agoHi 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 8y agoIts 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.