Thomas Gill / Mbed 2 deprecated LabyrinthOfTheMinotaur

Dependencies:   N5110 PowerControl mbed

Revision:
20:e54792b89571
Parent:
19:1ab2d83ebffa
Child:
21:aa4feee6aa39
--- a/main.cpp	Mon May 04 15:25:02 2015 +0000
+++ b/main.cpp	Mon May 04 16:26:43 2015 +0000
@@ -1,7 +1,7 @@
-#include "mbed.h"
 #include "N5110.h"
 #include "PowerControl/PowerControl.h"
 #include "PowerControl/EthernetPowerControl.h"
+#include "WorldBuilder.h"
 
 //         vcc sce rst dc  mosi clk  led
 N5110 lcd (p5, p6, p7, p8, p11, p13, p21);
@@ -15,22 +15,6 @@
 
 #define USR_POWERDOWN (0x104)
 
-#define WALL 0
-#define FLOOR 1
-#define ENTER 2
-#define EXIT 3
-#define FLOOR_SEEN 4
-#define CHEST 5
-#define CHEST_OPENED 6
-
-#define RIGHT 0
-#define LEFT 1
-#define UP 2
-#define DOWN 3
-
-#define SOUTH 0
-#define EAST 1
-
 struct TILES {
     char    Symbol; // Symbol for this tile
     bool   Passable; // Can tile be walked on
@@ -91,22 +75,6 @@
 int StartFlag = 0;
 int DirFlag = 0;
 
-int map[84][48];
-
-//Enterance coordinates
-int enx;
-int eny;
-
-//Exit coordinates
-int exx;
-int exy;
-
-int sx;
-int sy;
-int dir;
-
-int level;
-
 //Space type player is on
 int pSpace;
 
@@ -148,27 +116,6 @@
 void MainMenu();
 void GameLoop();
 
-void Walls()
-{
-    //Fill map with walls
-    for(int i=0; i<84; i++) {
-        for (int j=0; j<48; j++) {
-
-            map[i][j] = WALL;
-        }
-    }
-}
-
-void Floors()
-{
-    //Fill map with floors
-    for(int i=0; i<84; i++) {
-        for (int j=0; j<48; j++) {
-            map[i][j] = FLOOR;
-        }
-    }
-}
-
 void FlashPlayerLocation()
 {
     lcd.setPixel(px,py);
@@ -193,318 +140,7 @@
         }
     }
     lcd.refresh();
-}
-
-void FirstRoom()
-{
-    //Create initial room
-    int si = rand()%25 + 1;
-    int sj = rand()%15 + 1;
-
-    int sw = rand()%5+5;
-    int sh = rand()%5+5;
-
-    for(int i = si, w = si + sw; i <w; i++) {
-        for (int j = sj, h = sj + sh; j <h; j++) {
-            map[i][j] = FLOOR;
-        }
-    }
-    //Create enterance in room
-    enx = rand()%sw + si;
-    eny = rand()%sh + sj;
-    map[enx][eny] = ENTER;
-}
-
-void ExitRoom()
-{
-    //Create exit room
-    int si = rand()%50 + 30;
-    int sj = rand()%25 + 20;
-
-    int sw = rand()%5+5;
-    int sh = rand()%5+5;
-
-    for(int i = si, w = si + sw; i <w; i++) {
-        for (int j = sj, h = sj + sh; j <h; j++) {
-            map[i][j] = FLOOR;
-        }
-    }
-    //Create exit in room
-    exx = rand()%sw + si;
-    exy = rand()%sh + sj;
-    map[exx][exy] = EXIT;
-
-}
-
-void DungeonRoomBuilder()
-{
-    sx = rand()%84;
-    sy = rand()%48;
-
-    //Get length
-    int sw = rand()%5 + 5;
-    int sh = rand()%5 + 5;
-
-    /*
-        int b = 0;
-
-        //Check each space. +1 to variable if wall. If total = w*h then build room
-        for(int i = sx; i < sx + sw; i++) {
-            for(int j = sy; j < sy + sh; j++) {
-                if(map[i][j] == WALL) {
-                    b++;
-                }
-            }
-        }
-        if(b == sw*sh) {
-            */
-    if(sx + sw < 83 && sy + sh < 47) {
-        for(int i = sx; i < sx + sw; i++) {
-            for(int j = sy; j < sy + sh; j++) {
-                if(i < 84 && j < 48) {
-                    map[i][j] = FLOOR;
-                }
-            }
-        }
-    }
-
-    if(rand()%3 == 0) {
-        int i = rand()%sw + sx;
-        int j = rand()%sh + sy;
-        map[i][j] = CHEST;
-    }
-}
-
-int Neighbours(int i, int j)
-{
-    //Check neighbours
-    int n = 0;
-
-    if(map[i+1][j] == FLOOR) {
-        n++;
-    }
-    if(map[i-1][j] == FLOOR) {
-        n++;
-    }
-    if(map[i][j+1] == FLOOR) {
-        n++;
-    }
-    if(map[i][j-1] == FLOOR) {
-        n++;
-    }
-
-    return n;
-}
-
-void DeadEnds(int d)
-{
-    for (int del = d; del > 0; del--) {
-        for(int i = 0; i < 84; i++) {
-            for(int j = 0; j < 48; j++) {
-
-                if(Neighbours(i , j) < 2) {
-                    map[i][j] = WALL;
-                }
-            }
-        }
-    }
-}
-
-void Border()
-{
-
-    for(int i = 0; i < 84; i++) {
-        for(int j = 0; j < 48; j++) {
-
-            if(i == 0 || i == 83 || j == 0 || j == 47) {
-
-                map[i][j] = WALL;
-
-            }
-        }
-    }
-}
-
-void RandFloor(int r)
-{
-
-    for(int space = rand()%50 + r; space > 0; space--) {
-
-        int i = rand()% 84;
-        int j = rand()% 48;
-
-        if(rand()%2 == 0 && map[i][j] == WALL) {
-            map[i][j] = FLOOR;
-        }
-    }
-
-}
-
-void MazeOld()
-{
-    for(int i = 1; i < 83; i+=2) {
-        for(int j = 1; j < 47; j+=2) {
-
-            if(map[i][j] == WALL) {
-                map[i][j] = FLOOR;
-            }
-
-            dir = rand()%2; //South or east
-
-
-            if(dir == SOUTH && j < 47 && map[i][j+1] == WALL) {
-                map[i][j+1] = FLOOR;
-            }
-            if(dir == EAST && i < 84 && map[i+1][j] == WALL) {
-                map[i+1][j] = FLOOR;
-            }
-        }
-    }
-}
-
-void MazeKill()
-{
-
-    int move[4] = { UP, DOWN, LEFT, RIGHT};
-
-    bool moved = true;
-
-    while(moved == true) {
-
-        moved = false;
-
-        for (int s = 0; s < 3; s++) { //Shuffle array
-
-            int r = rand() % 4;
-
-            int temp = move[s];
-
-            move[s] = move[r];
-
-            move[r] = temp;
-        }
-
-
-
-        for (int i = 0; i < 3; i++) {
-            if (move[i] == UP) {
-                if (map[sx][sy - 1] == WALL && Neighbours(sx, sy - 1) == 1 && map[sx][sy - 2] == WALL && Neighbours(sx, sy - 2) == 0 && sy > 3) {
-                    map[sx][sy - 1] = FLOOR;
-                    map[sx][sy - 2] = FLOOR;
-                    sy = sy - 2;
-                    moved = true;
-                    break;
-                }
-            } else if (move[i] == DOWN) {
-                if (map[sx][sy + 1] == WALL && Neighbours(sx, sy + 1) == 1 && map[sx][sy + 2] == WALL && Neighbours(sx, sy + 2) == 0 && sy < 45) {
-                    map[sx][sy + 1] = FLOOR;
-                    map[sx][sy + 2] = FLOOR;
-                    sy = sy + 2;
-                    moved = true;
-                    break;
-                }
-            } else if (move[i] == LEFT) {
-                if (map[sx - 1][sy] == WALL && Neighbours(sx - 1, sy) == 1 && map[sx - 2][sy] == WALL && Neighbours(sx - 2, sy) == 0 && sx > 3) {
-                    map[sx - 1][sy] = FLOOR;
-                    map[sx - 2][sy] = FLOOR;
-                    sx = sx - 2;
-                    moved = true;
-                    break;
-                }
-            } else if (move[i] == RIGHT) {
-                if (map[sx + 1][sy] == WALL && Neighbours(sx + 1, sy) == 1 && map[sx + 2][sy] == WALL && Neighbours(sx + 2, sy) == 0 && sx < 81) {
-                    map[sx + 1][sy] = FLOOR;
-                    map[sx + 2][sy] = FLOOR;
-                    sx = sx + 2;
-                    moved = true;
-                    break;
-                }
-            }
-        }
-    }
-
-}
-
-void Maze()
-{
-    sx = 1;
-    sy = 1;
-
-    //Choose random direction
-    //Check if 2 cells in direction have no neighbours (excluding current position)
-    //If true then build and set new current position
-    //If false chose next direction
-
-    //If cannot move in any direction scan through each cell until there is one which can be built on
-    //If scan completes END
-
-    int end = false;
-
-    while(end == false) {
-
-        end = true;
-
-        map[sx][sy] = FLOOR;
-
-        MazeKill();
-
-        //DrawMap();
-
-        for(int i = 1; i < 83; i++) {
-            for(int j = 1; j < 47; j++) {
-
-                if(map[i][j] == WALL && Neighbours(i, j) == 1) {
-                    sx = i;
-                    sy = j;
-
-                    end = false;
-                }
-
-            }
-        }
-
-    }
-}
-
-void DungeonBuilder()
-{
-
-    Maze();
-
-    FirstRoom();
-    ExitRoom();
-
-    int rn = rand()%10 + 6;
-
-    for(int i = rn; i>0; i--) {
-        DungeonRoomBuilder();
-    }
-
-
-
-    RandFloor(51);
-
-    Border();
-
-    DeadEnds(20);
-
-}
-
-void LabyrinthBuilder()
-{
-
-    Maze();
-
-    FirstRoom();
-    ExitRoom();
-
-
-
-    RandFloor(551);
-
-    Border();
-
-}
+}        
 
 void World()
 {
@@ -513,6 +149,7 @@
         LabyrinthBuilder();
     } else {
         DungeonBuilder();
+        //LabyrinthBuilder();
     }
 
     px = enx;