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:
Fri Apr 14 15:38:31 2017 +0000
Revision:
9:3e7fca03c7c1
Parent:
8:1a785bfa4d08
Child:
10:92a658c3c5a4
Timeout configured correctly to allow actions to be used every 10s, new function to add a life added, indicator for availability added and started experimenting with tones etc to improve UI and general quality.

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 9:3e7fca03c7c1 37
Nathanj94 9:3e7fca03c7c1 38 catchm.check_a(lcd,pad);
Nathanj94 9:3e7fca03c7c1 39 catchm.check_b(lcd,pad);
Nathanj94 9:3e7fca03c7c1 40
Nathanj94 4:039294e6a8a5 41 lives = catchm.get_lives();
Nathanj94 4:039294e6a8a5 42 render();
Nathanj94 4:039294e6a8a5 43 wait(1.0f/fps);
Nathanj94 4:039294e6a8a5 44 } while(lives > 0);
Nathanj94 2:ada503e3486f 45 }
Nathanj94 2:ada503e3486f 46 }
Nathanj94 2:ada503e3486f 47
Nathanj94 4:039294e6a8a5 48 //FUNCTIONS//
Nathanj94 2:ada503e3486f 49 void init()
Nathanj94 2:ada503e3486f 50 {
Nathanj94 4:039294e6a8a5 51 // initialise LCD and Gamepad
Nathanj94 2:ada503e3486f 52 lcd.init();
Nathanj94 2:ada503e3486f 53 pad.init();
Nathanj94 2:ada503e3486f 54
Nathanj94 4:039294e6a8a5 55 // initialise game model
Nathanj94 4:039294e6a8a5 56 catchm.init(BASKET_Y,BASKET_WIDTH,BALL_SPEED,LIVES);
Nathanj94 2:ada503e3486f 57
Nathanj94 2:ada503e3486f 58 }
Nathanj94 2:ada503e3486f 59
Nathanj94 2:ada503e3486f 60 void render()
Nathanj94 2:ada503e3486f 61 {
Nathanj94 4:039294e6a8a5 62 // re-draw screen each loop
Nathanj94 2:ada503e3486f 63 lcd.clear();
Nathanj94 2:ada503e3486f 64 catchm.draw(lcd);
Nathanj94 2:ada503e3486f 65 lcd.refresh();
Nathanj94 2:ada503e3486f 66 }
Nathanj94 4:039294e6a8a5 67
Nathanj94 4:039294e6a8a5 68 void welcome() {
Nathanj94 4:039294e6a8a5 69
Nathanj94 4:039294e6a8a5 70 lcd.printString(" Press Start ",0,2);
Nathanj94 4:039294e6a8a5 71 lcd.refresh();
Nathanj94 4:039294e6a8a5 72
Nathanj94 5:136b13a9b8b5 73 while (pad.check_event(Gamepad::START_PRESSED) == false) {
Nathanj94 4:039294e6a8a5 74 pad.leds_on();
Nathanj94 4:039294e6a8a5 75 wait(0.1);
Nathanj94 4:039294e6a8a5 76 pad.leds_off();
Nathanj94 4:039294e6a8a5 77 wait(0.1);
Nathanj94 4:039294e6a8a5 78 }
Nathanj94 9:3e7fca03c7c1 79 pad.tone(500, 0.5);
Nathanj94 4:039294e6a8a5 80 }