Yuecheng Peng

About Me

CARROTS WILL LEAD THE WAY

Game Demo

May 2022 (finished in 2 weeks)

Project completed at Zhejiang University with Xiuyang Wu, Zhiyu Xie

Role : Team leader, C# developer (Unity), scene & UI & story designer

​Instructor: Weitao You, Lingyun Sun

VIDEO DEMONSTRATION

This video below incorporates the background and demonstration of our game. If you want to have a quick glimpse into what our game is about, check this video out! ☺️

INTRODUCTION

We wanted to build an interactive prototype of a puzzle-solving block toy. The game's goal is to lead the rabbit to eat all the carrots in a maze. Meanwhile, there are invisible traps, players need to refer to the LED dot-matrix display to figure out where these traps locate. Different colors of blocks represent different moves of the rabbit, including "forward", "clockwise turn", "anticlockwise turn", and "loop". The player can send movement command sequences to the rabbit by assembling blocks differently.

We got this fantastic inspiration from one Google Doodle game.

Additionally, in a technical sense, this is one of our attempts to combine Arduino, Raspberry Pi, and computer -- three most commonly used platforms for prototyping -- in one project, and achieve communication among them.

GAME BACKGROUND

Nika the Rabbit is your best friend. You can feel that something special of her is attracting you... Together you live happily.

One day, suddenly, a dark elf kidnapped Nika. "Haaaa! I gonna absorb her Rabbit Power for my magic powder!". Poor Nika thus got prisoned in a maze built by dark spell.

Burning with anxiety, you turned to a just Magician. He gave you a box and said "make full use of this magic box... and you can guide your friend out of the spell maze!"

When you were about to ask how to use the box exactly, he disappeared in a puff of smoke.

Upon the box you fixed your eyes, and it wrote "Carrots will Lead the Way "

GAME DESIGN

Interaction process

All hardwares (Arduino, Raspberry Pi, etc.) are placed in a game box. Players place blocks on this box and can check some important information (progress of the game level and trap locations) on the box. Plus, we used a computer to run our Unity program.

The playing process is simple:

➊ Analyze Maze

Players can see the maze on the computer (Unity) and check out whether there is any trap using the map (LED dot-matrix) on the game box.

❷ Place Blocks

Player place blocks and hit button1 to take a picture of blocks, which will be translated into movement command sequence to send to the computer

❸ Get Result

Unity will run this sequence to see whether can the rabbit eat all carrots. If successful, the progress indicator (a rabbit) will jump one step forward.

​Judgment for winning & losing:

Game Result Conditions Feedback
Fail step into trap fail sound effect
leave carrots uneaten stop after executing movement sequence 
Success eat all carrots success sound effect & progress indicator (rabbit) jump a step forward

Building blocks

Four different colors are used in blocks to represent four different movement commands:

jump one step forward

anticlockwise turn

clockwise turn

loop

(dice-like loop block, number represents times of loop)

Players place blocks from left to right to send sequential movement command to the rabbit, place blocks on the top of the loop block to incorporate movement in the loop body. For example:

​jump two steps forward

​​jump one step, clockwise turn, jump one step

Jump two steps, clockwise turn, jump two steps, clockwise turn, and jump one step. In this description, we can actually use a loop to solve it.

Furthermore, we can simplify it by letting the loop body run for 3 times, since the game's goal is just to eat all carrots.

We can also build multi-loops. Sometimes it can be useful when there is limited vertical space for blocks to place.

Traps

To make the game more challenging, we design a trap mechanism. Specifically, there are several "trap bricks" in the maze (looking just like normal bricks) but once the rabbit jumps onto a trap brick, the player will lose the game.

Players can check out where these traps locate by referring to the LED dot-matrix display on the game box, where traps and the position of the rabbit will both be marked out by LED light. There are four dimensions on the dot-matrix map, players can use a button to switch between different perspectives.

The example below shows a maze without traps and the LED light position represents the location of the rabbit. As a result, we can figure out which dimension is displayed according to the position of the rabbit.

This is a example of how LED dot-matrix display shows the location of traps.

Game play

To make the game more interesting and challenging, we place a limit on the number of blocks of each color (5 blocks per color), and the maximum number of blocks that can be placed vertically and horizontally (horizontally: max 5 blocks, vertically: max 4 blocks). This will lead to some very interesting solutions to the maze.

In this case, if we use a normal way to place the blocks, it will look like:

However, we use 6 horizontal positions, more than the maximum number allowed for horizontal blocks.

Therefore, we can place the blue and the red block on the top of a loop block, using vertical "complexity" to replace horizontal "complexity"

HARDWARE

Function design

To achieve the game design mentioned above, we use a computer (run Unity), Arduino, and Raspberry Pi. Specifically, they do the following things respectively.

  • after pushing the map switching button, change the dimension of the map
  • after pushing the upload button, take a picture of the blocks and convert it into a movement command sequence using the CV algorithm.
  • send the sequence to Unity and receive the game result sent from the computer.
  • if successfully pass the level, send a success signal to Arduino by USB serial
  • ​build a server using C# to receive the sequence sent from the Raspberry Pi and send the game result back to Raspberry Pi.
  • build game scene and implement logic (decoded the sequence into the movement of the rabbit and judgement of game success).
  • receive the success signal sent from Raspberry Pi and control the rotation of the servo motor.
  • refresh traps shown on the LED dot-matrix display once receive the signal to change the dimension of the map.
  • We used Arduino to control the servo motor because we found that using GPIO or pigpio port from Python on Raspberry Pi cannot control the angle of the servo and its moving speed stably. Using Arduino, on the other hand, provides easy and reliable control on the servo motor.

    Communications

    We used Websoket and USB Serial to realize the communication between computer, Raspberry Pi, and Arduino. Besides, we used different languages on these platforms, thus we also achieved communication between different programming languages (C#, Python, and C).

    build a websocket server on Unity (C#), to communicate between computer and Raspberry Pi:

    sending message from Raspberry Pi to Arduino using Serial write (Python):

    receive message from Raspberry Pi using Serial.read() function on Arduino (C):

    progress indicator

    We used a progress indicator (a rabbit) on the game box to indicate the progress of the game. When players pass one level, the rabbit will "jump" one step toward the destination. It is, however, quite challenging to animate the "jump" action of a rabbit physically. To achieve that, we design a ingenious mechanic:

    We used magnets to achieve a "non-invasive" way to move the rabbit. In this way, we can guarantee the integrity of the game board: we did not need to drill holes or tracks on it.

    Furthermore, through our experiment, we found that the rabbit can literally "jump" under proper friction and speed of servo motor:

    © 2023 All rights reserved by Yuecheng Peng.