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

Committer:
Nathanj94
Date:
Wed Apr 12 14:48:14 2017 +0000
Revision:
8:1a785bfa4d08
Parent:
7:32afc46c30f3
Child:
9:3e7fca03c7c1
Progress made with functions on button presses. Trying to use a timeout to delay the next use of the buttons but returning compiler error

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nathanj94 2:ada503e3486f 1 #include "mbed.h"
Nathanj94 2:ada503e3486f 2 #include "Gamepad.h"
Nathanj94 2:ada503e3486f 3 #include "N5110.h"
Nathanj94 2:ada503e3486f 4 #include "Catch_Model.h"
Nathanj94 2:ada503e3486f 5
Nathanj94 2:ada503e3486f 6 #define BASKET_Y 41
Nathanj94 2:ada503e3486f 7 #define BASKET_WIDTH 12
Nathanj94 7:32afc46c30f3 8 #define BALL_SPEED 3
Nathanj94 7:32afc46c30f3 9 #define LIVES 5
Nathanj94 2:ada503e3486f 10
Nathanj94 4:039294e6a8a5 11 //OBJECTS//
Nathanj94 2:ada503e3486f 12 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Nathanj94 3:69296f999fdf 13 Gamepad pad;
Nathanj94 2:ada503e3486f 14 Catch_Model catchm;
Nathanj94 4:039294e6a8a5 15
Nathanj94 4:039294e6a8a5 16 //FUNCTION PROTOTYPES//
Nathanj94 2:ada503e3486f 17 void init();
Nathanj94 2:ada503e3486f 18 void render();
Nathanj94 4:039294e6a8a5 19 void welcome();
Nathanj94 4:039294e6a8a5 20
Nathanj94 4:039294e6a8a5 21 //MAIN//
Nathanj94 2:ada503e3486f 22 int main()
Nathanj94 2:ada503e3486f 23 {
Nathanj94 4:039294e6a8a5 24 int fps = 8;
Nathanj94 4:039294e6a8a5 25
Nathanj94 4:039294e6a8a5 26 while(1) {
Nathanj94 2:ada503e3486f 27
Nathanj94 4:039294e6a8a5 28 init();
Nathanj94 4:039294e6a8a5 29 welcome();
Nathanj94 4:039294e6a8a5 30 render();
Nathanj94 4:039294e6a8a5 31 wait(1.0f/fps);
Nathanj94 4:039294e6a8a5 32 int lives;
Nathanj94 4:039294e6a8a5 33
Nathanj94 4:039294e6a8a5 34 do {
Nathanj94 4:039294e6a8a5 35 catchm.input(pad);
Nathanj94 4:039294e6a8a5 36 catchm.update(lcd, pad);
Nathanj94 8:1a785bfa4d08 37 catchm.check_abxy(lcd, pad);
Nathanj94 4:039294e6a8a5 38 lives = catchm.get_lives();
Nathanj94 4:039294e6a8a5 39 render();
Nathanj94 4:039294e6a8a5 40 wait(1.0f/fps);
Nathanj94 4:039294e6a8a5 41 } while(lives > 0);
Nathanj94 2:ada503e3486f 42 }
Nathanj94 2:ada503e3486f 43 }
Nathanj94 2:ada503e3486f 44
Nathanj94 4:039294e6a8a5 45 //FUNCTIONS//
Nathanj94 2:ada503e3486f 46 void init()
Nathanj94 2:ada503e3486f 47 {
Nathanj94 4:039294e6a8a5 48 // initialise LCD and Gamepad
Nathanj94 2:ada503e3486f 49 lcd.init();
Nathanj94 2:ada503e3486f 50 pad.init();
Nathanj94 2:ada503e3486f 51
Nathanj94 4:039294e6a8a5 52 // initialise game model
Nathanj94 4:039294e6a8a5 53 catchm.init(BASKET_Y,BASKET_WIDTH,BALL_SPEED,LIVES);
Nathanj94 2:ada503e3486f 54
Nathanj94 2:ada503e3486f 55 }
Nathanj94 2:ada503e3486f 56
Nathanj94 2:ada503e3486f 57 void render()
Nathanj94 2:ada503e3486f 58 {
Nathanj94 4:039294e6a8a5 59 // re-draw screen each loop
Nathanj94 2:ada503e3486f 60 lcd.clear();
Nathanj94 2:ada503e3486f 61 catchm.draw(lcd);
Nathanj94 2:ada503e3486f 62 lcd.refresh();
Nathanj94 2:ada503e3486f 63 }
Nathanj94 4:039294e6a8a5 64
Nathanj94 4:039294e6a8a5 65 void welcome() {
Nathanj94 4:039294e6a8a5 66
Nathanj94 4:039294e6a8a5 67 lcd.printString(" Press Start ",0,2);
Nathanj94 4:039294e6a8a5 68 lcd.refresh();
Nathanj94 4:039294e6a8a5 69
Nathanj94 5:136b13a9b8b5 70 while (pad.check_event(Gamepad::START_PRESSED) == false) {
Nathanj94 4:039294e6a8a5 71 pad.leds_on();
Nathanj94 4:039294e6a8a5 72 wait(0.1);
Nathanj94 4:039294e6a8a5 73 pad.leds_off();
Nathanj94 4:039294e6a8a5 74 wait(0.1);
Nathanj94 4:039294e6a8a5 75 }
Nathanj94 4:039294e6a8a5 76 }