Weapons, in a lot of games they are very important. And although they might seem quite simple (you just push a button and it works), there is quite a bit more to them. To illustrate this, I’ll give a detailed explanation of how I programmed the shotgun in my arcade game.

When I started building my arcade cabinet I didn’t have any wires, but that soon changed as I added the buttons to it, which meant 3 outgoing wires from the breadboard (2 to the button, 1 to the pi), and 2 for the voltage supply to the buttons. After that came the sound system, which used even more wires, then I added the LED-strip, and the central power supply and…, Well, you get the point. I kept on adding those wires without any rhyme or reason and it all just became one big jumbled mess.

The game that will run on my cabinet is coming along nicely. The game is based on Super Crate Box, and follows the original closely. Four weapons are implemented right now (pistols, dual pistols, machine gun, grenade launcher), as well as 2 enemies and 2 levels. Here is some footage of the game that will be running, recorded on my laptop.

Last post, I discussed using the APA102 LED strip with the raspberry pi. You can create very cool effects with it, but doing so requires quite a bit of code, so I created a library with some basic utility functions and animations for the APA102 LED driver, and I’ll be expanding it in the future as I need more animations for my arcade cabinet. In this post I’ll cover the basics of this library.

LED-strips are awesome things, and they aren’t hard to use if you know how to use them, but only íf you know how to use them. While there may be many guides to connecting it to an Arduino, guides on using it with the Raspberry Pi are quite sparse, and not everything might be as straightforward as it seems. We’ll be using C++ and the wiringPi library to drive an APA102 led strip.

Previously we saw how to get sound to work on the Raspberry Pi with SDL2 and the SDL2_mixer library. Although this works for simple situations, you’d like your game to have a more sophisticated sound system as we often have many different sound effects playing at once, as well as background music. We could load and play these every time we need them, but when things get busy on the screen this might lead to quite the performace drop.

I love Go. I love it’s simplicity, it’s static typing, it’s speed, it’s networking capabilities and how you can get libraries from GitHub with just one command without any further setup. But Go alone is often not enough, and you need something more, and that is where Gorilla Mux comes into place. The nature of Go often means you’re writing quite a bit more code than with other languages, but you get simplicity in return for that. To prevent some code from becoming way too big, I’ve been searching for an easy way of writing middleware for Gorilla, but most of the Google results involved implementing http.Handler or a different interface, which in my opinion is way too unwieldy when you can also use a very powerful feature of the Go programming language: the closure.

Last time we saw how to connect an amplifier and speakers to the Raspberry, now we’ll look at playing some sound with the SDL2_mixer library, but first we’ll have to enable sound. As I said in my previous post, sound on the Raspberry Pi is not as straightforward as you’d like it to be, so there are quite some steps involved to get it working properly.