
Final Commit
Dependencies: mbed
main.cpp@11:e260c17a0489, 2018-04-06 (annotated)
- Committer:
- JRM1986
- Date:
- Fri Apr 06 15:15:50 2018 +0000
- Revision:
- 11:e260c17a0489
- Parent:
- 10:62d8cb7742c3
- Child:
- 12:9f2f64016f56
Direction function debugged and test routine run ; Postion function test routine created not run
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 | 6:f3f508cea1c4 | 11 | struct UserInput |
JRM1986 | 6:f3f508cea1c4 | 12 | { |
JRM1986 | 6:f3f508cea1c4 | 13 | |
JRM1986 | 6:f3f508cea1c4 | 14 | Direction d; |
JRM1986 | 6:f3f508cea1c4 | 15 | |
JRM1986 | 6:f3f508cea1c4 | 16 | }; |
JRM1986 | 6:f3f508cea1c4 | 17 | |
JRM1986 | 0:53ee0f689634 | 18 | /* |
JRM1986 | 0:53ee0f689634 | 19 | ELEC2645 Embedded Systems Project |
JRM1986 | 7:c38800a428a6 | 20 | School of Electronic & Electrical Engineering |
JRM1986 | 0:53ee0f689634 | 21 | University of Leeds |
JRM1986 | 0:53ee0f689634 | 22 | Name: Joshua Robert Marshall |
JRM1986 | 0:53ee0f689634 | 23 | Username: ll13jrm |
JRM1986 | 0:53ee0f689634 | 24 | Student ID Number: 200764543 |
JRM1986 | 0:53ee0f689634 | 25 | Date: 28/02/2018 |
JRM1986 | 3:50f01159c61d | 26 | */ |
JRM1986 | 3:50f01159c61d | 27 | |
JRM1986 | 6:f3f508cea1c4 | 28 | // ----- Objects ----- |
JRM1986 | 6:f3f508cea1c4 | 29 | |
JRM1986 | 6:f3f508cea1c4 | 30 | SnakeEngine snake_engine; |
JRM1986 | 6:f3f508cea1c4 | 31 | Gamepad pad; |
JRM1986 | 10:62d8cb7742c3 | 32 | Snake snake; |
JRM1986 | 6:f3f508cea1c4 | 33 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
JRM1986 | 11:e260c17a0489 | 34 | Testing test1; |
JRM1986 | 3:50f01159c61d | 35 | |
JRM1986 | 6:f3f508cea1c4 | 36 | // ----- Prototypes ----- |
JRM1986 | 6:f3f508cea1c4 | 37 | |
JRM1986 | 6:f3f508cea1c4 | 38 | void init(); |
JRM1986 | 6:f3f508cea1c4 | 39 | void update_game(UserInput input); |
JRM1986 | 6:f3f508cea1c4 | 40 | void render(); |
JRM1986 | 6:f3f508cea1c4 | 41 | void start_menu(); |
JRM1986 | 6:f3f508cea1c4 | 42 | |
JRM1986 | 3:50f01159c61d | 43 | int main() { |
JRM1986 | 8:a2b431b9b3f7 | 44 | |
JRM1986 | 8:a2b431b9b3f7 | 45 | init(); |
JRM1986 | 8:a2b431b9b3f7 | 46 | //render(); |
JRM1986 | 8:a2b431b9b3f7 | 47 | wait(1.0); |
JRM1986 | 8:a2b431b9b3f7 | 48 | |
JRM1986 | 8:a2b431b9b3f7 | 49 | while(1) { |
JRM1986 | 10:62d8cb7742c3 | 50 | |
JRM1986 | 10:62d8cb7742c3 | 51 | snake_engine.get_input(pad, snake); |
JRM1986 | 10:62d8cb7742c3 | 52 | snake_engine.update(pad); |
JRM1986 | 9:561e5681b7a6 | 53 | render(); |
JRM1986 | 9:561e5681b7a6 | 54 | wait(1.0); |
JRM1986 | 10:62d8cb7742c3 | 55 | |
JRM1986 | 10:62d8cb7742c3 | 56 | |
JRM1986 | 10:62d8cb7742c3 | 57 | |
JRM1986 | 11:e260c17a0489 | 58 | |
JRM1986 | 11:e260c17a0489 | 59 | /* |
JRM1986 | 11:e260c17a0489 | 60 | if(test1.update_snake_test(W, E)) { |
JRM1986 | 10:62d8cb7742c3 | 61 | |
JRM1986 | 11:e260c17a0489 | 62 | printf("Passed direction test1 \n"); |
JRM1986 | 10:62d8cb7742c3 | 63 | |
JRM1986 | 10:62d8cb7742c3 | 64 | } |
JRM1986 | 11:e260c17a0489 | 65 | else { |
JRM1986 | 11:e260c17a0489 | 66 | |
JRM1986 | 11:e260c17a0489 | 67 | printf("Failed direction test \n"); |
JRM1986 | 11:e260c17a0489 | 68 | |
JRM1986 | 11:e260c17a0489 | 69 | }*/ |
JRM1986 | 11:e260c17a0489 | 70 | |
JRM1986 | 11:e260c17a0489 | 71 | if(test1.position_test(W, E)) { |
JRM1986 | 11:e260c17a0489 | 72 | |
JRM1986 | 11:e260c17a0489 | 73 | printf("Passed position test1 \n"); |
JRM1986 | 11:e260c17a0489 | 74 | |
JRM1986 | 11:e260c17a0489 | 75 | } |
JRM1986 | 11:e260c17a0489 | 76 | else { |
JRM1986 | 11:e260c17a0489 | 77 | |
JRM1986 | 11:e260c17a0489 | 78 | printf("Failed position test \n"); |
JRM1986 | 11:e260c17a0489 | 79 | |
JRM1986 | 11:e260c17a0489 | 80 | } |
JRM1986 | 5:27fcb9b36e7e | 81 | |
JRM1986 | 5:27fcb9b36e7e | 82 | } |
JRM1986 | 6:f3f508cea1c4 | 83 | } |
JRM1986 | 3:50f01159c61d | 84 | |
JRM1986 | 6:f3f508cea1c4 | 85 | // initialies all classes and libraries |
JRM1986 | 6:f3f508cea1c4 | 86 | void init() |
JRM1986 | 6:f3f508cea1c4 | 87 | { |
JRM1986 | 6:f3f508cea1c4 | 88 | // need to initialise LCD and Gamepad |
JRM1986 | 6:f3f508cea1c4 | 89 | lcd.init(); |
JRM1986 | 6:f3f508cea1c4 | 90 | pad.init(); |
JRM1986 | 6:f3f508cea1c4 | 91 | |
JRM1986 | 6:f3f508cea1c4 | 92 | // initialise the game with food, snake... |
JRM1986 | 10:62d8cb7742c3 | 93 | snake_engine.init(); |
JRM1986 | 6:f3f508cea1c4 | 94 | |
JRM1986 | 6:f3f508cea1c4 | 95 | } |
JRM1986 | 6:f3f508cea1c4 | 96 | |
JRM1986 | 6:f3f508cea1c4 | 97 | // this function draws each frame on the LCD |
JRM1986 | 6:f3f508cea1c4 | 98 | void render() |
JRM1986 | 6:f3f508cea1c4 | 99 | { |
JRM1986 | 6:f3f508cea1c4 | 100 | // clear screen, re-draw and refresh |
JRM1986 | 8:a2b431b9b3f7 | 101 | lcd.clear(); |
JRM1986 | 8:a2b431b9b3f7 | 102 | snake_engine.draw(lcd); |
JRM1986 | 6:f3f508cea1c4 | 103 | lcd.refresh(); |
JRM1986 | 8:a2b431b9b3f7 | 104 | |
JRM1986 | 6:f3f508cea1c4 | 105 | } |
JRM1986 | 6:f3f508cea1c4 | 106 | |
JRM1986 | 6:f3f508cea1c4 | 107 | void start_menu() { |
JRM1986 | 6:f3f508cea1c4 | 108 | |
JRM1986 | 6:f3f508cea1c4 | 109 | // brings up start menu, levels, scores |
JRM1986 | 6:f3f508cea1c4 | 110 | |
JRM1986 | 6:f3f508cea1c4 | 111 | } |