Final Commit

Dependencies:   mbed

Committer:
JRM1986
Date:
Tue Apr 03 12:24:18 2018 +0000
Revision:
9:561e5681b7a6
Parent:
8:a2b431b9b3f7
Child:
10:62d8cb7742c3
Functions to set and return direction of snake head, and position of snake head respectively done but not tested

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 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 6:f3f508cea1c4 32 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
JRM1986 5:27fcb9b36e7e 33 Testing test;
JRM1986 3:50f01159c61d 34
JRM1986 6:f3f508cea1c4 35 // ----- Prototypes -----
JRM1986 6:f3f508cea1c4 36
JRM1986 6:f3f508cea1c4 37 void init();
JRM1986 6:f3f508cea1c4 38 void update_game(UserInput input);
JRM1986 6:f3f508cea1c4 39 void render();
JRM1986 6:f3f508cea1c4 40 void start_menu();
JRM1986 6:f3f508cea1c4 41
JRM1986 3:50f01159c61d 42 int main() {
JRM1986 8:a2b431b9b3f7 43
JRM1986 8:a2b431b9b3f7 44 init();
JRM1986 8:a2b431b9b3f7 45 //render();
JRM1986 8:a2b431b9b3f7 46 wait(1.0);
JRM1986 8:a2b431b9b3f7 47
JRM1986 8:a2b431b9b3f7 48 while(1) {
JRM1986 8:a2b431b9b3f7 49
JRM1986 9:561e5681b7a6 50 render();
JRM1986 9:561e5681b7a6 51 wait(1.0);
JRM1986 5:27fcb9b36e7e 52
JRM1986 5:27fcb9b36e7e 53 }
JRM1986 6:f3f508cea1c4 54 }
JRM1986 3:50f01159c61d 55
JRM1986 6:f3f508cea1c4 56 // initialies all classes and libraries
JRM1986 6:f3f508cea1c4 57 void init()
JRM1986 6:f3f508cea1c4 58 {
JRM1986 6:f3f508cea1c4 59 // need to initialise LCD and Gamepad
JRM1986 6:f3f508cea1c4 60 lcd.init();
JRM1986 6:f3f508cea1c4 61 pad.init();
JRM1986 6:f3f508cea1c4 62
JRM1986 6:f3f508cea1c4 63 // initialise the game with food, snake...
JRM1986 8:a2b431b9b3f7 64 //snake_engine.init(FOOD_X, FOOD_Y);
JRM1986 6:f3f508cea1c4 65
JRM1986 6:f3f508cea1c4 66 }
JRM1986 6:f3f508cea1c4 67
JRM1986 6:f3f508cea1c4 68 // this function draws each frame on the LCD
JRM1986 6:f3f508cea1c4 69 void render()
JRM1986 6:f3f508cea1c4 70 {
JRM1986 6:f3f508cea1c4 71 // clear screen, re-draw and refresh
JRM1986 8:a2b431b9b3f7 72 lcd.clear();
JRM1986 8:a2b431b9b3f7 73 snake_engine.draw(lcd);
JRM1986 6:f3f508cea1c4 74 lcd.refresh();
JRM1986 8:a2b431b9b3f7 75
JRM1986 6:f3f508cea1c4 76 }
JRM1986 6:f3f508cea1c4 77
JRM1986 6:f3f508cea1c4 78 void start_menu() {
JRM1986 6:f3f508cea1c4 79
JRM1986 6:f3f508cea1c4 80 // brings up start menu, levels, scores
JRM1986 6:f3f508cea1c4 81
JRM1986 6:f3f508cea1c4 82 }