top of page
Search

Mbed Fruit Ninja

  • Writer: pinnintimohit
    pinnintimohit
  • Apr 21, 2021
  • 2 min read

As part of my ECE 2035 class, we were instructed to build a replica of the popular phone game Fruit Ninja using the arm mbed microcontroller and C & C++. After being given a very basic shell script that spawned fruits from the top and left of the screen, we were instructed to complete the game by making a player character controlled by an accelerometer that can throw knifes to slice fruit. We also had to implement a score counter, menu and game won/game over screens, and all of the fruit cutting and piling up of fruits on the bottom of the screen (in the compost pile, similar to a Tetris game). First, we had to create the circuit from a circuit diagram (shown below). This included connecting the LCD screen, push buttons, and accelerometer to the mbed microcontroller on a breadboard after first installing software onto the controller and booting it up for the first time.


After this was the coding. We first had to update the uLCD panel with the creation of the player, knife, and score objects at the beginning of the game, and read inputs from the accelerometer and push buttons to control the player and the knifes. The knifes had to be moved one step to the right every single frame, which took a lot of initial effort. Soon after, I programmed the fruits to fall into the compost pile if the touched the bottom of the screen, which originally wasn't so difficult. It was adding that increase to the original compost pile which took a lot of work, especially because some of my constants from the .h files were not being loaded into my .cpp files. I eventually replaced my constants with numbers for simplicity since they all referred to the same thing (with the intention of going back and redefining variables again when I become more familiar with C++ syntax, which I'm still working on). Finally, I put calls to all of these methods in a while loop in the main and added a method to determine whether fruit where contacted by a knife to repeated update the images on the screen until the boolean flags that determined the end of the game were triggered.



The end of the game was determined by two flags; one that would be triggered if the player hit a bomb or if one of the compost piles got too high for the end of the game. The other flag would be triggered when the score reaches a certain settable amount (I set it to 3 for myself because I'm not very good at video games). I eventually learned some of the special syntax that the uLCD had for drawing objects that were more complex than rectangles and I created my own sprite, a TNT box (similar to Minecraft TNT) to replace the bombs which were originally just red boxes. Although there's still some more advanced features that I would like to add, here are some pictures of the current project thus far:





 
 
 

Komentáře


  • Instagram

©2021 by mohitpinninti

bottom of page