static void BuildLevel() { int num = 0; for (int y = 0; y < inputTexture.height; y++) { for (int x = 0; x < inputTexture.width; x++) { num = inputTexture.width * y + x; //Build walls if (pix [num] == Color.blue) { tempBlock = inputTexture.GetPixels(x - 1, y - 1, 3, 3); wallType = DetermineType(); wallRot = DetermineRotation(); PlaceWall(x, y, wallType, wallRot); } else if (pix [num] == Color.green) { tempBlock = inputTexture.GetPixels(x - 1, y - 1, 3, 3); PlaceLight(x, y); } } } /* for (int i = 0; i < inputTexture.height; i++) { StartCoroutine(TestPixels(i)); } */ //Place floor PlaceFloor(); }
public void ToggleWall(WallTypes wall, bool toggle) { switch (wall) { case WallTypes.Center: wallCenter.SetActive(toggle); break; case WallTypes.North: wallNorth.SetActive(toggle); break; case WallTypes.South: wallSouth.SetActive(toggle); break; case WallTypes.East: wallEast.SetActive(toggle); break; case WallTypes.West: wallWest.SetActive(toggle); break; default: break; } }
public Wall CreateWall(WallTypes type, string title) { WallType wallType = dbContext.WallTypes.Where(wt => wt.Title == type.ToString()).First(); Wall wall = new Wall() { Title = title, WallType = wallType }; return(wall); }
public void handleSpeed(WallTypes wallType) { switch (wallType) { case WallTypes.Side: this.currentSpeed.x = -this.currentSpeed.x; break; case WallTypes.Upper: this.currentSpeed.y = -this.currentSpeed.y; break; } }
// Spawn the wall private void InstantiateWall(WallTypes wallType, Vector3 position, Quaternion rotation) { // Check there isn't already a wall there if (!placedWalls.Contains(position)) { // Instantiate the wall, and add it to the list GameObject wall = Instantiate(roomWalls[(int)wallType], position, rotation); placedWalls.Add(position); // If it is a door wall, isolate the Door object and add it to the list of doors if (wallType == WallTypes.DOOR) { Door[] doors = wall.GetComponentsInChildren <Door>(); currentDoors.AddRange(doors.ToList()); } } }
public Wall(ContentManager content, Vector2 position, bool health, WallTypes wallType, double velocity, Vector2 scale) : base(content, position, health, velocity, scale) { this.WallType = wallType; if (wallType == WallTypes.Unbreakable) { this.CurrentAnimationKey = UNBREAKABLE_ANIMATION_KEY; this.Scale = scale * 0.15f; } else { this.CurrentAnimationKey = BREAKABLE_ANIMATION_KEY; this.Scale = scale * 0.50f; } this.CreateAnimations(content); }
public GameObject CreateWall(WallTypes type, Transform parent, Vector3 position, Quaternion rotation) { GameObject wall = null; if (walls.Length > 0) { wall = SearchResource(walls, (int)type, maxWallIndex); if (wall) { wall.transform.parent = parent; wall.transform.localPosition = position; wall.transform.localRotation = rotation; } } return(wall); }
private void GenerateWalls(Transform roomTrans) { // Array to hold this room's four wall types WallTypes[] walls = new WallTypes[4]; hasDoors = false; // 2. For each wall, determine if [open], [closed], [door] for (int index = 0; index < walls.Length; index++) { // First wall values correspond to indices in roomWalls. Last is a special number to identify when there is no wall walls[index] = (WallTypes)Random.Range(0, 3); if (walls[index] == WallTypes.DOOR) { if (roomCount >= maxRooms) { walls[index] = WallTypes.BLANK; } hasDoors = true; } } // 3. Place associated walls (none for [open]) Vector3 wallPos = roomTrans.position; ////////////////////// // The four compass directions (-X, +X, -Z, +Z) are the same, so only first commented ////////////////////// // Left wall (-X) // If target position already filled if (placedRooms.Contains(roomTrans.position + (-roomTrans.right * 20.0f))) { Debug.Log("Room to -X"); } // If target position reserved for another room else if (reservedRooms.Contains(roomTrans.position + (-roomTrans.right * 20.0f))) { InstantiateWall(WallTypes.BLANK, roomTrans.position + (-roomTrans.right * 9.5f), Quaternion.identity); } // If target position available! else { // Individual wall logic switch (walls[0]) { // Spawn blank wall case WallTypes.BLANK: InstantiateWall(WallTypes.BLANK, roomTrans.position + (-roomTrans.right * 9.5f), Quaternion.identity); break; // Spawn a door and reserve the target beyond it for another room case WallTypes.DOOR: InstantiateWall(WallTypes.DOOR, roomTrans.position + (-roomTrans.right * 9.5f), Quaternion.identity); reservedRooms.Push(roomTrans.position + (-roomTrans.right * 20.0f)); break; // Leave a space, this room will be expanded case WallTypes.NONE: if (stackRoomCount > 0) { // Add a room to process in -X direction Vector3 pos = roomTrans.position; pos += (-roomTrans.right * 20.0f); // Add room beyond empty wall as next to generate, then decrease available stack roomsToDo.Push(pos); stackRoomCount--; } // Unless there is no space to expand -- close off the room else { InstantiateWall(WallTypes.BLANK, roomTrans.position + (-roomTrans.right * 9.5f), Quaternion.identity); } break; default: Debug.Log("========NO WALL========"); break; } } // Right wall (+X) // If target position already filled if (placedRooms.Contains(roomTrans.position + (roomTrans.right * 20.0f))) { Debug.Log("Room to +X"); } // If target position reserved for another room else if (reservedRooms.Contains(roomTrans.position + (roomTrans.right * 20.0f))) { InstantiateWall(WallTypes.BLANK, roomTrans.position + (roomTrans.right * 9.5f), Quaternion.identity); } // If target position available! else { // Individual wall logic switch (walls[1]) { // Spawn blank wall case WallTypes.BLANK: InstantiateWall(WallTypes.BLANK, roomTrans.position + (roomTrans.right * 9.5f), Quaternion.identity); break; // Spawn a door and reserve the target beyond it for another room case WallTypes.DOOR: InstantiateWall(WallTypes.DOOR, roomTrans.position + (roomTrans.right * 9.5f), Quaternion.identity); reservedRooms.Push(roomTrans.position + (roomTrans.right * 20.0f)); break; // Leave a space, this room will be expanded case WallTypes.NONE: if (stackRoomCount > 0) { // Add a room to process in +X direction Vector3 pos = roomTrans.position; pos += (roomTrans.right * 20.0f); // Add room beyond empty wall as next to generate, then decrease available stack roomsToDo.Push(pos); stackRoomCount--; } // Unless there is no space to expand -- close off the room else { InstantiateWall(WallTypes.BLANK, roomTrans.position + (roomTrans.right * 9.5f), Quaternion.identity); } break; default: Debug.Log("========NO WALL========"); break; } } // Back wall (-Z) // If target position already filled if (placedRooms.Contains(roomTrans.position + (-roomTrans.forward * 20.0f))) { Debug.Log("Room to -Z"); } // If target position reserved for another room else if (reservedRooms.Contains(roomTrans.position + (-roomTrans.forward * 20.0f))) { InstantiateWall(WallTypes.BLANK, roomTrans.position + (-roomTrans.forward * 9.5f), Quaternion.Euler(0.0f, 90.0f, 0.0f)); } // If target position available! else { // Individual wall logic switch (walls[2]) { // Spawn blank wall case WallTypes.BLANK: InstantiateWall(WallTypes.BLANK, roomTrans.position + (-roomTrans.forward * 9.5f), Quaternion.Euler(0.0f, 90.0f, 0.0f)); break; // Spawn a door and reserve the target beyond it for another room case WallTypes.DOOR: InstantiateWall(WallTypes.DOOR, roomTrans.position + (-roomTrans.forward * 9.5f), Quaternion.Euler(0.0f, 90.0f, 0.0f)); reservedRooms.Push(roomTrans.position + (-roomTrans.forward * 20.0f)); break; // Leave a space, this room will be expanded case WallTypes.NONE: if (stackRoomCount > 0) { // Add a room to process in +X direction Vector3 pos = roomTrans.position; pos += (-roomTrans.forward * 20.0f); // Add room beyond empty wall as next to generate, then decrease available stack roomsToDo.Push(pos); stackRoomCount--; } // Unless there is no space to expand -- close off the room else { InstantiateWall(WallTypes.BLANK, roomTrans.position + (-roomTrans.forward * 9.5f), Quaternion.Euler(0.0f, 90.0f, 0.0f)); } break; default: Debug.Log("========NO WALL========"); break; } } // Front wall (+Z) // If target position already filled if (placedRooms.Contains(roomTrans.position + (roomTrans.forward * 20.0f))) { Debug.Log("Room to +Z"); } // If target position reserved for another room else if (reservedRooms.Contains(roomTrans.position + (-roomTrans.right * 20.0f))) { InstantiateWall(WallTypes.BLANK, roomTrans.position + (roomTrans.forward * 9.5f), Quaternion.Euler(0.0f, 90.0f, 0.0f)); } // If target position available! else { // Individual wall logic switch (walls[3]) { // Spawn blank wall case WallTypes.BLANK: InstantiateWall(WallTypes.BLANK, roomTrans.position + (roomTrans.forward * 9.5f), Quaternion.Euler(0.0f, 90.0f, 0.0f)); break; // Spawn a door and reserve the target beyond it for another room case WallTypes.DOOR: InstantiateWall(WallTypes.DOOR, roomTrans.position + (roomTrans.forward * 9.5f), Quaternion.Euler(0.0f, 90.0f, 0.0f)); reservedRooms.Push(roomTrans.position + (roomTrans.forward * 20.0f)); break; // Leave a space, this room will be expanded case WallTypes.NONE: if (stackRoomCount > 0) { // Add a room to process in +X direction Vector3 pos = roomTrans.position; pos += (roomTrans.forward * 20.0f); // Add room beyond empty wall as next to generate, then decrease available stack roomsToDo.Push(pos); stackRoomCount--; } // Unless there is no space to expand -- close off the room else { InstantiateWall(WallTypes.BLANK, roomTrans.position + (roomTrans.forward * 9.5f), Quaternion.Euler(0.0f, 90.0f, 0.0f)); } break; default: Debug.Log("========NO WALL========"); break; } } // Determine if this room is the room with the goal - 80% chance it is not if (Random.value > 0.8f && !hasEnd && canSpawnEnemies) { Vector3 endRoom = roomTrans.position; endRoom.y += 10.0f; LevelSwitcher ls = Instantiate(levelEnd, endRoom, Quaternion.identity); ls.TheEnd = true; hasEnd = true; } // Add placed room to list of placed room placedRooms.Add(roomTrans.position); }
/* IEnumerator TestPixels(int y) { for (int x = 0; x < inputTexture.width; x ++) { int num = inputTexture.height * y + x; //Build walls if (IsColor(pix [num], Color.blue)) { wallType = DetermineType(x, y); wallRot = DetermineRotation(x, y); PlaceWall(x, y, wallType, wallRot); } else if (IsColor(pix [num], Color.yellow)) { PlaceLight(x, y); } } return; } */ static void PlaceWall(int xPos, int zPos, WallTypes type, int rot) { Quaternion rotation = Quaternion.Euler(new Vector3 (0, 90 * rot, 0)); string prefab = "Empty"; if (type == WallTypes.WALL) { prefab = "Wall_" + Random.Range(1, 4); } else if (type == WallTypes.CORNER_INNER) { prefab = "Wall_CornerInner"; } else if (type == WallTypes.CORNER_OUTER) { prefab = "Wall_CornerOuter"; } else { prefab = "ErrorCube"; } GameObject wall = (GameObject)PrefabUtility.InstantiatePrefab(Resources.Load("Prefabs/Environment/" + prefab) as GameObject); Undo.RegisterCreatedObjectUndo(wall, "Undo Level insert"); if (GameObject.Find("GeneratedLevel") != null) { wall.transform.parent = GameObject.Find("GeneratedLevel").transform; } wall.transform.position = new Vector3 (xPos, 0, zPos); wall.transform.rotation = rotation; }