Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using uRandom = UnityEngine.Random;
- using UnityEngine.Tilemaps;
- using System.Threading;
- using System.Linq;
- using System;
- public class GenerateTilemap : MonoBehaviour
- {
- private Tilemap m_Tilemap;
- [SerializeField] private TileBase m_Tile;
- [SerializeField] private Vector2 startEndEmptySpace = new Vector2(10, 5);
- private int[,] gridArray;
- private RoomClass[,] roomMap;
- /* Level Size Variables */
- private const int xMax = 225;
- private const int yMax = 125;
- private const int roomsX = 5;
- private const int roomsY = 5;
- private RelativeNeighbors directions = new RelativeNeighbors();
- public Player playerPrefab;
- public RoomClass roomPrefab;
- public RoomClass startRoom;
- public RoomClass exitRoom;
- public Player player;
- public Camera camera;
- public Vector2 startTilePos;
- public Vector2 endTilePos;
- public bool[,] visitedRooms;
- Dictionary<Vector2, Action> roomsPlacementList;
- // Start is called before the first frame update
- void Start()
- {
- roomsPlacementList = new Dictionary<Vector2, Action>();
- gridArray = GenerateArray(xMax, yMax, true);
- //player = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity);
- player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
- startRoom = Instantiate(roomPrefab, Vector3.zero, Quaternion.identity);
- exitRoom = Instantiate(roomPrefab, Vector3.zero, Quaternion.identity);
- startRoom.SetName("startRoom");
- exitRoom.SetName("exitRoom");
- ChooseStartAndEnd(ref startRoom, ref exitRoom);
- m_Tilemap = GetComponent<Tilemap>();
- camera = GameObject.Find("Main Camera").GetComponent<Camera>();
- camera.transform.SetParent(player.transform);
- camera.transform.localPosition = new Vector3(0, 0, -1);
- directions.Up = new Vector2(0, 1);
- directions.Down = new Vector2(0, -1);
- directions.Left = new Vector2(-1, 0);
- directions.Right = new Vector2(1, 0);
- directions.GetRandomDirection = delegate ()
- {
- int rand = uRandom.Range(0, 3);
- Vector2 randD = new Vector2(0, 0);
- switch (rand)
- {
- case 0:
- randD = this.directions.Up;
- break;
- case 1:
- randD = this.directions.Down;
- break;
- case 2:
- randD = this.directions.Left;
- break;
- case 3:
- randD = this.directions.Right;
- break;
- default:
- break;
- }
- return randD;
- };
- //directions.GetDirectionByIndex = new public delegate Vector2 (int index)
- //{
- // return Vector2.zero
- //}
- //// Remove tiles based on areas we need cleared
- //startRoom.PlaceRoom(ref gridArray);
- //exitRoom.PlaceRoom(ref gridArray);
- //for (int i = 0; i < 10; i++)
- //{
- // int randSizeX = (int) Mathf.Abs(uRandom.Range(5, 25));
- // int randSizeY = (int) Mathf.Abs(uRandom.Range(4, 15));
- // int randPosX = (int) Mathf.Abs(uRandom.Range(0 + Mathf.Ceil(randSizeX / 2), xMax - Mathf.Ceil(randSizeX / 2)));
- // int randPosY = (int)Mathf.Abs(uRandom.Range(0 + Mathf.Ceil(randSizeY / 2), yMax - Mathf.Ceil(randSizeY / 2)));
- // if (CanPlaceRoom(gridArray, new Vector2(randPosX, randPosY), randSizeX, randSizeY))
- // {
- // RoomClass newRoom = Instantiate(roomPrefab, Vector3.zero, Quaternion.identity);
- // newRoom.SetName("GeneratedRoom"+i);
- // newRoom.SetParams(new Vector2(randPosX, randPosY), new Vector2(randSizeX, randSizeY));
- // newRoom.UpdateCorners();
- // newRoom.SetRoomCorners(newRoom.GetRoomCorners());
- // newRoom.setDrawRoom(true);
- // this.roomsPlacementList.Add(newRoom.GetRoomPos(true), () => {
- // newRoom.PlaceRoom(ref gridArray);
- // });
- // }
- //}
- //foreach (Action action in roomsPlacementList.Values)
- //{
- // action();
- //}
- roomMap = new RoomClass[roomsX, roomsY];
- for (int x = 0; x <= roomMap.GetUpperBound(0); x++)
- {
- for (int y = 0; y <= roomMap.GetUpperBound(1); y++)
- {
- RoomClass newRoom = Instantiate(roomPrefab, Vector3.zero, Quaternion.identity);
- Vector2 roomSize = new Vector2( (int) Mathf.Floor(xMax / roomsX), (int) Mathf.Floor(yMax / roomsY) );
- Vector2 tilePos = new Vector2(x * roomSize.x, y * roomSize.y);
- newRoom.SetName("Room (" + x + ", " + y + ")");
- newRoom.SetParams(tilePos, roomSize);
- newRoom.SetRoomMapPos(new Vector2(x, y));
- newRoom.setDrawRoom(true);
- roomMap[x, y] = newRoom;
- }
- }
- GeneratePath();
- RenderMap(gridArray, m_Tilemap, m_Tile);
- }
- /* Methodology used:
- * Using a grid of 5x5 rooms, we create a weaved maze representing the flow of rooms the player needs to navigate in order to exit the level
- * We use this method or our room navigation: https://weblog.jamisbuck.org/2011/1/27/maze-generation-growing-tree-algorithm
- * We use this method for allowing "weaves" making the map more visually appealing: https://weblog.jamisbuck.org/2011/3/4/maze-generation-weave-mazes
- * We will probably be using a 75/25 split (75% of the time it's Newest or Backtracking method and 25% of the time, it's random or Prim)
- * We'll need to ensure navigability in each room similar to the Spelunky method: http://tinysubversions.com/spelunkyGen/
- * We want to ensure a clean "flow" for out monster generation and room types using a "Director AI" like here: https://steamcdn-a.akamaihd.net/apps/valve/2009/ai_systems_of_l4d_mike_booth.pdf
- * Some more details on how that Director AI can work for Metroidvanias: https://www.gamasutra.com/blogs/SebastienBENARD/20170329/294642/Building_the_Level_Design_of_a_procedurally_generated_Metroidvania_a_hybrid_approach.php
- *
- */
- public RoomClass[,] GeneratePath()
- {
- /* This is our "C" */
- List<RoomClass> placedRooms = new List<RoomClass>();
- int count = 0;
- int randX = (int)uRandom.Range(roomMap.GetLowerBound(0), roomMap.GetUpperBound(0));
- int randY = (int)uRandom.Range(roomMap.GetLowerBound(1), roomMap.GetUpperBound(1));
- Vector2 start = new Vector2(randX, randY);
- RoomClass thisRoom = this.roomMap[randX, randY];
- //thisRoom.SetRoomMapPos(start);
- thisRoom.SetVisitedOnGenerateMap(true);
- placedRooms.Add(thisRoom);
- int iterationCount = 0;
- Dictionary<Vector2, RoomClass> roomPath = new Dictionary<Vector2, RoomClass>();
- List<Vector2> unplacedRooms = new List<Vector2>();
- for (int x = 0; x < roomMap.GetUpperBound(0); x++)
- {
- for (int y = 0; y < roomMap.GetUpperBound(1); y++)
- {
- unplacedRooms.Add(new Vector2(x, y));
- }
- }
- Vector2 currentRoom = unplacedRooms[uRandom.Range(0, unplacedRooms.Count())];
- roomPath.Add(currentRoom, roomMap[(int) currentRoom.x, (int) currentRoom.y]);
- unplacedRooms.Remove(currentRoom);
- Vector2[] directions =
- {
- Vector2.up,
- Vector2.down,
- Vector2.left,
- Vector2.right
- };
- Vector2 chosenDirection = Vector2.zero;
- while (true)
- {
- List<Vector2> neighborsChecked = new List<Vector2>();
- foreach (Vector2 thisDirection in directions)
- {
- Vector2 roomChecked = currentRoom + thisDirection;
- if (!roomPath.ContainsKey(roomChecked) && unplacedRooms.Contains(roomChecked)) /* If there is no room in the direction we checked */
- {
- neighborsChecked.Add(roomChecked);
- }
- }
- if (neighborsChecked.Count() == 0)
- {
- break;
- }
- int randomIndex = uRandom.Range(0, neighborsChecked.Count());
- Vector2 nextRoom = neighborsChecked[randomIndex];
- roomPath.Add(nextRoom, roomMap[(int)nextRoom.x, (int)nextRoom.y]);
- unplacedRooms.Remove(nextRoom);
- Vector2 wallToRemove = nextRoom - currentRoom;
- /* Set the current room we're checking from and carve out the wall in the direction we're checking */
- RoomClass currentRoomObject = roomPath[currentRoom];
- RoomType newType = RemoveWallInDirection( currentRoomObject.GetRoomType(), wallToRemove);
- currentRoomObject.SetRoomType(newType);
- /* invert the direction so that we're removing the wall where we came FROM */
- RoomClass nextRoomObject = roomPath[nextRoom];
- wallToRemove *= -1;
- newType = RemoveWallInDirection(nextRoomObject.GetRoomType(), wallToRemove);
- nextRoomObject.SetRoomType(newType);
- /* Draw the rooms immediately to improve debugging */
- currentRoomObject.DrawRoom();
- nextRoomObject.DrawRoom();
- currentRoom = nextRoom;
- if (unplacedRooms.Count() == 0)
- {
- break;
- }
- }
- foreach (Vector2 key in roomPath.Keys)
- {
- RoomClass room = roomPath[key];
- roomMap[(int) room.GetRoomMapPos().x, (int) room.GetRoomMapPos().x] = room;
- }
- //while (placedRooms.Count() > 0 && iterationCount < 1000)
- //{
- // iterationCount++;
- // /* Choose a cell from the list of placed rooms */
- // RoomClass aRoom;
- // /* 75% of the time, we'll use the last room we placed, and 25% of the time we'll grab a random room from the list */
- // if (uRandom.Range(0, 1) < 1.01f)
- // {
- // aRoom = placedRooms[placedRooms.Count - 1];
- // } else {
- // aRoom = placedRooms[(int)uRandom.Range(0, placedRooms.Count() - 1)];
- // }
- // /* turn the by value reference into the actual instantiate game object */
- // //aRoom = aRoom.GetComponent<MonoBehaviour>();
- // int visitedCount = 0;
- // Vector2[] directions =
- // {
- // Vector2.up,
- // Vector2.down,
- // Vector2.left,
- // Vector2.right
- // };
- // //while (directions.Count() > 0)
- // //{
- // // int directionIndex = uRandom.Range(0, directions.Count());
- // // Vector2 thisDirection = directions[directionIndex];
- // // RoomClass checkedRoom = this.getRoomInDirection(aRoom, thisDirection);
- // // bool roomVisited = IsRoomVisited(checkedRoom);
- // // if (roomVisited)
- // // {
- // // visitedCount++;
- // // break;
- // // } else
- // // {
- // // /* Set the current room we're checking from and carve out the wall in the direction we're checking */
- // // Vector2 wallToRemove = thisDirection;
- // // RoomType newType = RemoveWallInDirection(aRoom.GetRoomType(), wallToRemove);
- // // aRoom.SetRoomType(newType);
- // // /* Set the checked room status to "visited" */
- // // checkedRoom.SetVisitedOnGenerateMap(true);
- // // /* invert the direction so that we're removing the wall where we came FROM */
- // // wallToRemove = thisDirection * new Vector2(-1, -1);
- // // newType = RemoveWallInDirection(checkedRoom.GetRoomType(), wallToRemove);
- // // checkedRoom.SetRoomType(newType);
- // // /* Draw the rooms immediately to improve debugging */
- // // aRoom.DrawRoom();
- // // checkedRoom.DrawRoom();
- // // placedRooms.Add(checkedRoom);
- // // break;
- // // }
- // // directions = directions.Where(val => val != thisDirection).ToArray();
- // //}
- // if (visitedCount == 4)
- // {
- // removeFromList(ref placedRooms, aRoom);
- // }
- // RoomClass nextRoom = this.getRoomInDirection(thisRoom, this.directions.GetRandomDirection());
- //}
- print( "Generate Path iterated x times: " + iterationCount);
- print("Ended with " + placedRooms.Count() + " rooms in placedRooms list");
- return roomMap;
- }
- private Vector2 GetStartRoom()
- {
- throw new NotImplementedException();
- }
- public bool IsRoomVisited(RoomClass room)
- {
- if (room == null)
- {
- return true;
- }
- return room.GetVisitedOnGenerateMap();
- }
- public void removeFromList(ref List<RoomClass> list, RoomClass room)
- {
- RoomClass roomToRemove = null;
- foreach (RoomClass thisRoom in list)
- {
- if (thisRoom.GetRoomMapPos() == room.GetRoomMapPos())
- {
- roomToRemove = thisRoom;
- break;
- }
- }
- if (roomToRemove != null)
- {
- list.Remove(roomToRemove);
- }
- }
- public void Update()
- {
- }
- void ChooseStartAndEnd(ref RoomClass startRoom, ref RoomClass exitRoom, int x = xMax, int y = yMax, int paddingX = 0, int paddingY = 0)
- {
- if (paddingX == 0 || paddingY == 0)
- {
- paddingX = (int)this.startEndEmptySpace.x;
- paddingY = (int)this.startEndEmptySpace.y;
- }
- Vector2 quadrant = Vector2.zero;
- if (Mathf.RoundToInt(uRandom.Range(0.0f, 1.0f)) == 0)
- {
- quadrant.x = -1;
- }
- else
- {
- quadrant.x = 1;
- }
- if (Mathf.RoundToInt(uRandom.Range(0.0f, 1.0f)) == 0)
- {
- quadrant.y = -1;
- }
- else
- {
- quadrant.y = 1;
- }
- // Calculate a random position between 0 and half of x, then repeat for y
- Vector2 startPos = new Vector2(Mathf.RoundToInt(uRandom.Range(0, x / 2 - paddingX)), Mathf.RoundToInt(uRandom.Range(0, y / 2 - paddingY)));
- Vector2 endPos = new Vector2(Mathf.RoundToInt(uRandom.Range(0, x / 2 - paddingX)), Mathf.RoundToInt(uRandom.Range(0, y / 2 - paddingY)));
- startTilePos = startPos;
- endTilePos = endPos;
- // Multiply the random position by the Quadrant Vector to get the start position
- startPos *= quadrant;
- // Invert the quadrant vector
- quadrant *= new Vector2(-1, -1);
- // Multiply the new position by the quadrant vector to get the exit.
- endPos *= quadrant;
- startTilePos = WorldPosToTilePos(startPos * new Vector2(16, 16));
- endTilePos = WorldPosToTilePos(endPos * new Vector2(16, 16));
- //player.transform.Translate(TilePosToWorldPos(startTilePos, Utils.worldSpaceOriginVectors.bottomLeft));
- //startRoom.transform.Translate(startPos);
- //startRoom.SetParams(startTilePos, new Vector2(paddingX, paddingY));
- //startRoom.PlaceRoom(ref this.gridArray);
- //exitRoom.transform.Translate(endPos);
- //exitRoom.SetParams(endTilePos, new Vector2(paddingX, paddingY));
- //exitRoom.PlaceRoom(ref this.gridArray);
- }
- public int[,] GenerateArray(int width, int height, bool initEmpty = true)
- {
- bool empty = initEmpty;
- int[,] map = new int[width, height];
- for (int x = 0; x < map.GetUpperBound(0); x++)
- {
- for (int y = 0; y < map.GetUpperBound(1); y++)
- {
- empty = initEmpty;
- //empty = (Mathf.RoundToInt(Random.Range(0.0f, 1.0f)) == 1 ? true : false);
- //// Make sure we are not close to the start, or the exit
- //// Check for player within a certain number of tiles
- //float distToPlayer = Mathf.Abs(Vector2.Distance(TilePosToWorldPos(new Vector2(x, y)), player.transform.position))/16;
- //float distToExit = Mathf.Abs(Vector2.Distance(TilePosToWorldPos(new Vector2(x, y)), exit.transform.position))/16;
- //if (distToPlayer <= startEndEmptySpace || distToExit <= startEndEmptySpace)
- //{
- // empty = true;
- //}
- if (x == map.GetUpperBound(0) - 1 || x == 0)
- {
- empty = false;
- }
- if (y == map.GetUpperBound(1) - 1 || y == 0)
- {
- empty = false;
- }
- if (empty)
- {
- map[x, y] = 0;
- }
- else
- {
- map[x, y] = 1;
- }
- }
- }
- return map;
- }
- public int[,] RadiusCleanMap(int[,] map, Vector2 pos, int radius)
- {
- for (int x = 0; x < map.GetUpperBound(0); x++)
- {
- for (int y = 0; y < map.GetUpperBound(1); y++)
- {
- int distance = Mathf.RoundToInt(Mathf.Abs(Vector2.Distance(TilePosToWorldPos(new Vector2(x, y), Utils.worldSpaceOriginVectors.center), pos)) / 16);
- if (distance <= radius)
- {
- map[x, y] = 0; // 0 = empty position. No tile
- }
- // If it's an outside edge, don't remove it
- if (x == map.GetUpperBound(0) - 1 || x == 0)
- {
- map[x, y] = 1; // 1 = tile
- }
- if (y == map.GetUpperBound(1) - 1 || y == 0)
- {
- map[x, y] = 1; // 1 = tile
- }
- }
- }
- return map;
- }
- public int[,] SquareCleanMap(ref int[,] map, Vector2 pos, int sizeX, int sizeY, bool useTile = false)
- {
- if (!useTile)
- {
- pos = WorldPosToTilePos(pos);
- }
- int startX = (int)Mathf.Floor(pos.x);
- int startY = (int)Mathf.Floor(pos.y);
- int stopX = (int)Mathf.Floor(pos.x + sizeX);
- int stopY = (int)Mathf.Floor(pos.y + sizeY);
- // Iterate from posX to posX + sizeX
- for (int x = startX; x <= stopX; x++)
- {
- // Iterate from posX to posX + sizeY
- for (int y = startY; y <= stopY; y++)
- {
- // Clean that space
- map[x, y] = 0;
- // If it's an outside edge, put it back
- if (x == map.GetUpperBound(0) - 1 || x == 0)
- {
- map[x, y] = 1; // 1 = tile
- }
- if (y == map.GetUpperBound(1) - 1 || y == 0)
- {
- map[x, y] = 1; // 1 = tile
- }
- }
- }
- return map;
- }
- public static Vector2 WorldPosToTilePos(Vector2 vector)
- {
- int thisX = Mathf.RoundToInt(vector.x / 16 + (xMax / 2));
- int thisY = Mathf.RoundToInt(vector.y / 16 + (yMax / 2));
- return new Vector2(thisX, thisY);
- }
- // 0,0 = 50%, 50%
- public static Vector2 TilePosToWorldPos(Vector2 vector, Vector2 worldSpaceOrigin)
- {
- int thisX = Mathf.RoundToInt((vector.x) - (xMax / 2));
- int thisY = Mathf.RoundToInt((vector.y) - (yMax / 2));
- int returnX = thisX * 16;
- int returnY = thisY * 16;
- return new Vector2(returnX, returnY) + (8 * worldSpaceOrigin);
- }
- public bool CanPlaceRoom(int[,] map, Vector2 pos, int sizeX, int sizeY, int padding = 1)
- {
- int minX = Mathf.Clamp(Mathf.FloorToInt(pos.x - Mathf.CeilToInt(sizeX / 2)) - padding, 0, map.GetUpperBound(0));
- int minY = Mathf.Clamp(Mathf.FloorToInt(pos.y - Mathf.CeilToInt(sizeY / 2)) - padding, 0, map.GetUpperBound(1));
- int maxX = Mathf.Clamp(Mathf.CeilToInt(pos.x + Mathf.CeilToInt(sizeX / 2)) + padding, 0, map.GetUpperBound(0));
- int maxY = Mathf.Clamp(Mathf.CeilToInt(pos.y + Mathf.CeilToInt(sizeY / 2)) + padding, 0, map.GetUpperBound(1));
- for (int x = minX; x < maxX; x++)
- {
- for (int y = minY; y < maxY; y++)
- {
- int tmp = map[x, y];
- if (tmp == 0 /* This is empty space, so there's a room or hallway here */)
- {
- return false;
- }
- }
- }
- // <= This point
- return true;
- }
- public static void RenderMap(int[,] map, Tilemap tilemap, TileBase tile)
- {
- int halfX = map.GetUpperBound(0) / 2;
- int halfY = map.GetUpperBound(1) / 2;
- //Clear the map (ensures we dont overlap)
- tilemap.ClearAllTiles();
- //Loop through the width of the map
- for (int x = 0; x < map.GetUpperBound(0); x++)
- {
- //Loop through the height of the map
- for (int y = 0; y < map.GetUpperBound(1); y++)
- {
- // 1 = tile, 0 = no tile
- if (map[x, y] == 1)
- {
- tilemap.SetTile(new Vector3Int(Mathf.RoundToInt(x - halfX), Mathf.RoundToInt(y - halfY), 0), tile);
- }
- }
- }
- }
- public RoomClass getRoomInDirection(RoomClass room, Vector2 direction)
- {
- RoomClass empty = null;
- /* return an empty Vector2 if there is no room in that direction */
- if ( room.GetRoomMapPos().x + direction.x > this.roomMap.GetUpperBound(0) || room.GetRoomMapPos().x + direction.x < this.roomMap.GetLowerBound(0)
- || room.GetRoomMapPos().y + direction.y > this.roomMap.GetUpperBound(1) || room.GetRoomMapPos().y + direction.y < this.roomMap.GetLowerBound(1) )
- {
- return empty;
- }
- Vector2 expectedRoomPos = room.GetRoomMapPos() + direction;
- /* Perform a check to see if a room with that position already exists on the room map */
- foreach (RoomClass thisRoom in this.roomMap)
- {
- if (thisRoom.GetRoomMapPos() == expectedRoomPos)
- {
- return thisRoom;
- }
- }
- /* Since each position in the roomsMap is prefilled with a new RoomClass,
- * there is no scenario where we shouldn't return a room.
- */
- return null;
- }
- public struct RelativeNeighbors
- {
- public Vector2 Up, Down, Left, Right;
- public Func<Vector2> GetRandomDirection;
- }
- public Vector2 GetDirectionByIndex(int index)
- {
- switch (index)
- {
- case 0:
- return directions.Up;
- break;
- case 1:
- return directions.Down;
- break;
- case 2:
- return directions.Left;
- break;
- case 3:
- return directions.Right;
- break;
- default:
- break;
- }
- return Vector2.zero;
- }
- public RoomType SetRoomType(RoomType[,] map, Vector2 roomPos, Vector2 direction)
- {
- RoomType currentRoomType = map[(int)roomPos.x, (int)roomPos.y];
- RoomType newRoom = RemoveWallInDirection(currentRoomType, direction);
- return newRoom;
- }
- public RoomType RemoveWallInDirection(RoomType type, Vector2 direction)
- {
- /* Assuming the type value is the current room type, try to knock a wall down in direction and return a new room type */
- switch (type)
- {
- case RoomType.OPEN_ALL:
- return RoomType.OPEN_ALL;
- break;
- case RoomType.OPEN_N:
- switch (direction.x)
- {
- case 0:
- switch (direction.y)
- {
- case -1:
- return RoomType.OPEN_E_W;
- break;
- case 1:
- return type;
- break;
- default:
- break;
- }
- break;
- case 1:
- return RoomType.OPEN_N_E;
- break;
- case -1:
- return RoomType.OPEN_N_W;
- break;
- default:
- break;
- }
- break;
- case RoomType.OPEN_E:
- switch (direction.x)
- {
- case 0:
- switch (direction.y)
- {
- case -1:
- return RoomType.OPEN_E_S;
- break;
- case 1:
- return RoomType.OPEN_N_E;
- break;
- default:
- break;
- }
- break;
- case 1:
- return type;
- break;
- case -1:
- return RoomType.OPEN_E_W;
- break;
- default:
- break;
- }
- break;
- case RoomType.OPEN_S:
- switch (direction.x)
- {
- case 0:
- switch (direction.y)
- {
- case -1:
- return type;
- break;
- case 1:
- return RoomType.OPEN_N_S;
- break;
- default:
- break;
- }
- break;
- case 1:
- return RoomType.OPEN_E_S;
- break;
- case -1:
- return RoomType.OPEN_S_W;
- break;
- default:
- break;
- }
- break;
- case RoomType.OPEN_W:
- switch (direction.x)
- {
- case 0:
- switch (direction.y)
- {
- case -1:
- return RoomType.OPEN_S_W;
- break;
- case 1:
- return RoomType.OPEN_N_W;
- break;
- default:
- break;
- }
- break;
- case 1:
- return RoomType.OPEN_E_W;
- break;
- case -1:
- return type;
- break;
- default:
- break;
- }
- break;
- case RoomType.OPEN_N_E:
- switch (direction.x)
- {
- case 0:
- switch (direction.y)
- {
- case -1:
- return RoomType.CLOSED_W;
- break;
- case 1:
- return type;
- break;
- default:
- break;
- }
- break;
- case 1:
- return type;
- break;
- case -1:
- return RoomType.CLOSED_S;
- break;
- default:
- break;
- }
- break;
- case RoomType.OPEN_N_S:
- switch (direction.x)
- {
- case 0:
- return type;
- break;
- case 1:
- return RoomType.CLOSED_W;
- break;
- case -1:
- return RoomType.CLOSED_E;
- break;
- default:
- break;
- }
- break;
- case RoomType.OPEN_N_W:
- switch (direction.x)
- {
- case 0:
- switch (direction.y)
- {
- case -1:
- return RoomType.CLOSED_E;
- break;
- case 1:
- return type;
- break;
- default:
- break;
- }
- break;
- case 1:
- return RoomType.CLOSED_S;
- break;
- case -1:
- return type;
- break;
- default:
- break;
- }
- break;
- case RoomType.OPEN_E_S:
- switch (direction.x)
- {
- case 0:
- switch (direction.y)
- {
- case -1:
- return type;
- break;
- case 1:
- return RoomType.CLOSED_W;
- break;
- default:
- break;
- }
- break;
- case 1:
- return type;
- break;
- case -1:
- return RoomType.CLOSED_N;
- break;
- default:
- break;
- }
- break;
- case RoomType.OPEN_E_W:
- if (direction.x == 0)
- {
- switch (direction.y)
- {
- case -1:
- return RoomType.CLOSED_N;
- break;
- case 1:
- return RoomType.CLOSED_S;
- break;
- default:
- break;
- }
- }else
- {
- return type;
- }
- break;
- case RoomType.OPEN_S_W:
- switch (direction.x)
- {
- case 0:
- switch (direction.y)
- {
- case -1:
- return type;
- break;
- case 1:
- return RoomType.CLOSED_E;
- break;
- default:
- break;
- }
- break;
- case 1:
- return RoomType.CLOSED_N;
- break;
- case -1:
- return type;
- break;
- default:
- break;
- }
- break;
- case RoomType.CLOSED_N:
- if (direction.y == 1)
- {
- return RoomType.OPEN_ALL;
- }
- break;
- case RoomType.CLOSED_S:
- if (direction.y == -1)
- {
- return RoomType.OPEN_ALL;
- }
- break;
- case RoomType.CLOSED_E:
- if (direction.x == 1)
- {
- return RoomType.OPEN_ALL;
- }
- break;
- case RoomType.CLOSED_W:
- if (direction.x == -1)
- {
- return RoomType.OPEN_ALL;
- }
- break;
- case RoomType.CLOSED_ALL:
- switch (direction.x)
- {
- case 0:
- switch (direction.y)
- {
- case -1:
- return RoomType.OPEN_S;
- break;
- case 1:
- return RoomType.OPEN_N;
- break;
- default:
- break;
- }
- break;
- case 1:
- return RoomType.OPEN_E;
- break;
- case -1:
- return RoomType.OPEN_W;
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- return RoomType.CLOSED_ALL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement