Custom Game Controllers assembled in lab sessions and mounted with Nokia N5110 LCD display and a FRDM-K64F mbed plus various buttons, a joystick, potentiometer and piezo. Designed a game called 'Fruit Basket' to be played on the game controller where the player controls a basket and moves it catch objects that fall from random points along the top of the display to collect score.

Dependencies:   Basket Catch_Model Fruit Gamepad N5110 Objects mbed

Revision:
14:e20bf6569607
Parent:
13:09a9ffd8eb60
Child:
15:03868ddf5bf3
diff -r 09a9ffd8eb60 -r e20bf6569607 Project_Submission.cpp
--- a/Project_Submission.cpp	Thu Apr 20 14:27:40 2017 +0000
+++ b/Project_Submission.cpp	Sat Apr 22 12:33:18 2017 +0000
@@ -12,6 +12,7 @@
 Gamepad pad; 
 Catch_Model catchm;
 Objects objects;
+Basket basket;
 
 int objects_speed;
 int lives;
@@ -20,6 +21,7 @@
 void init();
 void render();
 void welcome();
+void game_over();
 void instructions_general();
 void instructions_buttons();
 void set_brightness();
@@ -30,21 +32,19 @@
 {
     int fps = 8; 
     
+    init();
+    welcome();
+    instructions_general();
+    instructions_buttons();
+    set_brightness();
+    
     while(1) {
-
-        init();
         
-        welcome();
-        instructions_general();
-        instructions_buttons();
-        
-        set_brightness();
         set_speed();
         catchm.init(BASKET_Y,BASKET_WIDTH,set_speed(),LIVES);
         
         render(); 
         wait(1.0f/fps);  
-        //int lives;
 
         do {
             catchm.input(pad);
@@ -52,13 +52,14 @@
             
             catchm.check_a(lcd,pad);
             catchm.check_b(lcd,pad);
-            catchm.check_x(lcd,pad);
 
             lives = catchm.get_lives();
             render();
             wait(1.0f/fps);
             
            } while (lives > 0);
+           
+        game_over();
     }
 }
 
@@ -92,6 +93,32 @@
     }
 }
 
+void game_over()
+{
+    lcd.clear();
+    lcd.printString("   GAME OVER  ",0,2);
+    
+    char buffer[14];
+    int score = basket.get_score();
+    int print_score;
+    
+    if ((score == 0)||(score <= 9)) {
+        print_score = sprintf(buffer, "  Score: 000%d ", score);
+    } else if (score <= 99) {
+        print_score = sprintf(buffer, "  Score: 00%2d ", score);
+    } else if (score <= 999 ) {
+        print_score = sprintf(buffer, "  Score: 0%3d ", score);
+    } else {
+        print_score = sprintf(buffer, "  Score: %4d ", score);
+    }   
+    
+    if (print_score <= 14) {
+        lcd.printString(buffer,0,3);
+    }
+    lcd.refresh();
+    wait(8.0);
+}
+
 void instructions_general()
 {
     lcd.clear();