![](/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@7:32afc46c30f3, 2017-04-04 (annotated)
- Committer:
- Nathanj94
- Date:
- Tue Apr 04 16:34:36 2017 +0000
- Revision:
- 7:32afc46c30f3
- Parent:
- 5:136b13a9b8b5
- Child:
- 8:1a785bfa4d08
Antifruit added and library for abxy functions started
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:039294e6a8a5 | 37 | lives = catchm.get_lives(); |
Nathanj94 | 4:039294e6a8a5 | 38 | render(); |
Nathanj94 | 4:039294e6a8a5 | 39 | wait(1.0f/fps); |
Nathanj94 | 4:039294e6a8a5 | 40 | } while(lives > 0); |
Nathanj94 | 2:ada503e3486f | 41 | } |
Nathanj94 | 2:ada503e3486f | 42 | } |
Nathanj94 | 2:ada503e3486f | 43 | |
Nathanj94 | 4:039294e6a8a5 | 44 | //FUNCTIONS// |
Nathanj94 | 2:ada503e3486f | 45 | void init() |
Nathanj94 | 2:ada503e3486f | 46 | { |
Nathanj94 | 4:039294e6a8a5 | 47 | // initialise LCD and Gamepad |
Nathanj94 | 2:ada503e3486f | 48 | lcd.init(); |
Nathanj94 | 2:ada503e3486f | 49 | pad.init(); |
Nathanj94 | 2:ada503e3486f | 50 | |
Nathanj94 | 4:039294e6a8a5 | 51 | // initialise game model |
Nathanj94 | 4:039294e6a8a5 | 52 | catchm.init(BASKET_Y,BASKET_WIDTH,BALL_SPEED,LIVES); |
Nathanj94 | 2:ada503e3486f | 53 | |
Nathanj94 | 2:ada503e3486f | 54 | } |
Nathanj94 | 2:ada503e3486f | 55 | |
Nathanj94 | 2:ada503e3486f | 56 | void render() |
Nathanj94 | 2:ada503e3486f | 57 | { |
Nathanj94 | 4:039294e6a8a5 | 58 | // re-draw screen each loop |
Nathanj94 | 2:ada503e3486f | 59 | lcd.clear(); |
Nathanj94 | 2:ada503e3486f | 60 | catchm.draw(lcd); |
Nathanj94 | 2:ada503e3486f | 61 | lcd.refresh(); |
Nathanj94 | 2:ada503e3486f | 62 | } |
Nathanj94 | 4:039294e6a8a5 | 63 | |
Nathanj94 | 4:039294e6a8a5 | 64 | void welcome() { |
Nathanj94 | 4:039294e6a8a5 | 65 | |
Nathanj94 | 4:039294e6a8a5 | 66 | lcd.printString(" Press Start ",0,2); |
Nathanj94 | 4:039294e6a8a5 | 67 | lcd.refresh(); |
Nathanj94 | 4:039294e6a8a5 | 68 | |
Nathanj94 | 5:136b13a9b8b5 | 69 | while (pad.check_event(Gamepad::START_PRESSED) == false) { |
Nathanj94 | 4:039294e6a8a5 | 70 | pad.leds_on(); |
Nathanj94 | 4:039294e6a8a5 | 71 | wait(0.1); |
Nathanj94 | 4:039294e6a8a5 | 72 | pad.leds_off(); |
Nathanj94 | 4:039294e6a8a5 | 73 | wait(0.1); |
Nathanj94 | 4:039294e6a8a5 | 74 | } |
Nathanj94 | 4:039294e6a8a5 | 75 | } |