![](/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
Project_Submission.cpp
- Committer:
- Nathanj94
- Date:
- 2017-04-19
- Revision:
- 12:d87c9ae89472
- Parent:
- 11:a6a88a51dd57
- Child:
- 13:09a9ffd8eb60
File content as of revision 12:d87c9ae89472:
#include "mbed.h" #include "Gamepad.h" #include "N5110.h" #include "Catch_Model.h" #define BASKET_Y 41 #define BASKET_WIDTH 12 #define OBJECT_SPEED 1 #define LIVES 5 //OBJECTS// N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad pad; Catch_Model catchm; Objects objects; float speed; //FUNCTION PROTOTYPES// void init(); void render(); void welcome(); float speed_select(); //MAIN// int main() { int fps = 8; while(1) { init(); welcome(); //speed_select(); render(); wait(1.0f/fps); 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); lives = catchm.get_lives(); render(); wait(1.0f/fps); } while (lives > 0); } } //FUNCTIONS// void init() { // initialise LCD and Gamepad lcd.init(); pad.init(); // initialise game model catchm.init(BASKET_Y,BASKET_WIDTH,OBJECT_SPEED,LIVES); } void render() { // re-draw screen each loop lcd.clear(); catchm.draw(lcd); lcd.refresh(); } void welcome() { 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); pad.leds_off(); wait(0.1); } } float speed_select() { lcd.clear(); 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); if (speed > 1) { lcd.printString("INSANE",0,0); } else if (speed != 0) { lcd.printString(buffer,0,0); } lcd.refresh(); } speed = objects.speed_select(pad); objects.init(speed); return speed; }