![](/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:
- 4:039294e6a8a5
- Parent:
- 3:69296f999fdf
- Child:
- 5:136b13a9b8b5
--- a/Project_Submission.cpp Tue Mar 21 11:13:20 2017 +0000 +++ b/Project_Submission.cpp Thu Mar 23 15:28:52 2017 +0000 @@ -1,4 +1,3 @@ -///////// pre-processor directives //////// #include "mbed.h" #include "Gamepad.h" #include "N5110.h" @@ -7,54 +6,70 @@ #define BASKET_Y 41 #define BASKET_WIDTH 12 #define BALL_SPEED 2 +#define LIVES 3 -/////////////// structs ///////////////// -struct UserInput { - Direction d; - float mag; -}; -/////////////// objects /////////////// +//OBJECTS// N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad pad; Catch_Model catchm; -///////////// prototypes /////////////// + +//FUNCTION PROTOTYPES// void init(); -void update_game(UserInput input); void render(); -///////////// functions //////////////// +void welcome(); + +//MAIN// int main() { - int fps = 8; // frames per second - - init(); - - render(); // draw initial frame - wait(1.0f/fps); + int fps = 8; + + while(1) { - // game loop - read input, update the game state and render the display - while (1) { - catchm.input(pad); - catchm.update(lcd, pad); - render(); - wait(1.0f/fps); + init(); + welcome(); + render(); + wait(1.0f/fps); + int lives; + + do { + catchm.input(pad); + catchm.update(lcd, pad); + lives = catchm.get_lives(); + render(); + wait(1.0f/fps); + } while(lives > 0); } } +//FUNCTIONS// void init() { - // need to initialise LCD and Gamepad + // initialise LCD and Gamepad lcd.init(); pad.init(); - // initialise the game - catchm.init(BASKET_Y,BASKET_WIDTH,BALL_SPEED); + // initialise game model + catchm.init(BASKET_Y,BASKET_WIDTH,BALL_SPEED,LIVES); } void render() { - // clear screen, re-draw and refresh + // re-draw screen each loop lcd.clear(); catchm.draw(lcd); lcd.refresh(); } + +void welcome() { + + lcd.printString(" Press Start ",0,2); + lcd.refresh(); + + while ( pad.check_event(Gamepad::START_PRESSED) == false) { + pad.leds_on(); + wait(0.1); + pad.leds_off(); + wait(0.1); + } +} \ No newline at end of file