public IEnumerator Move(MazeCell cell) { isMoving = true; Vector3 startPosition = transform.position; Vector3 endPosition = cell.transform.localPosition; float step = Speed * Time.deltaTime; Vector3 targetDir = endPosition - startPosition; float t = 0; while (t < 1f) { t += Time.deltaTime * Speed; Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, t, 0f); transform.position = Vector3.Lerp(startPosition, endPosition, t); transform.rotation = Quaternion.LookRotation(newDir); yield return(null); } isMoving = false; currentCell = cell; room = currentCell.room; if (room != player.GetComponent <Player>().GetLocation().room) { isHidden = true; } else { isHidden = false; } yield return(0); }
public void Assimilate(MazeRoom room) { for (int i = 0; i < room.cells.Count; i++) { Add(room.cells[i]); } }
public void Initialize(MazeRoom room) { if (FindObjectOfType <Maze>().doorProbability != 0) { room.Add(this); } }
private IEnumerator GenerateEnemiesInRoom(MazeRoom room, int number) { int enemiesGenerated = 0; List <MazeCell> activeCells = new List <MazeCell>(room.Cells); while (enemiesGenerated < number) { if (enemies.Count % 10 == 0) { yield return(false); } if (activeCells.Count == 0) { break; } MazeCell randCell = activeCells[Random.Range(0, activeCells.Count)]; activeCells.Remove(randCell); if (randCell.IsFree) { randCell.RegisterEntity(); GameObject enemy = GameObject.Instantiate(enemiesPrefabs[Random.Range(0, enemiesPrefabs.Length)]) as GameObject; enemy.transform.parent = transform; enemy.transform.localPosition = new Vector3(randCell.coordinates.x - size.x * 0.5f + 0.5f, transform.position.y + 1.0f, randCell.coordinates.z - size.z * 0.5f + 0.5f); enemiesGenerated++; enemies.Add(enemy); } } }
// Used when maze is built to receive data about current room public void OnMazeUpdate(MazeRoom room) { // Add a guard int guardIndex = Random.Range(0, guards.Length); GuardType newGuard = guards[guardIndex]; int count = Random.Range(newGuard.minCount, newGuard.maxCount); // start from Random(0, maxCount-count) Vector3 startPosition = newGuard.minPosition + newGuard.step * Random.Range(0, newGuard.maxCount - count); for (int i = 0; i < count; i++) { Vector3 localPosition = startPosition + newGuard.step * i; GameObject go = (GameObject)Instantiate(newGuard.prefab, Vector3.zero, Quaternion.identity); go.transform.parent = room.roomObject.transform; go.transform.localPosition = localPosition; // Update patrol points from start position (take 0 as reference point) Guard g = go.GetComponent <Guard>(); for (int p = 0; p < g.patrol.Length; p++) { // substract position to patrol waypoint g.patrol[p].position -= localPosition; // modify speed a little float speedFactor = Random.Range(0.8f, 1.6f); g.patrol[p].speedToReach *= speedFactor; // adap sprite animation fps to speed (we know that's the animation at index 1, ugly hard coded thing...) g.spriteAnimation.animationList[1].fps *= speedFactor; } } }
private void CreateStartAndEnd() { startPrefab = Resources.Load <GameObject>("StartNode"); startRoom = mapGenerator.GetStartRoom(); MazeNode startNode = mapGenerator.GetRandomEmptyNodeCloseToCenter(startRoom); mapGenerator.GetEmptyRoomNodes(startRoom).ForEach(node => { node.Image.sprite = depthConfig.StartRoomSprite; node.Image.color = depthConfig.StartRoomSpriteColor; }); startObject = Instantiate(startPrefab, transform); startObject.transform.localScale = mapGenerator.GetScaled(Vector3.one); startObject.transform.position = mapGenerator.GetScaled(startNode.Rect.position); endRoom = mapGenerator.GetEndRoom(); MazeNode endNode = mapGenerator.GetRandomEmptyNodeCloseToCenter(endRoom); mapGenerator.GetEmptyRoomNodes(endRoom).ForEach(node => { node.Image.sprite = depthConfig.EndRoomSprite; node.Image.color = depthConfig.EndRoomSpriteColor; }); SpawnEndAt(mapGenerator.GetScaled(endNode.Rect.position)); }
protected void chooseStartLocation(SimpleAgent a) { MazeRoom r = laby.rooms [Random.Range(0, laby.rooms.Count)]; MazeCell c = r.cells [Random.Range(0, r.cells.Count)]; a.transform.localPosition = new Vector3(c.transform.position.x, 52f, c.transform.position.z); }
public void Assimilate(MazeRoom room) { for(int i=0; i<room.cells.Count; i++) { Add(room.cells[i]); } }
public MazeNode GetRandomEmptyNode(MazeRoom room) { List <MazeNode> emptyNodes = GetEmptyRoomNodes(room); int randomIndex = Random.Range(0, emptyNodes.Count); return(emptyNodes[randomIndex]); }
// creates a new room private MazeRoom CreateRoom(int roomType) { MazeRoom newRoom = ScriptableObject.CreateInstance <MazeRoom>(); newRoom.settingsIndex = roomTypeCount; // reserve last room setting type for puzzle rooms if (roomTypeCount < roomSettings.Length - 2) { roomTypeCount += 1; } else { roomTypeCount = 0; } // exclude creating rooms of a certain roomType if (newRoom.settingsIndex == roomType) { if (newRoom.settingsIndex < roomSettings.Length - 2) { newRoom.settingsIndex = newRoom.settingsIndex + 1; } else { newRoom.settingsIndex = newRoom.settingsIndex - 1; } } newRoom.roomSettings = roomSettings[newRoom.settingsIndex]; rooms.Add(newRoom); return(newRoom); }
public void Merge(MazeRoom otherRoom) { foreach (MazeCell cell in otherRoom.cells) { AddCell(cell); } }
public void Initialize(MazeRoom room) { room.Add(this); floorRenderer = transform.GetChild(0).GetComponent <Renderer>(); floorRenderer.material = room.settings.floorMaterial; currentColor = room.settings.floorMaterial.color; }
public void Assimlate(MazeRoom Room) { for (int i = 0; i < Room.cells.Count; i++) { Add(Room.cells[i]); } }
private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction) { MazePassage prefab = Random.value < doorProbability ? doorPrefab : passagePrefab; MazePassage passage = Instantiate(prefab) as MazePassage; passage.Initialize(cell, otherCell, direction); //passage = Instantiate(prefab) as MazePassage; if (cell.room != otherCell.room && otherCell.room != null) { MazeRoom roomToAssimilate = otherCell.room; cell.room.Assimilate(roomToAssimilate); rooms.Remove(roomToAssimilate); Destroy(roomToAssimilate); } if (passage is MazeDoor) { otherCell.Initialize(CreateRoom(cell.room.settingsIndex)); } else { otherCell.Initialize(cell.room); } passage.Initialize(otherCell, cell, direction.GetOpposite()); }
private void OnTriggerExit(Collider other) { if (other.tag == "minigame") { currentGame.endGame(); currentGame = null; } else if (other.tag == "roomChange" && gameManager.generateCeilings) { MazeRoom otherRoom = other.gameObject.GetComponentInParent <MazeCell>().room; if (otherRoom != currentRoom) { gameManager.activeRooms.Add(otherRoom); gameManager.activeRooms.Remove(currentRoom); if (!gameManager.activeRooms.Contains(currentRoom)) { currentRoom.ceiling.GetComponent <Ceiling>().fadeIn = true; currentRoom.ceiling.GetComponent <Ceiling>().fadeOut = false; otherRoom.ceiling.GetComponent <Ceiling>().fadeOut = true; otherRoom.ceiling.GetComponent <Ceiling>().fadeIn = false; } else { otherRoom.ceiling.GetComponent <Ceiling>().fadeOut = true; otherRoom.ceiling.GetComponent <Ceiling>().fadeIn = false; } currentRoom = otherRoom; } } }
public void LoadBaseLevel() { loading = true; MazeRoom mainRoom = new MazeRoom(new Rect(5, 5, 11, 11)); LevelDepthConfig depthConfig = generalLevelConfig.GetLevelDepthConfiguration(-1); LevelConfig levelConfig = Resources.Load <LevelConfig>("LevelConfigs/base"); levelConfig.Randomize(); MapGenerator.Initialize(levelConfig, depthConfig, ReadyWithBase); //MazeCarver carver = mapGenerator.InitializeCarver(worldRect, mapGenerator, levelConfig, depthConfig); MazeCarver carver = MapGenerator.InitializeCarver(); MapGenerator.PlaceRoom(mainRoom); carver.FillWithHallway(); //carver.RemoveFalseWalls(); carver.Create3DWalls(); carver.CreateNavMeshes(); mapPopulator = MapGenerator.InitializeMapPopulator(); //mapPopulator.SpawnKeyAt(mapGenerator.GetScaled(new Vector3(10, 10, 0))); SpawnWandAt(new Vector3(9, 9, 0), depthConfig.PowerLevel); SpawnWandAt(new Vector3(7, 9, 0), depthConfig.PowerLevel); SpawnWandAt(new Vector3(9, 7, 0), depthConfig.PowerLevel); Dummy dummyPrefab = Resources.Load <Dummy>("Dummy"); Dummy dummy = Instantiate(dummyPrefab, MapGenerator.transform); dummy.transform.position = MapGenerator.GetScaled(new Vector3(13, 13, 0)); mapPopulator.SpawnEndAt(MapGenerator.GetScaled(new Vector3(10, 10, 0))); player = mapPopulator.SpawnPlayerAt(MapGenerator.GetScaled(new Vector3(7, 7, 0))); mapPopulator.SetUpCamera(player); //fullscreenFade.FadeOut(ReadyWithBase); }
public void Assimilate(MazeRoom room) { foreach (MazeCell c in room.cells) { Add(c); } }
protected void findPath() { // Select a random room MazeRoom r = maze.rooms [Random.Range(0, maze.rooms.Count)]; float randomNumber = Random.Range(0.0f, 1.0f); // Number of total steps int nbSteps = 0; foreach (MazeCell c in r.cells) { nbSteps += c.playerStepsCounter + 1; } // Look for the cell to go to float cpt = 0.0f; foreach (MazeCell c in r.cells) { if (randomNumber >= cpt && randomNumber <= cpt + ((c.playerStepsCounter + 1) * 1.0f / nbSteps)) { walkingTarget = c; break; } cpt += (c.playerStepsCounter + 1) * 1.0f / nbSteps; } //walkingTarget = c; state = STATES.WALKING; }
// Used when maze is built to receive data about current room public void OnMazeUpdate(MazeRoom room) { if (firstRoom == null) { // If this is the first room ever, do not add crate, and store the first room // Note : this is used in multiple scripts in the demo, to optimize it, use only one static var ! firstRoom = room; // Swith on light of the first room Light firstLight = room.roomObject.GetComponentInChildren <Light>(); if (firstLight != null) { firstLight.enabled = true; } //Debug.Log("First Monster Room is " + room.roomObject.name); // If player is found, move it into this room (the room wihout any monster) and move the camera above him GameObject player = GameObject.FindGameObjectWithTag("Player"); if (player != null) { Vector3 abovePlayer = room.roomObject.transform.position; abovePlayer.y = player.transform.position.y; player.transform.position = abovePlayer; player.GetComponent <CSPlayer>().spawnPosition = abovePlayer; abovePlayer.y = Camera.main.transform.position.y; Camera.main.transform.position = abovePlayer; } return; } // raycast from the center at a random direction, and instantiate a crate int monsterCount = Random.Range(minMonsterNumber, maxMonsterNumber); AddMonster(room, monsterCount); }
public IEnumerator Populate(int enemiesNumber, int maxEnemiesPerRoom) { enemies = new List <GameObject>(); List <MazeRoom> activeRooms = new List <MazeRoom>(rooms); if (playerStartCell != null) { activeRooms.Remove(playerStartCell.room); } while (enemies.Count < enemiesNumber) { if (activeRooms.Count == 0) { break; } MazeRoom randRoom = activeRooms[Random.Range(0, activeRooms.Count)]; activeRooms.Remove(randRoom); int randNumber = Random.Range(1, maxEnemiesPerRoom + 1); yield return(StartCoroutine(GenerateEnemiesInRoom(randRoom, randNumber))); } foreach (var enemy in enemies) { StatsManager stm = enemy.GetComponent <StatsManager>(); if (stm != null) { stm.GenerateRandomStats(checked ((uint)Random.Range(Mathf.Max(1u, GameManager.Stage - 1u), Mathf.Max(2u, GameManager.Stage + 1u)))); } } }
public List <MazeNode> GetEmptyRoomNodes(MazeRoom room) { List <MazeNode> emptyNodes = mazeCarver .GetAllNodes() .FindAll(node => node != null && !node.IsWall && node.IsOpen && node.IsRoom && node.Room != null && node.Room.Equals(room)); return(emptyNodes); }
/// <summary> /// Initializing room. /// </summary> /// <param name="room">A room in maze.</param> public void Initialize(MazeRoom room) { // Assigning the right materials. room.Add(this); // Insert material. transform.GetChild(0).GetComponent <Renderer>().material = room.Settings.FloorMaterial; }
void CreateEndRoom() { int posX = Random.Range(0, 100) > 50 ? 0 : m_MapSize.x - 1; int posY = Random.Range(0, 100) > 50 ? 0 : m_MapSize.y - 1; m_Map[posX, posY].MakeEndRoom(); EndRoom = m_Map[posX, posY]; }
private IEnumerator GenerateChestsInRoom(MazeRoom room, int number) { int chestsGenerated = 0; List <MazeCell> activeCells = new List <MazeCell>(room.Cells); while (chestsGenerated < number) { if (chests.Count % 10 == 0) { yield return(false); } if (activeCells.Count == 0) { break; } MazeCell randCell = activeCells[Random.Range(0, activeCells.Count)]; activeCells.Remove(randCell); MazePassage passage = null; if (randCell.IsFree) { int passageCount = 0; for (int i = 0; i < 4; i++) { MazeCellEdge edge = randCell.GetEdge(i); if (edge is MazePassage) { passage = edge as MazePassage; passageCount++; if (passageCount > 1) { break; } } } if (passageCount > 1) { continue; } randCell.RegisterEntity(); Container chest = GameObject.Instantiate(chestPrefab) as Container; chest.transform.parent = transform; chest.transform.localPosition = new Vector3(randCell.coordinates.x - size.x * 0.5f + 0.5f, transform.position.y, randCell.coordinates.z - size.z * 0.5f + 0.5f); chest.transform.localRotation = passage.direction.ToRotation(); chestsGenerated++; chests.Add(chest); } } }
public void Initialize(MazeRoom room) { room.Add(this); Floor.material = room.settings.FloorMaterial; if (HasLight) { Instantiate(LightPrefab, LightParent); } }
void OnMazeUpdate(MazeRoom room) { if (firstRoom == null) { firstRoom = room; GameObject go = (GameObject)Instantiate(carPrefab, transform.position + position, Quaternion.identity); go.transform.parent = room.roomObject.transform; } }
void AddMonster(MazeRoom room, int count) { Vector3 position = transform.position + Vector3.up * monster.GetComponent <Renderer>().bounds.extents.y; Vector3 direction = Vector3.right * monster.GetComponent <Renderer>().bounds.size.x; for (int i = 0; i < count; i++) { CreateMonster(room, position + direction * i); } }
public void AddPassage(MazeDirection dir, MazeRoom neighbour) { //if (!m_ActiveDirections.ContainsKey(dir)) m_ActiveDirections.Add(dir, neighbour); if (m_DirectionsList.Contains(dir)) { m_DirectionsList.Remove(dir); } }
public void AddOpenNode(int x, int y, MazeRoom room) { MazeNode node = GetOrCreateNode(x, y); node.IsOpen = true; node.Image = CreateRectSprite(node.Rect, Color.yellow, FloorType.Room); node.IsRoom = true; node.Room = room; node.Room.NumberOfNodes += 1; }
private MazeRoom GenerateRoom(List <RoomType> roomTypes) { RoomType roomType = roomTypes[Random.Range(0, roomTypes.Count)]; int x = Random.Range((int)world.xMin + 1, (int)world.xMax); int y = Random.Range((int)world.yMin + 1, (int)world.yMax); MazeRoom room = new MazeRoom(new Rect(NearestEven(x), NearestEven(y), roomType.Width, roomType.Height)); return(room); }
private void AttemptToPlaceARoom(MazeRoom room) { bool outOfBounds = room.Rect.xMax > config.Width - 1 || room.Rect.yMax > config.Height - 1; bool overlaps = rooms.Any(existingRoom => room.Rect.Overlaps(existingRoom.Rect)); if (!overlaps && !outOfBounds) { PlaceRoom(room); } }
public static List<MazeCell> GetSurroundingCellsInSameRoom(MazeCell cell, MazeCell otherCell, MazeRoom room) { var selectedCell = cell.room.RoomId == room.RoomId ? cell : otherCell; List<MazeCell> cells = new List<MazeCell>(); foreach (IntVector2 vectors in MazeDirections.vectorsAllDirections) { IntVector2 coordinates = selectedCell.coordinates + vectors; var celly = selectedCell.room.cells.Find (x => x.coordinates == coordinates); if (celly != null) cells.Add (celly); } return cells; }
public MazeRoomTrackAniControl(MazeRoom mazeRoom_) { m_mazeRoom = mazeRoom_; m_numAniParal = new NumAniParallel(); }
private void CalculateRoomComplexity (MazeRoom room) { foreach (var cell in room.cells) CalculateCellComplexity (cell); }
public void Initialize(MazeRoom room) { room.Add(this); transform.GetChild(0).GetComponent<Renderer>().material = room.settings.floorMaterial; }
public MazeOp() { m_curMazeRoom = null; m_bStart = false; }