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
Diff: Project_Submission.cpp
- Revision:
- 13:09a9ffd8eb60
- Parent:
- 12:d87c9ae89472
- Child:
- 14:e20bf6569607
diff -r d87c9ae89472 -r 09a9ffd8eb60 Project_Submission.cpp --- a/Project_Submission.cpp Wed Apr 19 14:35:27 2017 +0000 +++ b/Project_Submission.cpp Thu Apr 20 14:27:40 2017 +0000 @@ -5,7 +5,6 @@ #define BASKET_Y 41 #define BASKET_WIDTH 12 -#define OBJECT_SPEED 1 #define LIVES 5 //OBJECTS// @@ -14,13 +13,17 @@ Catch_Model catchm; Objects objects; -float speed; +int objects_speed; +int lives; //FUNCTION PROTOTYPES// void init(); void render(); void welcome(); -float speed_select(); +void instructions_general(); +void instructions_buttons(); +void set_brightness(); +int set_speed(); //MAIN// int main() @@ -30,18 +33,23 @@ while(1) { init(); + welcome(); - //speed_select(); + instructions_general(); + instructions_buttons(); + + set_brightness(); + set_speed(); + catchm.init(BASKET_Y,BASKET_WIDTH,set_speed(),LIVES); + render(); wait(1.0f/fps); - int lives; + //int lives; do { catchm.input(pad); catchm.update(lcd, pad); - //objects.move(speed_select()); - catchm.check_a(lcd,pad); catchm.check_b(lcd,pad); catchm.check_x(lcd,pad); @@ -60,10 +68,6 @@ // initialise LCD and Gamepad lcd.init(); pad.init(); - - // initialise game model - catchm.init(BASKET_Y,BASKET_WIDTH,OBJECT_SPEED,LIVES); - } void render() @@ -88,27 +92,80 @@ } } -float speed_select() +void instructions_general() { lcd.clear(); + lcd.printString("Move the",0,0); + lcd.printString("basket with",0,1); + lcd.printString("L/R or the",0,2); + lcd.printString("joystick to",0,3); + 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); + pad.leds_off(); + wait(0.1); + } +} + +void instructions_buttons() +{ + lcd.clear(); + lcd.printString("Press A for a",0,0); + lcd.printString("second chance.",0,1); + lcd.printString("Press B for an",0,2); + lcd.printString("extra life.",0,3); + lcd.printString("Available when",0,4); + lcd.printString("you see the",0,5); + lcd.drawLine(69,43,73,47,1); + lcd.drawLine(73,47,77,39,1); lcd.refresh(); while (pad.check_event(Gamepad::START_PRESSED) == false) { - - speed = objects.speed_select(pad); - - char buffer[14]; - int print_speed = sprintf(buffer, "%10.2f", speed); + pad.leds_on(); + wait(0.1); + pad.leds_off(); + wait(0.1); + } +} + +void set_brightness() +{ + lcd.clear(); + lcd.printString("Set Brightness",0,2); + lcd.refresh(); + + while (pad.check_event(Gamepad::START_PRESSED) == false) { + lcd.setBrightness(pad.read_pot()); + 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 (speed > 1) { - lcd.printString("INSANE",0,0); - } else if (speed != 0) { - lcd.printString(buffer,0,0); - } + if (pad.read_pot() > 0.9f) { + objects_speed = 5; + lcd.printString("High",0,3); + }else if (pad.read_pot() > 0.6f) { + objects_speed = 4; + lcd.printString("Normal",0,3); + }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(); } - speed = objects.speed_select(pad); - objects.init(speed); - return speed; + return objects_speed; } \ No newline at end of file