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:
16:d70fd9ff28b9
Parent:
15:03868ddf5bf3
Child:
17:d0853ac51e38
--- a/Project_Submission.cpp	Thu Apr 27 12:40:30 2017 +0000
+++ b/Project_Submission.cpp	Fri Apr 28 17:15:43 2017 +0000
@@ -9,7 +9,8 @@
 
 //OBJECTS//
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
-Gamepad pad; 
+
+Gamepad pad;
 Catch_Model catchm;
 Objects objects;
 Basket basket;
@@ -21,7 +22,6 @@
 void init();
 void render();
 void welcome();
-void game_over(int score);
 void instructions_general();
 void instructions_buttons();
 void set_brightness();
@@ -30,45 +30,42 @@
 //MAIN//
 int main()
 {
-    int fps = 8; 
-    
+    int fps = 8;
+
     init();
     welcome();
     instructions_general();
     instructions_buttons();
     set_brightness();
-    
+
     while(1) {
-        
+
         set_speed();
         catchm.init(BASKET_Y,BASKET_WIDTH,set_speed(),LIVES);
-        
-        render(); 
-        wait(1.0f/fps);  
+
+        render();
+        wait(1.0f/fps);
 
         do {
             catchm.input(pad);
             catchm.update(lcd, pad);
-            
+
             catchm.check_a(lcd,pad);
             catchm.check_b(lcd,pad);
 
             lives = catchm.get_lives();
-            if (lives == 0) {
-                game_over(basket.get_score());
-            }
             
             render();
             wait(1.0f/fps);
-            
-           } while (lives > 0);
+
+        } while (lives > 0);
     }
 }
 
 //FUNCTIONS//
 void init()
 {
-    // initialise LCD and Gamepad 
+    // initialise LCD and Gamepad
     lcd.init();
     pad.init();
 }
@@ -76,17 +73,17 @@
 void render()
 {
     // re-draw screen each loop
-    lcd.clear();  
-    catchm.draw(lcd);
+    lcd.clear();
+    catchm.draw(lcd,pad);
     lcd.refresh();
 }
 
-void welcome() 
+void welcome()
 {
-    lcd.printString("FRUIT BASKET",0,2); 
+    lcd.printString("FRUIT BASKET",0,2);
     lcd.printString("press start",0,3);
     lcd.refresh();
-     
+
     while (pad.check_event(Gamepad::START_PRESSED) == false) {
         pad.leds_on();
         wait(0.1);
@@ -95,32 +92,6 @@
     }
 }
 
-void game_over(int score)
-{
-    lcd.clear();
-    lcd.printString("   GAME OVER  ",0,2);
-    
-    char buffer[14];
-    int _score = 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();
@@ -131,7 +102,7 @@
     lcd.printString("catch the",0,4);
     lcd.printString("fruit.",0,5);
     lcd.refresh();
-    
+
     while (pad.check_event(Gamepad::START_PRESSED) == false) {
         pad.leds_on();
         wait(0.1);
@@ -152,7 +123,7 @@
     lcd.drawLine(69,43,73,47,1);
     lcd.drawLine(73,47,77,39,1);
     lcd.refresh();
-    
+
     while (pad.check_event(Gamepad::START_PRESSED) == false) {
         pad.leds_on();
         wait(0.1);
@@ -166,35 +137,35 @@
     lcd.clear();
     lcd.printString("Set Brightness",0,2);
     lcd.refresh();
-    
+
     while (pad.check_event(Gamepad::START_PRESSED) == false) {
         lcd.setBrightness(pad.read_pot()*10);
         pad.leds(pad.read_pot());
-    }       
+    }
 }
 
 int set_speed()
-{   
+{
     while (pad.check_event(Gamepad::START_PRESSED) == false) {
         lcd.clear();
         lcd.printString("Set Speed",0,2);
-        
+
         if (pad.read_pot() > 0.9f) {
             objects_speed = 5;
             lcd.printString("High",0,3);
-        }else if (pad.read_pot() > 0.6f) {
+        } else if (pad.read_pot() > 0.6f) {
             objects_speed = 4;
             lcd.printString("Normal",0,3);
-        }else if (pad.read_pot() > 0.3f) {
+        } else if (pad.read_pot() > 0.3f) {
             objects_speed = 3;
             lcd.printString("Slow",0,3);
         } else {
             objects_speed = 2;
             lcd.printString("Very Slow",0,3);
-        }  
-          
+        }
+
         lcd.refresh();
     }
-    
+
     return objects_speed;
 }
\ No newline at end of file