Testing submission
Dependencies: mbed ll16j23s_test_docs
main.cpp@14:2dfe04ced21c, 2020-05-27 (annotated)
- Committer:
- JoeShotton
- Date:
- Wed May 27 03:18:16 2020 +0000
- Revision:
- 14:2dfe04ced21c
- Parent:
- 13:7b7ec5db56b2
Final Version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eencae | 0:b7f1f47bb26a | 1 | /* |
eencae | 0:b7f1f47bb26a | 2 | ELEC2645 Embedded Systems Project |
eencae | 0:b7f1f47bb26a | 3 | School of Electronic & Electrical Engineering |
eencae | 0:b7f1f47bb26a | 4 | University of Leeds |
eencae | 0:b7f1f47bb26a | 5 | 2019/20 |
eencae | 0:b7f1f47bb26a | 6 | |
JoeShotton | 2:86b67b492cbc | 7 | Name: Joe Shotton |
JoeShotton | 2:86b67b492cbc | 8 | Username: ll16j23s |
JoeShotton | 2:86b67b492cbc | 9 | Student ID Number: 201127267 |
JoeShotton | 2:86b67b492cbc | 10 | Date: 4/4/20 |
eencae | 0:b7f1f47bb26a | 11 | */ |
eencae | 0:b7f1f47bb26a | 12 | |
eencae | 0:b7f1f47bb26a | 13 | // includes |
eencae | 0:b7f1f47bb26a | 14 | #include "mbed.h" |
eencae | 0:b7f1f47bb26a | 15 | #include "Gamepad.h" |
eencae | 0:b7f1f47bb26a | 16 | #include "N5110.h" |
JoeShotton | 3:fcd6d70e9694 | 17 | #include "FXOS8700CQ.h" |
JoeShotton | 3:fcd6d70e9694 | 18 | #include "SnakeEngine.h" |
JoeShotton | 3:fcd6d70e9694 | 19 | #include <vector> |
JoeShotton | 3:fcd6d70e9694 | 20 | #include <cstdlib> |
eencae | 0:b7f1f47bb26a | 21 | |
JoeShotton | 1:985dfa6cee28 | 22 | #define X_MAX 84 |
JoeShotton | 1:985dfa6cee28 | 23 | #define Y_MAX 48 |
eencae | 0:b7f1f47bb26a | 24 | |
eencae | 0:b7f1f47bb26a | 25 | // objects |
eencae | 0:b7f1f47bb26a | 26 | Gamepad pad; |
eencae | 0:b7f1f47bb26a | 27 | N5110 lcd; |
JoeShotton | 3:fcd6d70e9694 | 28 | SnakeEngine snake; |
JoeShotton | 5:06fa7674622a | 29 | FXOS8700CQ mag(I2C_SDA,I2C_SCL); |
eencae | 0:b7f1f47bb26a | 30 | |
JoeShotton | 1:985dfa6cee28 | 31 | int main() { |
JoeShotton | 1:985dfa6cee28 | 32 | |
JoeShotton | 10:a2d643b3c782 | 33 | lcd.init(); //initialise the screen |
JoeShotton | 10:a2d643b3c782 | 34 | pad.init(); //initialise the gamepad |
JoeShotton | 1:985dfa6cee28 | 35 | |
JoeShotton | 10:a2d643b3c782 | 36 | snake.game_state = 1; |
JoeShotton | 9:0571880085cc | 37 | snake.menu1_init(pad, lcd); |
JoeShotton | 3:fcd6d70e9694 | 38 | |
JoeShotton | 10:a2d643b3c782 | 39 | while(1) { |
JoeShotton | 10:a2d643b3c782 | 40 | |
JoeShotton | 10:a2d643b3c782 | 41 | while(snake.game_state == 1){ //menu 1 |
JoeShotton | 10:a2d643b3c782 | 42 | snake.menu1_select(pad, lcd, mag); //run menu 1 controls |
JoeShotton | 10:a2d643b3c782 | 43 | snake.contrast(pad, lcd); //set contrast with pot2 |
JoeShotton | 10:a2d643b3c782 | 44 | } |
JoeShotton | 1:985dfa6cee28 | 45 | |
JoeShotton | 10:a2d643b3c782 | 46 | while(snake.game_state == 2){ //menu 2 |
JoeShotton | 10:a2d643b3c782 | 47 | snake.menu2_select(pad, lcd, mag); //run menu 2 controls |
JoeShotton | 10:a2d643b3c782 | 48 | snake.contrast(pad, lcd); //set contrast with pot2 |
JoeShotton | 10:a2d643b3c782 | 49 | } |
JoeShotton | 7:dd84e0fab346 | 50 | |
JoeShotton | 10:a2d643b3c782 | 51 | while(snake.game_state == 3){ //game |
JoeShotton | 10:a2d643b3c782 | 52 | lcd.clear(); //reset the screen buffer |
JoeShotton | 10:a2d643b3c782 | 53 | snake.game_run(pad, lcd); //run the game |
JoeShotton | 10:a2d643b3c782 | 54 | lcd.refresh(); //refresh the screen with the updated buffer |
JoeShotton | 10:a2d643b3c782 | 55 | wait_ms(500/(5+snake.score)); //wait time is a function of the score |
JoeShotton | 10:a2d643b3c782 | 56 | } |
JoeShotton | 7:dd84e0fab346 | 57 | |
JoeShotton | 10:a2d643b3c782 | 58 | while(snake.game_state == 4){ //death menu |
JoeShotton | 10:a2d643b3c782 | 59 | snake.death_select(pad, lcd, mag); //run death menu controls |
JoeShotton | 10:a2d643b3c782 | 60 | snake.contrast(pad, lcd); //set contrast with pot2 |
JoeShotton | 10:a2d643b3c782 | 61 | } |
JoeShotton | 7:dd84e0fab346 | 62 | } |
JoeShotton | 10:a2d643b3c782 | 63 | } |