Introduction: Pacman on a String
Well it is not exactly a Pac-man, but it basically moves along a long LED strip to collect good things and avoid bad things. So you get the idea!
A group of middle-school kids have been learning and playing Arduino, NodeMCU and MQTT with me over the weekends, and as I heard about a Maker-Faire event, it is a perfect opportunity for us to make a cool game with what we have learned so far.
So the kids came up with the colorful gems to be collected, we call them Emerald, Gold, etc., and introduced an alarming wasp to chase you around. The game is very simple to get started, but quite challenging to get high score. You move a segment of LEDs along the strip, push left to collect gems and right to knock out wasp, but timing is significant in determining your score, which I will explain later in game mechanics.
Step 1: Build Components
We use an Arduino Mega board to run game basics: joystick, LED strip, Sparkles, Wasp, random appearance and disappearance, collision and game events, scoring.
NodeMCU bridges game with Internet. The events and scores are published to a MQTT channel, so interested app can receive and process the information.
Android App listen to MQTT channel, and display the score board as the game progresses. When a game is over, it let you save the game score and display in the game leader board.
The MQTT channel and messaging are transient in nature, so the leader board is also kept in a cloud database, so whenever Android App starts up, it will get the leader board as of now.
Step 2: Game Mechanics
We use a joystick to control the movement and actions, well simply moving a Light Saber (a 5-LED segment of blue light) up and down the LED strip.
When Light Saber reaches a sparkling gem, push joystick left to collect it and get score. Remember the segment has 5 LEDs, labelling it A-B-C-D-E. If you collected the gem with "C", you get 100 points, with "B" or "D", 50 points, and with "A" or "E", you have 25 points. So the game is easy that you have 5-LED to touch the gem, but meanwhile it is challenging that you need to have very good timing to use "C" light to maximize the score.
The gem stays in a location - it does not move, but it has limited time staying there - that is, it will disappear after a random duration of time. So you need rush there to get it. After some random time of disappearance, the gem will pop up at another location, and again you have limited time to reach there to get it.
The gems are good. And the world is fair, with anything good it comes bad thing. A red color LED is a wasp, it looks like a ruby gem but it keeps chasing you (Light Saber). Again, it has a random amount of life time. You can run away from it until it disappears (you get 0 point), or you can knock it out at the very moment it touches you (you get some points), or otherwise, it touches you and it stings you - you lose points, and you lose valuable game time as it frozen you for a while.
The game starts with a START button, and you get 45 seconds to collect gems, knock out or avoid wasp to achieve highest score. When time is up, the game is over, and you will be put in a place on a leader board.
If the game idles for some time, it goes into auto-play mode. It may play better or worse than you.
1. 45 second game time,
2. gem collecting points: C = 100, BD = 50, AE = 25
3. wasp sting deduction: each sting is -24, depending on wasp life time, it could sting you several time while you are frozen.
The game is easy to get started by anyone - you can align 5-LED segment next to gem and push joystick to the left, right? At the same time, the game is quite challenging if you try to get a high score, it requires very good timing and anticipating to align middle C to a gem, and it requires you have good reflexes to knock out wasp before it stings you.
Step 3: Material List
Arduino Mega (~$45)
Official board from Arduino.cc: https://store-usa.arduino.cc/collections/products-...
Or any variants ($15), you can search "Arduino Mega" on amazon.com
Or pay a little more, and buy it on amazon.com
LED strip (~$37)
Power source (~$17)
Box: I re-used a clear acrylic box from another product package. But you can buy any wood or acrylic box for about ($10). I'd suggest the dimension of around 8" x 8" x 3".
Wires, capacitor, connector, resistors: Obviously you need some jumper wires to connect the circuit. Good to have a capacitor and resistor to protect LED lights.
Telescope Pole: Use a long pole to put up the long LED strip, I have a 16 ft telescope pole.
Step 4: Hardware Build and Wiring
As shown in wiring diagram, the PIN assignment on Arduino Mega board:
PIN 8 - Joystick Up
PIN 9 - Joystick Down
PIN 10 - Joystick Left
PIN 11 - Joystick Right
GND - Joystick Common
PIN 7 - Start button
PIN 5 - LED Strip
PIN 5 - LED Star
PIN 16 - RX
PIN 17 - TX
The PIN assignment on NodeMCU board:
D5 - TX
D6 - RX
You may reference the actual wiring from the photos.
Step 5: Software Coding
We have published our software code in github.
Arduino game code (https://github.com/raymondxie/JetReactGame)
NodeMCU communication code (https://github.com/raymondxie/JetReactComm)
Android score board and leader board (https://github.com/raymondxie/JetReactAndroid)
MQTT channel: We use CloudMQTT service to create a channel and use it in both NodeMCU and Android app.
Apex data store: A database service to save Leaderboard scores. You can save the game plays in other cloud data store.
Step 6: Maker Faire Event
The game was first publicly played on November 17, 2016, at Oracle Maker Faire. It was an instant hit, and people were having fun to play the game again and again. It is quite addicting!
It is a perfect game for the Holiday Seasons to play with family and friends!
Participated in the
First Time Authors Contest 2016
Participated in the
Arduino Contest 2016
Participated in the
Make it Glow Contest 2016