![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
main.cpp@6:3ffab44ed49c, 2019-03-23 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Sat Mar 23 15:07:15 2019 +0000
- Revision:
- 6:3ffab44ed49c
- Parent:
- 3:fbb1fa853f09
- Child:
- 7:48ba87cd79b5
Added some tones and animation in Launch
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AhmedPlaymaker | 0:4b15c2d4aa58 | 1 | /* |
AhmedPlaymaker | 0:4b15c2d4aa58 | 2 | ELEC2645 Embedded Systems Project |
AhmedPlaymaker | 0:4b15c2d4aa58 | 3 | School of Electronic & Electrical Engineering |
AhmedPlaymaker | 0:4b15c2d4aa58 | 4 | University of Leeds |
AhmedPlaymaker | 0:4b15c2d4aa58 | 5 | Name: Ahmed Nomaan Adamjee |
AhmedPlaymaker | 0:4b15c2d4aa58 | 6 | Username: AhmedPlaymaker |
AhmedPlaymaker | 0:4b15c2d4aa58 | 7 | Student ID Number: 201161436 |
AhmedPlaymaker | 0:4b15c2d4aa58 | 8 | Date: |
AhmedPlaymaker | 0:4b15c2d4aa58 | 9 | */ |
AhmedPlaymaker | 0:4b15c2d4aa58 | 10 | |
AhmedPlaymaker | 1:32e312688a65 | 11 | ///////// pre-processor directives //////// |
AhmedPlaymaker | 0:4b15c2d4aa58 | 12 | #include "mbed.h" |
AhmedPlaymaker | 1:32e312688a65 | 13 | #include "Gamepad.h" |
AhmedPlaymaker | 1:32e312688a65 | 14 | #include "N5110.h" |
AhmedPlaymaker | 1:32e312688a65 | 15 | #include "FXOS8700CQ.h" |
AhmedPlaymaker | 3:fbb1fa853f09 | 16 | #include "StartScreen.h" |
AhmedPlaymaker | 6:3ffab44ed49c | 17 | //#include "SnakevsBlock.h" |
AhmedPlaymaker | 6:3ffab44ed49c | 18 | |
AhmedPlaymaker | 6:3ffab44ed49c | 19 | /////////////// structs ///////////////// |
AhmedPlaymaker | 6:3ffab44ed49c | 20 | struct UserInput { |
AhmedPlaymaker | 6:3ffab44ed49c | 21 | Direction d; |
AhmedPlaymaker | 6:3ffab44ed49c | 22 | float mag; |
AhmedPlaymaker | 6:3ffab44ed49c | 23 | }; |
AhmedPlaymaker | 1:32e312688a65 | 24 | |
AhmedPlaymaker | 1:32e312688a65 | 25 | /////////////// objects /////////////// |
AhmedPlaymaker | 1:32e312688a65 | 26 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
AhmedPlaymaker | 1:32e312688a65 | 27 | Gamepad pad; |
AhmedPlaymaker | 1:32e312688a65 | 28 | FXOS8700CQ device(I2C_SDA,I2C_SCL); |
AhmedPlaymaker | 3:fbb1fa853f09 | 29 | StartScreen _start; |
AhmedPlaymaker | 2:83e85dea3c89 | 30 | //SnakevsBlock game; |
AhmedPlaymaker | 1:32e312688a65 | 31 | |
AhmedPlaymaker | 1:32e312688a65 | 32 | ///////////// prototypes /////////////// |
AhmedPlaymaker | 1:32e312688a65 | 33 | void init(); |
AhmedPlaymaker | 1:32e312688a65 | 34 | void refresh_game(); |
AhmedPlaymaker | 6:3ffab44ed49c | 35 | //void update_game(UserInput input); |
AhmedPlaymaker | 1:32e312688a65 | 36 | |
AhmedPlaymaker | 2:83e85dea3c89 | 37 | //Constants// |
AhmedPlaymaker | 2:83e85dea3c89 | 38 | int fps = 7; // frames per second |
AhmedPlaymaker | 2:83e85dea3c89 | 39 | |
AhmedPlaymaker | 1:32e312688a65 | 40 | ///////////// MAIN //////////////// |
AhmedPlaymaker | 1:32e312688a65 | 41 | int main() |
AhmedPlaymaker | 1:32e312688a65 | 42 | { |
AhmedPlaymaker | 2:83e85dea3c89 | 43 | |
AhmedPlaymaker | 1:32e312688a65 | 44 | init(); |
AhmedPlaymaker | 3:fbb1fa853f09 | 45 | _start.screen_saver(lcd, pad); |
AhmedPlaymaker | 3:fbb1fa853f09 | 46 | _start.instruct(lcd, pad); |
AhmedPlaymaker | 3:fbb1fa853f09 | 47 | _start.info(lcd, pad); |
AhmedPlaymaker | 3:fbb1fa853f09 | 48 | _start.menu_screen1(lcd, pad); |
AhmedPlaymaker | 1:32e312688a65 | 49 | // start the game |
AhmedPlaymaker | 1:32e312688a65 | 50 | refresh_game(); |
AhmedPlaymaker | 1:32e312688a65 | 51 | wait(1.0f/fps); |
AhmedPlaymaker | 1:32e312688a65 | 52 | |
AhmedPlaymaker | 1:32e312688a65 | 53 | // snakeVSblock - detect input respect to the menu options, and update data and refresh screen |
AhmedPlaymaker | 1:32e312688a65 | 54 | while (1) { |
AhmedPlaymaker | 1:32e312688a65 | 55 | |
AhmedPlaymaker | 2:83e85dea3c89 | 56 | //game.read_input(pad); |
AhmedPlaymaker | 2:83e85dea3c89 | 57 | //game.update(pad); |
AhmedPlaymaker | 1:32e312688a65 | 58 | refresh_game(); |
AhmedPlaymaker | 1:32e312688a65 | 59 | |
AhmedPlaymaker | 1:32e312688a65 | 60 | wait(1.0f/fps); |
AhmedPlaymaker | 1:32e312688a65 | 61 | |
AhmedPlaymaker | 1:32e312688a65 | 62 | } |
AhmedPlaymaker | 1:32e312688a65 | 63 | } |
AhmedPlaymaker | 1:32e312688a65 | 64 | |
AhmedPlaymaker | 1:32e312688a65 | 65 | void init() |
AhmedPlaymaker | 1:32e312688a65 | 66 | { |
AhmedPlaymaker | 1:32e312688a65 | 67 | // need to initialise LCD and Gamepad |
AhmedPlaymaker | 1:32e312688a65 | 68 | lcd.init(); |
AhmedPlaymaker | 1:32e312688a65 | 69 | pad.init(); |
AhmedPlaymaker | 6:3ffab44ed49c | 70 | pad.tone(1000.0,0.1); |
AhmedPlaymaker | 6:3ffab44ed49c | 71 | //game.init(); |
AhmedPlaymaker | 1:32e312688a65 | 72 | |
AhmedPlaymaker | 1:32e312688a65 | 73 | } |
AhmedPlaymaker | 1:32e312688a65 | 74 | |
AhmedPlaymaker | 1:32e312688a65 | 75 | void refresh_game() |
AhmedPlaymaker | 1:32e312688a65 | 76 | { |
AhmedPlaymaker | 3:fbb1fa853f09 | 77 | lcd.clear(); |
AhmedPlaymaker | 6:3ffab44ed49c | 78 | //game.draw(lcd, pad); |
AhmedPlaymaker | 1:32e312688a65 | 79 | lcd.refresh(); |
AhmedPlaymaker | 3:fbb1fa853f09 | 80 | |
AhmedPlaymaker | 0:4b15c2d4aa58 | 81 | } |