Guy Dunton

Asteroids Redux

Asteroids Redux is a remake of the Atari classic game Asteroids. Written in C++ and using DirectX. Code available here

Youtube video of Asteroids redux

Original

Originally Asteroids Redux was written around 2014 using C++11 and DirectX 9. Almost all of the code was written from scratch (excluding a couple of libraries) and it features a few alterations over the original game.

World Wrapping

In the original Asteroids, objects would dissappear completely off the side of the screen before appearing again on the opposite side of the screen. In Redux I added custom rendering so that objects would be visible on both sides of the screen at the same time.

A 3x3 matrix of cameras was used to render objects. When an Asteroids (or player) reaches the edge of the screen they are rendered by the main central camera but also by the camera at that edge. This overlays the object on the screen multiple times and gives the illusion that the object is in both places at once.

Rigid Body Collisions

Asteroids Redux features a rigid body collision system, meaning that asteroids will bounce off each other as well as the player.

In order to prevent slowdown when large numbers of asteroids are on screen collision detection is optimized using a quad tree. This optimization means that the sreen needs to be full of asteroids before a slowdown due to collision detection is detected.


Rewrite

In 2018 I was migrating my website and decided to check out the Asteroids code which I had been using as part of my portfolio. I was not impressed. Rather than lose the code altogether I decided that I would refactor the code so that it was more representative of my current coding style and it followed best practices.

Refactor vs rewrite Note that I chose to refactor the code rather than throw it away and start again. I believe that attempting to rewrite the code would have taken a lot more time to do and would have left me fighting with a lot of the same bugs that I fixed in the original. I believe that I would never have actually finished a rewrite, whereas I could finish a refactor at any time because I kept the code working the whole time.

These are the bad practices I noticed as I went through the code, as well as how I removed/fixed:

Conclusion

The code is still not completely refactored but at least it contains fewer obvious mistakes and I’m not so ashamed to show the code to other people.