Pac-Man on a String

Oracle hosted the first-ever company co-sponsored Maker Faire event on November 17, 2016.

When I heard of the event, I had something in my mind that I would encourage a group of middle-schoolers to make a game for the event. I have been teaching them occasionally on Arduino, NodeMCU and MQTT concept over some weekends, and this is the perfect opportunity to put them together in a build.

After some brain-storming, we came up with “Pac-Man on a String” concept. And because of the way of this game plays, the player needs to rush to a location and do a quick action, I picked the team name as “JET – React” to describe the game play, (and if you are writing JavaScript at Oracle, you know JET and React).

There are some interesting design points we have put into the build:

  • We want to make a game that is simple, anyone can come by and play;
  • We want to make a game that is addicting and challenging (which seems to be conflicting with point #1), so people can keep playing for many times and not getting bored;
  • Simple control and interface.

So we adapted the game plot of well-known Pac-Man, and changed narratives to collect gems (as Emily likes sparkling gems), and changed ghost to wasp so we can flee or just attack at the spot with precise timing. Coding-wise, it turns out “wasp” is very much like “gem” except it chases player (represented as 5-LED segment).

The modified game story and play mechanism fit very well with the limited control and interface we have. Making a interesting game with just one joystick and one LED strip, that presents serious constraints as what you can work with. But in the end, I think we achieved excellent results.

To make it simple, we coded 5-LED segment (we call it Saber) that a player can move it up and down along the LED strip, and use that to collect a gem or attach a wasp. Most people can align 5-LED to sparkling dot on the strip, right?

To make it challenging (that is to gain high score), we made the scoring logic to require a player has great timing and quick reflexes. First, all the gems and wasps can show up at any location, any moment, for any length of duration (all the parameters are randomly generated). So player has to move fast, and quickly decide what to do when multiple gems/wasps are showing. Second, the Saber has 5-LED segment, and if you use middle LED to collect a gem, you get 100 points; the two LED next the middle one will get you 50 points, and two side LED get you 25 points. So it has great incentive to use the middle LED to do your work, but it is very difficult to move the Saber to the right spot, it requires great skill of timing and anticipation. And finally, the wasp can sting you, but if you are quick enough, you can knock it out before it can sting you, and you gain points, that requires great timing skill. Overall, it takes practice to play this game well.

So here is the team info and game play description:

These are the components and flow for the game build.

The game code is on the Arduino Mega board, where the player moves Saber to collect and attack. The code controls all LED light state at all time, which represents space, gems, wasps, as well as detect the player action, and Saber to gem/wasp collision time. It has scoring logic when detected collision, and sends game events to NodeMCU for reporting.

The code on NodeMCU is to rely game events into CloudMQTT, so that the App on Tablet can get the events, and starts/stops game, or accumulates points. Once a game is over, the score is recorded into Oracle Apex database for keeping the Leader board.

First prototype build, using a wooden tea box:

This is the cleaned up final build, hosting all components in a acrylic box:

This is the close-up look at the inside of box:

Score board and leader board in an Android App:

The game as played out at the Maker Faire. Both adults and kids had a blast!

Update: Here’s a video of the gameplay.

3 comments

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.