Final Commit

Dependencies:   mbed

Committer:
JRM1986
Date:
Thu Mar 22 14:52:08 2018 +0000
Revision:
8:a2b431b9b3f7
Parent:
7:c38800a428a6
Child:
9:561e5681b7a6
Function to get random position for food now working; To do next; Snake movement; Snake 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 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 8:a2b431b9b3f7 50 // render();
JRM1986 8:a2b431b9b3f7 51 // wait(1.0);
JRM1986 8:a2b431b9b3f7 52 if(test.food_test_position()) {
JRM1986 8:a2b431b9b3f7 53
JRM1986 8:a2b431b9b3f7 54 printf("Passed position test \n");
JRM1986 8:a2b431b9b3f7 55
JRM1986 8:a2b431b9b3f7 56 }
JRM1986 6:f3f508cea1c4 57
JRM1986 8:a2b431b9b3f7 58 else {
JRM1986 8:a2b431b9b3f7 59
JRM1986 8:a2b431b9b3f7 60 printf("Failed position test \n");
JRM1986 8:a2b431b9b3f7 61
JRM1986 8:a2b431b9b3f7 62 }
JRM1986 5:27fcb9b36e7e 63
JRM1986 8:a2b431b9b3f7 64 if(test.food_test_range()) {
JRM1986 8:a2b431b9b3f7 65
JRM1986 8:a2b431b9b3f7 66 printf("Passed Range Test \n");
JRM1986 8:a2b431b9b3f7 67
JRM1986 8:a2b431b9b3f7 68 }
JRM1986 8:a2b431b9b3f7 69
JRM1986 8:a2b431b9b3f7 70 else {
JRM1986 8:a2b431b9b3f7 71
JRM1986 8:a2b431b9b3f7 72 printf("Failed Range Test \n");
JRM1986 8:a2b431b9b3f7 73
JRM1986 8:a2b431b9b3f7 74 }
JRM1986 8:a2b431b9b3f7 75
JRM1986 8:a2b431b9b3f7 76 wait(1.0);
JRM1986 8:a2b431b9b3f7 77
JRM1986 5:27fcb9b36e7e 78 }
JRM1986 6:f3f508cea1c4 79 }
JRM1986 3:50f01159c61d 80
JRM1986 6:f3f508cea1c4 81 // initialies all classes and libraries
JRM1986 6:f3f508cea1c4 82 void init()
JRM1986 6:f3f508cea1c4 83 {
JRM1986 6:f3f508cea1c4 84 // need to initialise LCD and Gamepad
JRM1986 6:f3f508cea1c4 85 lcd.init();
JRM1986 6:f3f508cea1c4 86 pad.init();
JRM1986 6:f3f508cea1c4 87
JRM1986 6:f3f508cea1c4 88 // initialise the game with food, snake...
JRM1986 8:a2b431b9b3f7 89 //snake_engine.init(FOOD_X, FOOD_Y);
JRM1986 6:f3f508cea1c4 90
JRM1986 6:f3f508cea1c4 91 }
JRM1986 6:f3f508cea1c4 92
JRM1986 6:f3f508cea1c4 93 // this function draws each frame on the LCD
JRM1986 6:f3f508cea1c4 94 void render()
JRM1986 6:f3f508cea1c4 95 {
JRM1986 6:f3f508cea1c4 96 // clear screen, re-draw and refresh
JRM1986 8:a2b431b9b3f7 97 lcd.clear();
JRM1986 8:a2b431b9b3f7 98 snake_engine.draw(lcd);
JRM1986 6:f3f508cea1c4 99 lcd.refresh();
JRM1986 8:a2b431b9b3f7 100
JRM1986 6:f3f508cea1c4 101 }
JRM1986 6:f3f508cea1c4 102
JRM1986 6:f3f508cea1c4 103 void start_menu() {
JRM1986 6:f3f508cea1c4 104
JRM1986 6:f3f508cea1c4 105 // brings up start menu, levels, scores
JRM1986 6:f3f508cea1c4 106
JRM1986 6:f3f508cea1c4 107 }