
Final Commit
Dependencies: mbed
main.cpp@19:b437806e579b, 2018-04-30 (annotated)
- Committer:
- JRM1986
- Date:
- Mon Apr 30 10:13:35 2018 +0000
- Revision:
- 19:b437806e579b
- Parent:
- 18:406fc298a7c4
- Child:
- 20:277e88a8185f
exeptions for set direction debugged, function for set direction seperated into smaller blocks;
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 | 7:c38800a428a6 | 10 | |
JRM1986 | 13:72bc2579e85e | 11 | |
JRM1986 | 6:f3f508cea1c4 | 12 | struct UserInput |
JRM1986 | 6:f3f508cea1c4 | 13 | { |
JRM1986 | 6:f3f508cea1c4 | 14 | |
JRM1986 | 6:f3f508cea1c4 | 15 | Direction d; |
JRM1986 | 6:f3f508cea1c4 | 16 | |
JRM1986 | 6:f3f508cea1c4 | 17 | }; |
JRM1986 | 6:f3f508cea1c4 | 18 | |
JRM1986 | 12:9f2f64016f56 | 19 | |
JRM1986 | 0:53ee0f689634 | 20 | /* |
JRM1986 | 0:53ee0f689634 | 21 | ELEC2645 Embedded Systems Project |
JRM1986 | 7:c38800a428a6 | 22 | School of Electronic & Electrical Engineering |
JRM1986 | 0:53ee0f689634 | 23 | University of Leeds |
JRM1986 | 0:53ee0f689634 | 24 | Name: Joshua Robert Marshall |
JRM1986 | 0:53ee0f689634 | 25 | Username: ll13jrm |
JRM1986 | 0:53ee0f689634 | 26 | Student ID Number: 200764543 |
JRM1986 | 0:53ee0f689634 | 27 | Date: 28/02/2018 |
JRM1986 | 3:50f01159c61d | 28 | */ |
JRM1986 | 3:50f01159c61d | 29 | |
JRM1986 | 6:f3f508cea1c4 | 30 | // ----- Objects ----- |
JRM1986 | 6:f3f508cea1c4 | 31 | |
JRM1986 | 6:f3f508cea1c4 | 32 | SnakeEngine snake_engine; |
JRM1986 | 6:f3f508cea1c4 | 33 | Gamepad pad; |
JRM1986 | 10:62d8cb7742c3 | 34 | Snake snake; |
JRM1986 | 6:f3f508cea1c4 | 35 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
JRM1986 | 11:e260c17a0489 | 36 | Testing test1; |
JRM1986 | 3:50f01159c61d | 37 | |
JRM1986 | 6:f3f508cea1c4 | 38 | // ----- Prototypes ----- |
JRM1986 | 6:f3f508cea1c4 | 39 | |
JRM1986 | 6:f3f508cea1c4 | 40 | void init(); |
JRM1986 | 6:f3f508cea1c4 | 41 | void update_game(UserInput input); |
JRM1986 | 6:f3f508cea1c4 | 42 | void render(); |
JRM1986 | 6:f3f508cea1c4 | 43 | void start_menu(); |
JRM1986 | 6:f3f508cea1c4 | 44 | |
JRM1986 | 3:50f01159c61d | 45 | int main() { |
JRM1986 | 8:a2b431b9b3f7 | 46 | |
JRM1986 | 8:a2b431b9b3f7 | 47 | init(); |
JRM1986 | 13:72bc2579e85e | 48 | render(); |
JRM1986 | 13:72bc2579e85e | 49 | |
JRM1986 | 8:a2b431b9b3f7 | 50 | while(1) { |
JRM1986 | 10:62d8cb7742c3 | 51 | |
JRM1986 | 13:72bc2579e85e | 52 | snake_engine.get_input(pad); |
JRM1986 | 10:62d8cb7742c3 | 53 | snake_engine.update(pad); |
JRM1986 | 9:561e5681b7a6 | 54 | render(); |
JRM1986 | 16:85ca9feccf3f | 55 | |
JRM1986 | 16:85ca9feccf3f | 56 | wait(0.3); |
JRM1986 | 10:62d8cb7742c3 | 57 | |
JRM1986 | 16:85ca9feccf3f | 58 | } |
JRM1986 | 6:f3f508cea1c4 | 59 | } |
JRM1986 | 3:50f01159c61d | 60 | |
JRM1986 | 6:f3f508cea1c4 | 61 | // initialies all classes and libraries |
JRM1986 | 6:f3f508cea1c4 | 62 | void init() |
JRM1986 | 6:f3f508cea1c4 | 63 | { |
JRM1986 | 6:f3f508cea1c4 | 64 | // need to initialise LCD and Gamepad |
JRM1986 | 6:f3f508cea1c4 | 65 | lcd.init(); |
JRM1986 | 6:f3f508cea1c4 | 66 | pad.init(); |
JRM1986 | 6:f3f508cea1c4 | 67 | |
JRM1986 | 6:f3f508cea1c4 | 68 | // initialise the game with food, snake... |
JRM1986 | 18:406fc298a7c4 | 69 | snake_engine.init(); |
JRM1986 | 6:f3f508cea1c4 | 70 | |
JRM1986 | 6:f3f508cea1c4 | 71 | } |
JRM1986 | 6:f3f508cea1c4 | 72 | |
JRM1986 | 6:f3f508cea1c4 | 73 | // this function draws each frame on the LCD |
JRM1986 | 6:f3f508cea1c4 | 74 | void render() |
JRM1986 | 6:f3f508cea1c4 | 75 | { |
JRM1986 | 6:f3f508cea1c4 | 76 | // clear screen, re-draw and refresh |
JRM1986 | 8:a2b431b9b3f7 | 77 | lcd.clear(); |
JRM1986 | 8:a2b431b9b3f7 | 78 | snake_engine.draw(lcd); |
JRM1986 | 6:f3f508cea1c4 | 79 | lcd.refresh(); |
JRM1986 | 8:a2b431b9b3f7 | 80 | |
JRM1986 | 6:f3f508cea1c4 | 81 | } |
JRM1986 | 6:f3f508cea1c4 | 82 | |
JRM1986 | 16:85ca9feccf3f | 83 | void start_menu() |
JRM1986 | 16:85ca9feccf3f | 84 | { |
JRM1986 | 6:f3f508cea1c4 | 85 | |
JRM1986 | 6:f3f508cea1c4 | 86 | |
JRM1986 | 6:f3f508cea1c4 | 87 | } |