1Designing the Game
For this Pong game I wanted to keep it relatively simple, which meant no computer controlled paddle or fancy ball reflection algorithms. Basically, there is a single paddle that a user can move up or down, and making the ball collide with the paddle would cause its x axis vector to flip. Each time the ball gets hit there is a sound that plays.
When the game device is powered on, a screen comes up with the game title and instructions. Additionally, my mother created a small theme song that loops in the background until the top button is pressed.
2Designing the Gaming Device
My go-to CAD program is Fusion 360, so I decided to use it to design my pong gaming device. I began by designing each component used: an OLED, Arduino Nano, and a speaker.
3Constructing the Device
I began by 3D printing each part, consisting of the lower half, the upper half, and 2 buttons.
4Programming the Game
The use of a simple interface was vital to keeping the program small. I started by adding several libraries: Adafruit_GFX, Adafruit_SSD1351, and the Arduino Timer library. Next I defined my pins and colors, such as the OLED's pins and 16 bit color definitions. In my code there are also 4 ways to change how the game plays, such as changing the paddle dimensions and how quickly the ball moves. A section then exists where each variable is defined, including the score and various coordinates. Whenever the device is powered on an image of a ball and some text appears on the screen, along with a little theme song which is defined earlier in the code. Once the game starts two timers are created, one that updates the paddle, and the other updates the ball. Each time the ball's position updates its coordinates are checked to make sure it doesn't go past the screen border or if it's touching a paddle. Each time it bounces either its x or y axis is inverted and a small tone plays. Watch the video at the beginning of this writeup to see how the game plays.
The name of the game is to get the lowest score possible. There is no time limit, so it is very enjoyable and even trance-inducing. All that is necessary is pushing one of two buttons to move the paddle up or down. It is also possible to add a way to store the highest score using the Arduino's EEPROM.