Thomas Gill / Mbed 2 deprecated LabyrinthOfTheMinotaur

Dependencies:   N5110 PowerControl mbed

Revision:
8:ee857f0147aa
Parent:
7:cd799c701997
Child:
9:3cad581b5419
--- a/main.cpp	Fri Apr 17 12:58:04 2015 +0000
+++ b/main.cpp	Fri Apr 17 14:27:13 2015 +0000
@@ -28,13 +28,12 @@
 #define SOUTH 0
 #define EAST 1
 
-struct TILE
-{
+struct TILES {
     char    Symbol; // Symbol for this tile
     bool   Passable; // Can tile be walked on
 };
 
-TILE  TileList[] = {
+TILES  TileList[] = {
     { '#', false },  // 0- WALL
     { '.', true},  // 1- FLOOR
     { '+', true }, // 2- ENTER
@@ -177,9 +176,9 @@
         }
     }
     //Create exit in room
-    enx = rand()%sw + si;
-    eny = rand()%sh + sj;
-    map[enx][eny] = EXIT;
+    exx = rand()%sw + si;
+    exy = rand()%sh + sj;
+    map[exx][exy] = EXIT;
 }
 
 void DungeonRoomBuilder()
@@ -214,7 +213,6 @@
 
 void Neighbours()
 {
-
     //Check neighbours
     n = 0;
 
@@ -332,8 +330,73 @@
 
     DrawMap();
 
+    px = enx;
+    py = eny;
+
+    wait(1.0);
+
+
+
 }
 
+void PlayerCamera()
+{
+    lcd.clear();
+
+    int tile;
+
+    for(int i = 0; i < 14; i++) {
+        for(int j = 0; j < 6; j++) {
+
+            if(i == 6 && j == 2) {
+                lcd.printString("@", (6*i)+1, j);
+            } else {
+
+                int diffx = i - 6;
+                int diffy = j - 2;
+
+                tile = map[px+diffx][py+diffy];
+
+                lcd.printChar(TileList[tile].Symbol, (6*i)+1, j);
+            }
+        }
+    }
+
+    lcd.refresh();
+}
+
+void PlayerMove()
+{
+
+    
+    if(Up) {
+        int tile = map[px][py-1];
+        if(TileList[tile].Passable) {
+            py--;
+        }
+    }
+    if(Down) {
+        int tile = map[px][py+1];
+        if(TileList[tile].Passable) {
+            py++;
+        }
+    }
+    if(Right) {
+        int tile = map[px+1][py];
+        if(TileList[tile].Passable) {
+            px++;
+        }
+    }
+    if(Left) {
+        int tile = map[px-1][py];
+        if(TileList[tile].Passable) {
+            px--;
+        }
+    }
+
+}
+
+
 int main()
 {
     //Power Saving
@@ -345,11 +408,15 @@
 
     //Initilize screen
     lcd.init();
-    
+
     World();
 
     //Game loop
     while(1) {
-        
+
+        PlayerCamera();
+        PlayerMove();
+        wait(0.5);
+
     }
 }
\ No newline at end of file