public RoomDebugInfo GetRoomDebugInfo() { var debugInfo = new RoomDebugInfo(); debugInfo.State = state.ToString(); debugInfo.HallRoomId = hallRoom == null ? 0 : hallRoom.HallRoomId; debugInfo.RoomId = RoomId.Id; return(debugInfo); }
private void InitialGenerate() { rooms = new HashSet <Room>(); CoordGameObjectMap = new Dictionary <Coord, GameObject>(); exploredArea = new HashSet <Coord>(); if (useRandomSeed) { seed = (int)Network.time; } rand = new Random(seed); for (int i = 0; i < initRoomAttempts; i++) { int startX = NextRandomOdd(-areaAroundPlayerX / 2, areaAroundPlayerX / 2); int startY = NextRandomOdd(-areaAroundPlayerY / 2, areaAroundPlayerY / 2); int sizeX = NextRandomOdd(minRoomSize, maxRoomSize); int sizeY = NextRandomOdd(minRoomSize, maxRoomSize); Room room = new Room(startX, startY, sizeX, sizeY); bool roomValid = CheckRoomValid(room); if (roomValid) { rooms.Add(room); } } for (int x = -areaAroundPlayerX / 2; x < areaAroundPlayerX / 2; x++) { for (int y = -areaAroundPlayerY / 2; y < areaAroundPlayerY / 2; y++) { Coord c = new Coord(x, y); GameObject prefab = GetPrefabForCoord(c); GameObject obj = Instantiate(prefab, new Vector3(x, y), Quaternion.identity, this.transform); obj.name = prefab.name + " " + x + " " + y; RoomDebugInfo debug = obj.GetComponent <RoomDebugInfo>(); if (debug != null) { Room r; IsInRoom(x, y, out r); debug.Room = r; } CoordGameObjectMap.Add(new Coord(x, y), obj); exploredArea.Add(c); } } }
// TODO: This function needs to be greatly optimized. private void PlayerController_OnPlayerMove(int h, int v, Coord PlayerPosition) { // Make sure that the h and v values are good CheckHVValues(h, v); // This represents the new total area to display. We will disable everything, then turn on the gameobjects inside this //Rect area = new Rect( // PlayerPosition.x - areaAroundPlayerX / 2, // PlayerPosition.y - areaAroundPlayerY / 2, // PlayerPosition.x + areaAroundPlayerX / 2, // PlayerPosition.y + areaAroundPlayerY / 2 // ); Rect area = new Rect(PlayerPosition.x - areaAroundPlayerX / 2, PlayerPosition.y - areaAroundPlayerY / 2, 0, 0); area.End = new Coord(PlayerPosition.x + areaAroundPlayerX / 2, PlayerPosition.y + areaAroundPlayerY / 2); //Debug.Log(area); /* We need to know the players position * The players position is never recorded. * It can be calculated based on the unity transform component * but this is hackish * the player could keep a coord value as its position * But this is extra bookkeeping and requires passing around another value * I think the second is the better solution. I'll see what I think in the morning */ // Disable the gameobjects that shouldn't be rendered foreach (KeyValuePair <Coord, GameObject> kvp in CoordGameObjectMap) { if (area.Contains(kvp.Key) == false) { kvp.Value.SetActive(false); } } // TODO: A lot of duplicated code between this and Initial Generate // For each tile that should be rendered... for (int x = area.start.x; x < area.End.x; x++) { for (int y = area.start.y; y < area.End.y; y++) { Coord c = new Coord(x, y); // If this earea hasn't been explored, give it the chance to create a new room if (exploredArea.Contains(c) == false) { // make sure this is odd. even tiles are reserved for walls. if (c.x % 2 != 0 && c.y % 2 != 0) { // newRoomProb * 100 % of the time, add a room if (rand.NextDouble() < newRoomProb) { int startX = c.x; int startY = c.y; // chose the size. odd for the same reason start is odd int sizeX = NextRandomOdd(minRoomSize, maxRoomSize); int sizeY = NextRandomOdd(minRoomSize, maxRoomSize); Room room = new Room(startX, startY, sizeX, sizeY); // make sure this room doesn't intersect any other room bool roomValid = CheckRoomValid(room); if (roomValid) { // add to the rooms list (set) rooms.Add(room); // destroy the gameobject for all of the tiles in the rooms. they will be remade later with the correct graphics for (int i = room.start.x; i < room.End.x; i++) { for (int j = room.start.y; j < room.End.y; j++) { Coord c2 = new Coord(i, j); if (CoordGameObjectMap.ContainsKey(c2)) { GameObject obj = CoordGameObjectMap[c2]; Destroy(obj); CoordGameObjectMap.Remove(c2); } } } } } } exploredArea.Add(c); } //...either enable the gameobject OR create a new one if (CoordGameObjectMap.ContainsKey(c)) { CoordGameObjectMap[c].SetActive(true); } else { GameObject prefab = GetPrefabForCoord(c); GameObject obj = Instantiate(prefab, new Vector3(x, y), Quaternion.identity, this.transform); obj.name = prefab.name + " " + x + " " + y; RoomDebugInfo debug = obj.GetComponent <RoomDebugInfo>(); if (debug != null) { Room r; IsInRoom(x, y, out r); debug.Room = r; } CoordGameObjectMap.Add(c, obj); } } } }