![](/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@3:69296f999fdf, 2017-03-21 (annotated)
- Committer:
- Nathanj94
- Date:
- Tue Mar 21 11:13:20 2017 +0000
- Revision:
- 3:69296f999fdf
- Parent:
- 2:ada503e3486f
- Child:
- 4:039294e6a8a5
Collision mechanics completed, main things left to be completed involve UI, difficulty settings etc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nathanj94 | 2:ada503e3486f | 1 | ///////// pre-processor directives //////// |
Nathanj94 | 2:ada503e3486f | 2 | #include "mbed.h" |
Nathanj94 | 2:ada503e3486f | 3 | #include "Gamepad.h" |
Nathanj94 | 2:ada503e3486f | 4 | #include "N5110.h" |
Nathanj94 | 2:ada503e3486f | 5 | #include "Catch_Model.h" |
Nathanj94 | 2:ada503e3486f | 6 | |
Nathanj94 | 2:ada503e3486f | 7 | #define BASKET_Y 41 |
Nathanj94 | 2:ada503e3486f | 8 | #define BASKET_WIDTH 12 |
Nathanj94 | 3:69296f999fdf | 9 | #define BALL_SPEED 2 |
Nathanj94 | 2:ada503e3486f | 10 | |
Nathanj94 | 2:ada503e3486f | 11 | /////////////// structs ///////////////// |
Nathanj94 | 2:ada503e3486f | 12 | struct UserInput { |
Nathanj94 | 2:ada503e3486f | 13 | Direction d; |
Nathanj94 | 2:ada503e3486f | 14 | float mag; |
Nathanj94 | 2:ada503e3486f | 15 | }; |
Nathanj94 | 2:ada503e3486f | 16 | /////////////// objects /////////////// |
Nathanj94 | 2:ada503e3486f | 17 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
Nathanj94 | 3:69296f999fdf | 18 | Gamepad pad; |
Nathanj94 | 2:ada503e3486f | 19 | Catch_Model catchm; |
Nathanj94 | 2:ada503e3486f | 20 | ///////////// prototypes /////////////// |
Nathanj94 | 2:ada503e3486f | 21 | void init(); |
Nathanj94 | 2:ada503e3486f | 22 | void update_game(UserInput input); |
Nathanj94 | 2:ada503e3486f | 23 | void render(); |
Nathanj94 | 2:ada503e3486f | 24 | ///////////// functions //////////////// |
Nathanj94 | 2:ada503e3486f | 25 | int main() |
Nathanj94 | 2:ada503e3486f | 26 | { |
Nathanj94 | 2:ada503e3486f | 27 | int fps = 8; // frames per second |
Nathanj94 | 2:ada503e3486f | 28 | |
Nathanj94 | 2:ada503e3486f | 29 | init(); |
Nathanj94 | 2:ada503e3486f | 30 | |
Nathanj94 | 2:ada503e3486f | 31 | render(); // draw initial frame |
Nathanj94 | 2:ada503e3486f | 32 | wait(1.0f/fps); |
Nathanj94 | 2:ada503e3486f | 33 | |
Nathanj94 | 2:ada503e3486f | 34 | // game loop - read input, update the game state and render the display |
Nathanj94 | 2:ada503e3486f | 35 | while (1) { |
Nathanj94 | 2:ada503e3486f | 36 | catchm.input(pad); |
Nathanj94 | 3:69296f999fdf | 37 | catchm.update(lcd, pad); |
Nathanj94 | 2:ada503e3486f | 38 | render(); |
Nathanj94 | 2:ada503e3486f | 39 | wait(1.0f/fps); |
Nathanj94 | 2:ada503e3486f | 40 | } |
Nathanj94 | 2:ada503e3486f | 41 | } |
Nathanj94 | 2:ada503e3486f | 42 | |
Nathanj94 | 2:ada503e3486f | 43 | void init() |
Nathanj94 | 2:ada503e3486f | 44 | { |
Nathanj94 | 2:ada503e3486f | 45 | // need to initialise LCD and Gamepad |
Nathanj94 | 2:ada503e3486f | 46 | lcd.init(); |
Nathanj94 | 2:ada503e3486f | 47 | pad.init(); |
Nathanj94 | 2:ada503e3486f | 48 | |
Nathanj94 | 2:ada503e3486f | 49 | // initialise the game |
Nathanj94 | 2:ada503e3486f | 50 | catchm.init(BASKET_Y,BASKET_WIDTH,BALL_SPEED); |
Nathanj94 | 2:ada503e3486f | 51 | |
Nathanj94 | 2:ada503e3486f | 52 | } |
Nathanj94 | 2:ada503e3486f | 53 | |
Nathanj94 | 2:ada503e3486f | 54 | void render() |
Nathanj94 | 2:ada503e3486f | 55 | { |
Nathanj94 | 2:ada503e3486f | 56 | // clear screen, re-draw and refresh |
Nathanj94 | 2:ada503e3486f | 57 | lcd.clear(); |
Nathanj94 | 2:ada503e3486f | 58 | catchm.draw(lcd); |
Nathanj94 | 2:ada503e3486f | 59 | lcd.refresh(); |
Nathanj94 | 2:ada503e3486f | 60 | } |