The Software Stack

A project log for ASTROGUN

An Asteroid Shooting Game

avishorpavishorp 08/18/2014 at 10:440 Comments

Software documentation is a complex issue, and project log is probably not a best place to do it. Nevertheless, here's a short review of the major software components that were used in the creation of the ASTROGUN.

First of all - the Pi operating system Raspbian. There's not a lot to say about it that already haven't been said. Just copy the image onto an SD card, put the card in the Pi and off you go.

The application was written in the Python language, also an extremely popular choice for Pi programming. All the main logic of the game (Asteroid generation, scores, lives, etc.) were written in pure Python. Some places required a little number crunching. For example, when a shot is made the program calculates whether it would hit an Asteroid or not. Such calculation were made using NumPy. The general logic of the game is quite simple. The player always stands at a fixed point (0,0,0) and Asteroids are randomly generated at various angles and times. Every Asteroid is initially created at a fixed distance (one that is far enough to looks like a single pixel to the player) and moves along a linear course towards the player. If the Asteroid arrives to a certain distance from the origin, it is considered as a hit. When the player moves the gun, an IMU is used to sense the direction (angle) to which the player is looking and adjust a virtual camera, eventually causing the correct graphics to be drawn. When the player squeezes the trigger, a bullet is created with a course opposite to the Asteroid - it starts from the origin and travel in a straight line at the angle the user was looking at when hitting the trigger. If the bullet hits the Asteroid, it explodes and a point is added to the player; otherwise it travels until it hits a certain distance from the origin and disappears.

The 3D graphics task is performed by the Pi3D library which acts as a bridge between the Python code to the GLES interface, which in turn is executed on the GPU. When I started the project, I had no previous experience in 3D graphics (though I was familiar with its concepts) and this library helped me to quickly ramp up fro idea into a full application.

Finally, the gun orientation was calculated, as I already mentioned, from the outputs of an IMU (Accelerometer, Gyroscope & Magnetometer). The fusion of the output of those sensors into an orientation angle (not a trivial task at all) was done using the RTIMULib. During the development, I had to interface that library, which was written in C++, to the main application written in Python. To do this, I created a Python binding module, which was contributed back to the project.

This is not a full list of course. I used PyGame to add sound effects, Blender to post-process the Asteroid models (grabbed from the 3D Asteroid Catalogue), Inkscape to create graphichs and many more. To put it simply, open source is what made this thing possible!