Final Commit

Dependencies:   mbed

Committer:
JRM1986
Date:
Wed Apr 04 12:25:51 2018 +0000
Revision:
10:62d8cb7742c3
Parent:
9:561e5681b7a6
Child:
11:e260c17a0489
Function to set and return direction works in low level test, unable to implement as FSM as of yet.

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 10:62d8cb7742c3 32 Snake snake;
JRM1986 6:f3f508cea1c4 33 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
JRM1986 5:27fcb9b36e7e 34 Testing test;
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 10:62d8cb7742c3 58 if(test.direction_test()) {
JRM1986 10:62d8cb7742c3 59
JRM1986 10:62d8cb7742c3 60 printf("Passed direction test \n");
JRM1986 10:62d8cb7742c3 61
JRM1986 10:62d8cb7742c3 62 }
JRM1986 10:62d8cb7742c3 63
JRM1986 10:62d8cb7742c3 64 else {
JRM1986 10:62d8cb7742c3 65
JRM1986 10:62d8cb7742c3 66 printf("Failed direction test \n");
JRM1986 10:62d8cb7742c3 67
JRM1986 10:62d8cb7742c3 68 }
JRM1986 5:27fcb9b36e7e 69
JRM1986 5:27fcb9b36e7e 70 }
JRM1986 6:f3f508cea1c4 71 }
JRM1986 3:50f01159c61d 72
JRM1986 6:f3f508cea1c4 73 // initialies all classes and libraries
JRM1986 6:f3f508cea1c4 74 void init()
JRM1986 6:f3f508cea1c4 75 {
JRM1986 6:f3f508cea1c4 76 // need to initialise LCD and Gamepad
JRM1986 6:f3f508cea1c4 77 lcd.init();
JRM1986 6:f3f508cea1c4 78 pad.init();
JRM1986 6:f3f508cea1c4 79
JRM1986 6:f3f508cea1c4 80 // initialise the game with food, snake...
JRM1986 10:62d8cb7742c3 81 snake_engine.init();
JRM1986 6:f3f508cea1c4 82
JRM1986 6:f3f508cea1c4 83 }
JRM1986 6:f3f508cea1c4 84
JRM1986 6:f3f508cea1c4 85 // this function draws each frame on the LCD
JRM1986 6:f3f508cea1c4 86 void render()
JRM1986 6:f3f508cea1c4 87 {
JRM1986 6:f3f508cea1c4 88 // clear screen, re-draw and refresh
JRM1986 8:a2b431b9b3f7 89 lcd.clear();
JRM1986 8:a2b431b9b3f7 90 snake_engine.draw(lcd);
JRM1986 6:f3f508cea1c4 91 lcd.refresh();
JRM1986 8:a2b431b9b3f7 92
JRM1986 6:f3f508cea1c4 93 }
JRM1986 6:f3f508cea1c4 94
JRM1986 6:f3f508cea1c4 95 void start_menu() {
JRM1986 6:f3f508cea1c4 96
JRM1986 6:f3f508cea1c4 97 // brings up start menu, levels, scores
JRM1986 6:f3f508cea1c4 98
JRM1986 6:f3f508cea1c4 99 }