![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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:
- 17:d0853ac51e38
- Parent:
- 16:d70fd9ff28b9
diff -r d70fd9ff28b9 -r d0853ac51e38 Project_Submission.cpp --- a/Project_Submission.cpp Fri Apr 28 17:15:43 2017 +0000 +++ b/Project_Submission.cpp Thu May 04 10:30:48 2017 +0000 @@ -40,8 +40,9 @@ while(1) { - set_speed(); + set_speed();//don't init game until speed is set manually catchm.init(BASKET_Y,BASKET_WIDTH,set_speed(),LIVES); + //printf("game initialised\n"); render(); wait(1.0f/fps); @@ -50,13 +51,13 @@ catchm.input(pad); catchm.update(lcd, pad); - catchm.check_a(lcd,pad); - catchm.check_b(lcd,pad); + catchm.check_a(lcd,pad); //game runs better if these functions are + catchm.check_b(lcd,pad); //seperate from Catch_Model::update() lives = catchm.get_lives(); render(); - wait(1.0f/fps); + wait(1.0f/fps); // frame rate } while (lives > 0); } @@ -95,7 +96,7 @@ void instructions_general() { lcd.clear(); - lcd.printString("Move the",0,0); + lcd.printString("Move the",0,0); // instructions for moving basket lcd.printString("basket with",0,1); lcd.printString("L/R or the",0,2); lcd.printString("joystick to",0,3); @@ -114,14 +115,14 @@ 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("Press A for a",0,0); // A button cancels an object mid-drop + lcd.printString("second chance.",0,1); // and immediately drops another randomly + lcd.printString("Press B for an",0,2); // B button adds an extra life 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.drawLine(69,43,73,47,1); //draw + lcd.drawLine(73,47,77,39,1); //tick lcd.refresh(); while (pad.check_event(Gamepad::START_PRESSED) == false) { @@ -139,7 +140,7 @@ lcd.refresh(); while (pad.check_event(Gamepad::START_PRESSED) == false) { - lcd.setBrightness(pad.read_pot()*10); + lcd.setBrightness(pad.read_pot()); pad.leds(pad.read_pot()); } } @@ -150,13 +151,13 @@ 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) { + if (pad.read_pot() > 0.75f) { // value of pot selects speed objects will fall at + objects_speed = 5; // int value translates to pixels per game loop + lcd.printString("Fast",0,3); + } else if (pad.read_pot() > 0.5f) { objects_speed = 4; lcd.printString("Normal",0,3); - } else if (pad.read_pot() > 0.3f) { + } else if (pad.read_pot() > 0.25f) { objects_speed = 3; lcd.printString("Slow",0,3); } else { @@ -167,5 +168,5 @@ lcd.refresh(); } - return objects_speed; + return objects_speed; // game initialised with this value } \ No newline at end of file