This may be the craziest thing I've ever made. Super janky right now, but I'll have the kinks worked out soon enough.
Hopefully this project won't turn out like 5126310810.
For those who havenât seen it yet, hereâs my first game: A clone of the classic arcade game Asteroids.
It feels awesome to be done with my first and second gamedev projects (the second being this blog). Iâd like to take this opportunity to do a little reminiscing, so please indulge me while I show off the evolution of my first project. These examples will work best on a laptop/desktop since they make heavy use of keyboard events.
Click the following images for live demos - controls are described in the captions
Now weâre getting somewhere! This is when I got the idea for the Asteroids clone - not sure if I had fully committed to the idea yet, but it seemed like a fun project.
Yeah, the player controls are backwards. And your speed is unbounded. You can also just keep accelerating in a single direction until your ship is going so fast that your ship seems to exist in several places at once. Progress!
Shooting! Well this is pretty crazy. I hadn't quite figured out the right way to calculate bullet velocity and obviously you can shoot an absurd number of shots. Also, Iâve put a speed limit on your ship, but as you can see from the helpful red velocity vector protruding from your vessel that your ship really doesnât handle correctly when youâre close to top speed and turning... Progress!
Now you can hit asteroids with your shots! How the hit detection works in this example is by comparing the max radius (the distance from the center of the asteroid to its farthest vertex) to the distance from your bullet. This definitely leaves something to be desired! But hey, it works. Progress!
Boom! Now the distance formula for colliding asteroids and bullets is much smarter. First, make a first pass to see if the bullet is even close, then calculate the distance between the center of the asteroid and the "radius" of the asteroid at the bullet's angle. Works like a charm! Oh, and you have a score now - that was pretty easy to add. It's boring though - the numbers are just way too low. Also, what a difference those visual flourishes can add! Thrusters AND particles? Itâs amazing how much more fun the game gets with these small additions.
Now you can die! Well this is actually less fun since the collision detection is complete bullshit. Again, a naive first pass just as a proof of concept - seems like thereâs a theme developing here. Maybe itâs just me, but this is the only process I know which actually works. You just have to start with bullshit and mold it into something better. The tricky part is probably knowing how to implement your bullshit in a way which allows you to iterate meaningfully on it. That is truly an art.
Added a death animation. Maybe you'll notice that it looks a bit... off. The ship pieces not only rotate, but change their length (as if rotating in three dimensions, not two). This was another incredibly frustrating and stupidly syntactical bug which made me a bit crazy. If I do a technical writeup at some point Iâll be forced to confront my worst fears and relive this period of temporary insanity. Progress!
Now the collisions between player and asteroid are much fairer. Basically, this collision detection algorithm calculates the point of intersection between every line creating the ship and asteroid and if that point falls on the actual line segments that make up the ship then thatâs a collision.
Well, here we are with the finished product. There were plenty more steps, but most of them were boring. Hope you enjoyed this odyssey as much as I did - thanks for reading!
Well, how about that? A blag.
I hope to update this somewhat frequently. I'll probably start by writing a few posts about my first ever videogame: a copy (in spirit) of the 1979 arcade classic Asteroids.
If folks on basket carriage are interested, I'll write about the math I had to use to make this game: basic calculus, linear algebra and of course every highschooler's favorite: trigonometry. Or maybe try to document my entire next project from start to finish. Or perhaps a post-mortem about all of the lessons I learned from making this game (protip: surprisingly few). Who knows?
Oh, and I should probably thank makemistakes for the blog theme. It's built using Jekyll and if I can get it up and running in a single night, then they must be doing something right.