Final Commit

Dependencies:   mbed

Committer:
JRM1986
Date:
Wed Apr 18 10:38:10 2018 +0000
Revision:
16:85ca9feccf3f
Parent:
14:c3a435597196
Child:
18:406fc298a7c4
length counter works in conjuction with food/snake head collision detection

Who changed what in which revision?

UserRevisionLine numberNew 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 14:c3a435597196 49 wait(1.5);
JRM1986 13:72bc2579e85e 50
JRM1986 8:a2b431b9b3f7 51 while(1) {
JRM1986 10:62d8cb7742c3 52
JRM1986 13:72bc2579e85e 53 snake_engine.get_input(pad);
JRM1986 10:62d8cb7742c3 54 snake_engine.update(pad);
JRM1986 9:561e5681b7a6 55 render();
JRM1986 16:85ca9feccf3f 56
JRM1986 16:85ca9feccf3f 57 wait(0.3);
JRM1986 10:62d8cb7742c3 58
JRM1986 16:85ca9feccf3f 59 }
JRM1986 6:f3f508cea1c4 60 }
JRM1986 3:50f01159c61d 61
JRM1986 6:f3f508cea1c4 62 // initialies all classes and libraries
JRM1986 6:f3f508cea1c4 63 void init()
JRM1986 6:f3f508cea1c4 64 {
JRM1986 6:f3f508cea1c4 65 // need to initialise LCD and Gamepad
JRM1986 6:f3f508cea1c4 66 lcd.init();
JRM1986 6:f3f508cea1c4 67 pad.init();
JRM1986 6:f3f508cea1c4 68
JRM1986 6:f3f508cea1c4 69 // initialise the game with food, snake...
JRM1986 14:c3a435597196 70 snake_engine.init(43, 23);
JRM1986 6:f3f508cea1c4 71
JRM1986 6:f3f508cea1c4 72 }
JRM1986 6:f3f508cea1c4 73
JRM1986 6:f3f508cea1c4 74 // this function draws each frame on the LCD
JRM1986 6:f3f508cea1c4 75 void render()
JRM1986 6:f3f508cea1c4 76 {
JRM1986 6:f3f508cea1c4 77 // clear screen, re-draw and refresh
JRM1986 8:a2b431b9b3f7 78 lcd.clear();
JRM1986 8:a2b431b9b3f7 79 snake_engine.draw(lcd);
JRM1986 6:f3f508cea1c4 80 lcd.refresh();
JRM1986 8:a2b431b9b3f7 81
JRM1986 6:f3f508cea1c4 82 }
JRM1986 6:f3f508cea1c4 83
JRM1986 16:85ca9feccf3f 84 void start_menu()
JRM1986 16:85ca9feccf3f 85 {
JRM1986 6:f3f508cea1c4 86
JRM1986 6:f3f508cea1c4 87 // brings up start menu, levels, scores
JRM1986 6:f3f508cea1c4 88
JRM1986 6:f3f508cea1c4 89 }