Arcade Stacker Game

by Maxym in Circuits > Arduino

2098 Views, 13 Favorites, 0 Comments

Arcade Stacker Game

rn_image_picker_lib_temp_f8c332ea-d45f-4c0e-b256-9e032b2a3740.jpg
rn_image_picker_lib_temp_554fa234-6cc7-4b15-ac13-885106fc1c9c.jpg

What's this?

I wanted to create a small game that doesn't require many materials and complicated wiring. So I came up with a game that is fully playable with only 1 button and a "screen". This is a downscaled version of the Stacker game that you can find in Arcade Halls. Its main purpose is being a desktop toy, but you can do whatever you want with it. The controls of the game are not hard, because you can only press 1 button, but it does take some skill to win.


How does it work?

In this game there is a pixel that moves from side to side. When you press the button, you place the pixel on its current position. Then the next layer above that pixel starts to appear and move. The higher you get, the faster the pixel will move. In order to win, you have to reach the top.

Underneath is a video of some gameplay.

Supplies

Arduino Parts:

Arduino Uno R3

USB-B USB cable

LED Matrix 8*8 with MAX7219 Module

5 Dupont Female-Female (in my case it came together with the Matrix)

DFRobot Gravity LED Switch Module - White

Digital Sensor Connector (in my case it came toegether with the Switch)

8 Dupont Male-Male

(Optional)

Some Heat Shrink


Casing:

30x50cm 3mm MDF

Hot glue gun

Building the Arduino Circuit

ArduinoDrawing.png
rn_image_picker_lib_temp_b432a826-705f-44c1-91f9-a8ba2683d7c6.jpg

First we need to get the electronics hooked up. For this you'll need to use the schematic made above. Be sure that the right wires are connected to the right ports of the arduino. Otherwise it won't work with the code that comes later.

As you can see in the Supplies list, there is some Heat Shrink. I reinforced the wires with the Heat Shrink so that they won't disconnect too quickly. This is not necessary to do, but it helps.

Code

In order to play the game, we need some working code.

First we need to import other files that help with controlling the LED Matrix. These are "LedControl.cp" and "LedControl.h". These are files I found online and they make my life way easier for controlling the LED's of the Matrix.

After that we make our own file which I named "Stacker.ino". In this is the complete behaviour of the game. If you dont care about what is exactly inside the code, you can just use this file and upload it to your arduino and start playing. But I will give some explanation to a couple important variables and other important things.


#include "LedControl.h"

Make sure that you include the LedControl.h file. Without this you won't be able to easily control the Matrix.


int DIN = 11;
int CS = 7;
int  CLK = 13;
int BUTTON = 4;
LedControl lc=LedControl(DIN, CLK, CS,0);

These are the ports that I've used in order to handle the input and output. These have the same name as the names you can see on the Matrix. These variables are also used inside the LedControl code.


//button variables
bool buttonOn = false;
int buttonValue;

Because I didn't use my eyes while searching a fancy LED button, I accidentally got a switch instead of a button. Because of this, I had to convert the switch to work as a button. These variables are then used to keep track of the switch input.


//Some game variables
int speedReduction = 10;
int currentSpeed = 100;
int startSpeed = 100;

These are the variables you can change in order to change the difficulty of the game.

The startSpeed if the time it takes for a pixel to change from 1 position to another. So if you make this value higher, the pixel will move slower and give you more time to react, thus making the game easier.

The speedReduction is the values that reduces the currentSpeed to a lower value. This is used when you start stacking the pixels. Each time you go up 1 row, the speed increases. The higher speedReduction, the more the game will increase in speed to more you stack. If you want your game to have the same speed all the time, you can change speedReduction to 0.


int StackerMatrix[8][46] = {
 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
 {0,0,0,0,0,1,1,1,1,1,0,1,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,0,1,0,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0},
 {0,0,1,1,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,1,0,1,0,0,1,0,0,0,1,0,0,1,0,1,1,0,0},
 {1,0,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,1,1,0,0,0,1,1,1,0,1,0,0,1,0,0,0,0,1},
 {0,0,1,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,1,1,1,1,0,1,0,0,0,0,1,0,1,0,0,1,0,0,0,1,1,1,0,0,1,1,0,0},
 {0,0,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,1,1,0,1,0,0,1,0,1,1,1,0,1,0,0,1,0,0,0,0,0},
 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
};

When you start the game up, you are welcomed with a scrolling text. In order to make this work, I used a 2D int array in which you can vaguely see the text already. The 1's are the LED's that will be turned on and the 0's are the ones that will be turned off.

A small problem I almost came across is that this costs 'a lot' of data which this arduino does not have much of. The arduino has only 2kB of data and this fills it up quickly. So if you want to have way more scrollable text, then you'll need to either optimise this array or get a different arduino.

Casing

FinalBox.png
GeneratedBoxes.png

Before I started making the drawing for the casing, I looked up some sites that would help me with that. I came across a super useful site that generates some cool boxes, based on variables you give.

There are a lot of different options that didn't fit the style that I wanted. But because I didn't have much experience with drawing these boxes myself, I had to come up with a creative alternative. I generated 3 different smaller boxes, which would together build the arcade machine style that I wanted. I used the generated files, imported them in Illustrator and modified them to fit together.

I didn't have my arduino stuff with me at the time, so I had to search some measurements and hope for the best. It turned out to be exactly right on the first go.

Building Time

rn_image_picker_lib_temp_8c800aee-3976-44ed-a71e-79565d8c0a9b.jpg
rn_image_picker_lib_temp_02f67ba7-cc66-4665-986d-6e0548a72e59.jpg
rn_image_picker_lib_temp_b432a826-705f-44c1-91f9-a8ba2683d7c6.jpg
rn_image_picker_lib_temp_c1e9121d-a502-4297-b9e2-dbc10b51d9aa.jpg

Because I didn't have my arduino stuff at home while I was working on the drawing, I didnt know where the holes for the arduino should be. So I drew on the back piece where those holes needed to be and created the holes.


But once you've done this, you can attack the electronics to the casing. In this case I used a hot glue gun, and gave the button a little extra support by using some scrap MDF. The button really needs this, because otherwise it would just come loose when you press the button too hard. (Make sure that you don't get glue underneith the button like I did)


After this you can put everything together, close up the back, put it in a power source, and start playing. If you want to glue everything together, you can do that. I didn't do it, because I wanted to be able to check the insides.

LED Strip

rn_image_picker_lib_temp_d1fcbfe6-63d1-4d3c-b457-f12965920ae9.jpg

In the beginning I wanted to add LED strips in the slits above and below the Matrix, but they were too bright and would take away the focus from the game. If you want to add some sort of decoration to it like this, then you can do that. I have not included this in the supplies or the schematic.