
Final Commit
Dependencies: mbed
main.cpp@20:277e88a8185f, 2018-04-30 (annotated)
- Committer:
- JRM1986
- Date:
- Mon Apr 30 11:15:44 2018 +0000
- Revision:
- 20:277e88a8185f
- Parent:
- 19:b437806e579b
- Child:
- 21:63c5590cb2c2
removing unneccessary global variables;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JRM1986 | 3:50f01159c61d | 1 | #include "mbed.h" |
JRM1986 | 3:50f01159c61d | 2 | #include "FXOS8700CQ.h" |
JRM1986 | 3:50f01159c61d | 3 | #include "Gamepad.h" |
JRM1986 | 3:50f01159c61d | 4 | #include "N5110.h" |
JRM1986 | 5:27fcb9b36e7e | 5 | #include "Testing.h" |
JRM1986 | 6:f3f508cea1c4 | 6 | #include "SnakeEngine.h" |
JRM1986 | 6:f3f508cea1c4 | 7 | |
JRM1986 | 8:a2b431b9b3f7 | 8 | #define FOOD_X 20 |
JRM1986 | 8:a2b431b9b3f7 | 9 | #define FOOD_Y 20 |
JRM1986 | 20:277e88a8185f | 10 | #define SNAKE_P_X 42 |
JRM1986 | 20:277e88a8185f | 11 | #define SNAKE_P_Y 24 |
JRM1986 | 20:277e88a8185f | 12 | #define IN E |
JRM1986 | 20:277e88a8185f | 13 | #define CUR E |
JRM1986 | 13:72bc2579e85e | 14 | |
JRM1986 | 6:f3f508cea1c4 | 15 | struct UserInput |
JRM1986 | 6:f3f508cea1c4 | 16 | { |
JRM1986 | 6:f3f508cea1c4 | 17 | |
JRM1986 | 6:f3f508cea1c4 | 18 | Direction d; |
JRM1986 | 6:f3f508cea1c4 | 19 | |
JRM1986 | 6:f3f508cea1c4 | 20 | }; |
JRM1986 | 6:f3f508cea1c4 | 21 | |
JRM1986 | 12:9f2f64016f56 | 22 | |
JRM1986 | 0:53ee0f689634 | 23 | /* |
JRM1986 | 0:53ee0f689634 | 24 | ELEC2645 Embedded Systems Project |
JRM1986 | 7:c38800a428a6 | 25 | School of Electronic & Electrical Engineering |
JRM1986 | 0:53ee0f689634 | 26 | University of Leeds |
JRM1986 | 0:53ee0f689634 | 27 | Name: Joshua Robert Marshall |
JRM1986 | 0:53ee0f689634 | 28 | Username: ll13jrm |
JRM1986 | 0:53ee0f689634 | 29 | Student ID Number: 200764543 |
JRM1986 | 0:53ee0f689634 | 30 | Date: 28/02/2018 |
JRM1986 | 3:50f01159c61d | 31 | */ |
JRM1986 | 3:50f01159c61d | 32 | |
JRM1986 | 6:f3f508cea1c4 | 33 | // ----- Objects ----- |
JRM1986 | 6:f3f508cea1c4 | 34 | |
JRM1986 | 6:f3f508cea1c4 | 35 | SnakeEngine snake_engine; |
JRM1986 | 6:f3f508cea1c4 | 36 | Gamepad pad; |
JRM1986 | 10:62d8cb7742c3 | 37 | Snake snake; |
JRM1986 | 6:f3f508cea1c4 | 38 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
JRM1986 | 11:e260c17a0489 | 39 | Testing test1; |
JRM1986 | 3:50f01159c61d | 40 | |
JRM1986 | 6:f3f508cea1c4 | 41 | // ----- Prototypes ----- |
JRM1986 | 6:f3f508cea1c4 | 42 | |
JRM1986 | 6:f3f508cea1c4 | 43 | void init(); |
JRM1986 | 6:f3f508cea1c4 | 44 | void update_game(UserInput input); |
JRM1986 | 6:f3f508cea1c4 | 45 | void render(); |
JRM1986 | 6:f3f508cea1c4 | 46 | void start_menu(); |
JRM1986 | 6:f3f508cea1c4 | 47 | |
JRM1986 | 3:50f01159c61d | 48 | int main() { |
JRM1986 | 8:a2b431b9b3f7 | 49 | |
JRM1986 | 8:a2b431b9b3f7 | 50 | init(); |
JRM1986 | 13:72bc2579e85e | 51 | render(); |
JRM1986 | 20:277e88a8185f | 52 | |
JRM1986 | 20:277e88a8185f | 53 | wait(0.3); |
JRM1986 | 20:277e88a8185f | 54 | |
JRM1986 | 8:a2b431b9b3f7 | 55 | while(1) { |
JRM1986 | 10:62d8cb7742c3 | 56 | |
JRM1986 | 13:72bc2579e85e | 57 | snake_engine.get_input(pad); |
JRM1986 | 10:62d8cb7742c3 | 58 | snake_engine.update(pad); |
JRM1986 | 9:561e5681b7a6 | 59 | render(); |
JRM1986 | 16:85ca9feccf3f | 60 | |
JRM1986 | 16:85ca9feccf3f | 61 | wait(0.3); |
JRM1986 | 10:62d8cb7742c3 | 62 | |
JRM1986 | 16:85ca9feccf3f | 63 | } |
JRM1986 | 6:f3f508cea1c4 | 64 | } |
JRM1986 | 3:50f01159c61d | 65 | |
JRM1986 | 6:f3f508cea1c4 | 66 | // initialies all classes and libraries |
JRM1986 | 6:f3f508cea1c4 | 67 | void init() |
JRM1986 | 6:f3f508cea1c4 | 68 | { |
JRM1986 | 6:f3f508cea1c4 | 69 | // need to initialise LCD and Gamepad |
JRM1986 | 6:f3f508cea1c4 | 70 | lcd.init(); |
JRM1986 | 6:f3f508cea1c4 | 71 | pad.init(); |
JRM1986 | 6:f3f508cea1c4 | 72 | |
JRM1986 | 6:f3f508cea1c4 | 73 | // initialise the game with food, snake... |
JRM1986 | 20:277e88a8185f | 74 | snake_engine.init(IN, CUR, SNAKE_P_X, SNAKE_P_Y); |
JRM1986 | 6:f3f508cea1c4 | 75 | |
JRM1986 | 6:f3f508cea1c4 | 76 | } |
JRM1986 | 6:f3f508cea1c4 | 77 | |
JRM1986 | 6:f3f508cea1c4 | 78 | // this function draws each frame on the LCD |
JRM1986 | 6:f3f508cea1c4 | 79 | void render() |
JRM1986 | 6:f3f508cea1c4 | 80 | { |
JRM1986 | 6:f3f508cea1c4 | 81 | // clear screen, re-draw and refresh |
JRM1986 | 8:a2b431b9b3f7 | 82 | lcd.clear(); |
JRM1986 | 8:a2b431b9b3f7 | 83 | snake_engine.draw(lcd); |
JRM1986 | 6:f3f508cea1c4 | 84 | lcd.refresh(); |
JRM1986 | 8:a2b431b9b3f7 | 85 | |
JRM1986 | 6:f3f508cea1c4 | 86 | } |
JRM1986 | 6:f3f508cea1c4 | 87 | |
JRM1986 | 16:85ca9feccf3f | 88 | void start_menu() |
JRM1986 | 16:85ca9feccf3f | 89 | { |
JRM1986 | 6:f3f508cea1c4 | 90 | |
JRM1986 | 6:f3f508cea1c4 | 91 | |
JRM1986 | 6:f3f508cea1c4 | 92 | } |