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 19 14:35:27 2017 +0000
Revision:
12:d87c9ae89472
Parent:
11:a6a88a51dd57
Child:
13:09a9ffd8eb60
Continued trying to allow speed to be selected before game but still doesn't work. UI improvements/notes will be finished before returning to the problem

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 12:d87c9ae89472 8 #define OBJECT_SPEED 1
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 11:a6a88a51dd57 15 Objects objects;
Nathanj94 4:039294e6a8a5 16
Nathanj94 12:d87c9ae89472 17 float speed;
Nathanj94 12:d87c9ae89472 18
Nathanj94 4:039294e6a8a5 19 //FUNCTION PROTOTYPES//
Nathanj94 2:ada503e3486f 20 void init();
Nathanj94 2:ada503e3486f 21 void render();
Nathanj94 4:039294e6a8a5 22 void welcome();
Nathanj94 12:d87c9ae89472 23 float speed_select();
Nathanj94 4:039294e6a8a5 24
Nathanj94 4:039294e6a8a5 25 //MAIN//
Nathanj94 2:ada503e3486f 26 int main()
Nathanj94 2:ada503e3486f 27 {
Nathanj94 4:039294e6a8a5 28 int fps = 8;
Nathanj94 4:039294e6a8a5 29
Nathanj94 4:039294e6a8a5 30 while(1) {
Nathanj94 2:ada503e3486f 31
Nathanj94 4:039294e6a8a5 32 init();
Nathanj94 4:039294e6a8a5 33 welcome();
Nathanj94 11:a6a88a51dd57 34 //speed_select();
Nathanj94 4:039294e6a8a5 35 render();
Nathanj94 4:039294e6a8a5 36 wait(1.0f/fps);
Nathanj94 4:039294e6a8a5 37 int lives;
Nathanj94 4:039294e6a8a5 38
Nathanj94 4:039294e6a8a5 39 do {
Nathanj94 4:039294e6a8a5 40 catchm.input(pad);
Nathanj94 4:039294e6a8a5 41 catchm.update(lcd, pad);
Nathanj94 9:3e7fca03c7c1 42
Nathanj94 12:d87c9ae89472 43 //objects.move(speed_select());
Nathanj94 12:d87c9ae89472 44
Nathanj94 9:3e7fca03c7c1 45 catchm.check_a(lcd,pad);
Nathanj94 9:3e7fca03c7c1 46 catchm.check_b(lcd,pad);
Nathanj94 10:92a658c3c5a4 47 catchm.check_x(lcd,pad);
Nathanj94 9:3e7fca03c7c1 48
Nathanj94 4:039294e6a8a5 49 lives = catchm.get_lives();
Nathanj94 4:039294e6a8a5 50 render();
Nathanj94 4:039294e6a8a5 51 wait(1.0f/fps);
Nathanj94 11:a6a88a51dd57 52
Nathanj94 12:d87c9ae89472 53 } while (lives > 0);
Nathanj94 2:ada503e3486f 54 }
Nathanj94 2:ada503e3486f 55 }
Nathanj94 2:ada503e3486f 56
Nathanj94 4:039294e6a8a5 57 //FUNCTIONS//
Nathanj94 2:ada503e3486f 58 void init()
Nathanj94 2:ada503e3486f 59 {
Nathanj94 4:039294e6a8a5 60 // initialise LCD and Gamepad
Nathanj94 2:ada503e3486f 61 lcd.init();
Nathanj94 2:ada503e3486f 62 pad.init();
Nathanj94 2:ada503e3486f 63
Nathanj94 4:039294e6a8a5 64 // initialise game model
Nathanj94 12:d87c9ae89472 65 catchm.init(BASKET_Y,BASKET_WIDTH,OBJECT_SPEED,LIVES);
Nathanj94 2:ada503e3486f 66
Nathanj94 2:ada503e3486f 67 }
Nathanj94 2:ada503e3486f 68
Nathanj94 2:ada503e3486f 69 void render()
Nathanj94 2:ada503e3486f 70 {
Nathanj94 4:039294e6a8a5 71 // re-draw screen each loop
Nathanj94 2:ada503e3486f 72 lcd.clear();
Nathanj94 2:ada503e3486f 73 catchm.draw(lcd);
Nathanj94 2:ada503e3486f 74 lcd.refresh();
Nathanj94 2:ada503e3486f 75 }
Nathanj94 4:039294e6a8a5 76
Nathanj94 11:a6a88a51dd57 77 void welcome()
Nathanj94 11:a6a88a51dd57 78 {
Nathanj94 12:d87c9ae89472 79 lcd.printString("FRUIT BASKET",0,2);
Nathanj94 12:d87c9ae89472 80 lcd.printString("press start",0,3);
Nathanj94 4:039294e6a8a5 81 lcd.refresh();
Nathanj94 4:039294e6a8a5 82
Nathanj94 5:136b13a9b8b5 83 while (pad.check_event(Gamepad::START_PRESSED) == false) {
Nathanj94 4:039294e6a8a5 84 pad.leds_on();
Nathanj94 4:039294e6a8a5 85 wait(0.1);
Nathanj94 4:039294e6a8a5 86 pad.leds_off();
Nathanj94 4:039294e6a8a5 87 wait(0.1);
Nathanj94 4:039294e6a8a5 88 }
Nathanj94 11:a6a88a51dd57 89 }
Nathanj94 11:a6a88a51dd57 90
Nathanj94 12:d87c9ae89472 91 float speed_select()
Nathanj94 11:a6a88a51dd57 92 {
Nathanj94 11:a6a88a51dd57 93 lcd.clear();
Nathanj94 11:a6a88a51dd57 94 lcd.refresh();
Nathanj94 11:a6a88a51dd57 95
Nathanj94 11:a6a88a51dd57 96 while (pad.check_event(Gamepad::START_PRESSED) == false) {
Nathanj94 11:a6a88a51dd57 97
Nathanj94 12:d87c9ae89472 98 speed = objects.speed_select(pad);
Nathanj94 11:a6a88a51dd57 99
Nathanj94 11:a6a88a51dd57 100 char buffer[14];
Nathanj94 11:a6a88a51dd57 101 int print_speed = sprintf(buffer, "%10.2f", speed);
Nathanj94 11:a6a88a51dd57 102
Nathanj94 11:a6a88a51dd57 103 if (speed > 1) {
Nathanj94 11:a6a88a51dd57 104 lcd.printString("INSANE",0,0);
Nathanj94 11:a6a88a51dd57 105 } else if (speed != 0) {
Nathanj94 11:a6a88a51dd57 106 lcd.printString(buffer,0,0);
Nathanj94 11:a6a88a51dd57 107 }
Nathanj94 11:a6a88a51dd57 108 lcd.refresh();
Nathanj94 11:a6a88a51dd57 109 }
Nathanj94 12:d87c9ae89472 110
Nathanj94 12:d87c9ae89472 111 speed = objects.speed_select(pad);
Nathanj94 12:d87c9ae89472 112 objects.init(speed);
Nathanj94 12:d87c9ae89472 113 return speed;
Nathanj94 4:039294e6a8a5 114 }