public override void Initialize(LevelCell cell, LevelCell otherCell, LevelDirection direction) { base.Initialize(cell, otherCell, direction); wall.GetComponent <Renderer>().material = material; this.cell = cell; this.otherCell = otherCell; this.direction = direction; }
public virtual void Initialize(LevelCell cell, LevelCell otherCell, LevelDirection direction) { this.cell = cell; this.otherCell = otherCell; this.direction = direction; cell.SetEdge(direction, this); transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
private void CreateWall(LevelCell cell, LevelCell otherCell, LevelDirection direction, Canvas twoDMap) { LevelWall wall = Instantiate(wallPrefab) as LevelWall; wall.Initialize(cell, otherCell, direction); if (otherCell != null) { wall = Instantiate(wallPrefab) as LevelWall; wall.Initialize(otherCell, cell, direction.GetOpposite()); } CreateTwoDWall(cell, twoDMap, direction); }
private void CreateBreakableWall(LevelCell cell, LevelCell otherCell, LevelDirection direction, Canvas twoDMap) { LevelBreakableWall wall = Instantiate(breakableWallPrefab) as LevelBreakableWall; wall.material = breakableMats[cell.room.matIndex]; wall.Initialize(cell, otherCell, direction); breakableWalls.Add(wall); LevelBreakableWall otherWall = Instantiate(breakableWallPrefab) as LevelBreakableWall; otherWall.material = breakableMats[otherCell.room.matIndex]; otherWall.Initialize(otherCell, cell, direction.GetOpposite()); breakableWalls.Add(otherWall); CreateTwoDWall(cell, twoDMap, direction); }
private void DoNextGenerationStep(LevelCell [,] cells, List <LevelCell> activeCells, Canvas twoDMap, IntVector2 offset, IntVector2 size) { int currentIndex = activeCells.Count - 1; LevelCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } LevelDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates, size, offset)) { LevelCell neighbor = cells[coordinates.x - offset.x, coordinates.z - offset.z]; if (neighbor == null) { neighbor = CreateCell(cells, coordinates, twoDMap, offset); CreatePassage(currentCell, neighbor, direction, twoDMap, false); activeCells.Add(neighbor); } else if (currentCell.room == neighbor.room) { CreatePassageInSameRoom(currentCell, neighbor, direction, twoDMap); } else { if (currentCell.room.matIndex == neighbor.room.matIndex) { CreatePassageInSameRoom(currentCell, neighbor, direction, twoDMap); } else { if (Random.value < breakableWallProability) { CreateBreakableWall(currentCell, neighbor, direction, twoDMap); } else { CreateWall(currentCell, neighbor, direction, twoDMap); } } } } else { CreateWall(currentCell, null, direction, twoDMap); } }
// TODO: Decide whether or not I really care if the player already has the artifact. public bool SetArtifact(LevelDirection location) { if (Artifacts [(int)location].Equals(true)) { Debug.Log("layerDetails::SetArtifact - player already has artifact, hax?"); return(false); } else { Artifacts [(int)location] = true; } ItterateThroughArtifacts(); return(true); }
private void CreatePassageInSameRoom(LevelCell cell, LevelCell otherCell, LevelDirection direction, Canvas twoDMap) { LevelPassage passage = Instantiate(passagePrefab) as LevelPassage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(passagePrefab) as LevelPassage; passage.Initialize(otherCell, cell, direction.GetOpposite()); if (cell.room != otherCell.room) { LevelRoom joinRoom = otherCell.room; cell.room.Join(joinRoom); rooms.Remove(joinRoom); Destroy(joinRoom); } CreateTwoDPassage(cell, twoDMap, direction); }
public IEnumerator CleanLevelCinematically() { LevelCell[,] areaCells = cells; IntVector2 offset = new IntVector2(0, 0); List <LevelRoom> deadRooms = new List <LevelRoom>(); foreach (LevelRoom room in rooms) { if (room.cells.Count <= 4) { deadRooms.Add(room); bool roomCleaned = false; int cellIndex = 0; LevelCell cell = room.cells[0]; LevelDirection direction = 0; while (!roomCleaned && cellIndex < room.cells.Count) { cell = room.cells[cellIndex]; while ((int)direction < 4 && !roomCleaned) { if (cell.GetEdge(direction) is LevelPassage) { IntVector2 coordinates = cell.coordinates + direction.ToIntVector2(); LevelCell otherCell = areaCells[coordinates.x - offset.x, coordinates.z - offset.z]; if (otherCell.room != cell.room) { StartCoroutine(AssimilateCinematically(otherCell.room, cell.room)); roomCleaned = true; } } direction++; } cellIndex++; } } yield return(new WaitForSeconds(0.0f)); } foreach (LevelRoom room in deadRooms) { rooms.Remove(room); Destroy(room); } }
public LevelItem GetNeighbour(LevelItem rootItem, LevelDirection dir) { switch (dir) { case LevelDirection.Up: return(_levelItems.FirstOrDefault(i => i.Position.y - 1 == rootItem.Position.y)); case LevelDirection.Down: return(_levelItems.FirstOrDefault(i => i.Position.y + 1 == rootItem.Position.y)); case LevelDirection.Left: return(_levelItems.FirstOrDefault(i => i.Position.x - 1 == rootItem.Position.x)); case LevelDirection.Right: return(_levelItems.FirstOrDefault(i => i.Position.x + 1 == rootItem.Position.x)); default: throw new ArgumentOutOfRangeException("dir", dir, null); } }
private void CreatePassage(LevelCell cell, LevelCell otherCell, LevelDirection direction, Canvas twoDMap, bool existingCell) { LevelPassage passage = Instantiate(passagePrefab) as LevelPassage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(passagePrefab) as LevelPassage; if (!existingCell) { if (Random.value < newRoomProbability) { otherCell.InitializeCell(CreateRoom(cell.room.matIndex)); } else { otherCell.InitializeCell(cell.room); } CreateTwoDCell(otherCell, twoDMap); } passage.Initialize(otherCell, cell, direction.GetOpposite()); CreateTwoDPassage(cell, twoDMap, direction); }
private void CreateTwoDWall(LevelCell cell, Canvas twoDMap, LevelDirection direction) { IntVector2 positionMultiplier = direction.ToIntVector2(); Vector3 cellPosition = new Vector3((cell.coordinates.x - midX) * 1.0f, (cell.coordinates.z - midY) * 1.0f, 0); Vector2 offset = new Vector2(positionMultiplier.x * 0.5f, positionMultiplier.z * 0.5f); Image newImage = null; if (positionMultiplier.x != 0) { newImage = Instantiate(twoDVertPrefab) as Image; } else { newImage = Instantiate(twoDHorzPrefab) as Image; } newImage.transform.SetParent(twoDMap.transform, false); newImage.transform.localPosition = new Vector3(cellPosition.x + offset.x, cellPosition.y + offset.y, 0); newImage.color = Color.black; newImage.transform.SetAsLastSibling(); cell.GetEdge(direction).image = newImage; }
public bool IncrementKeyCount(LevelDirection location, int value = 1) { if (value < 1) { Debug.Log("Do not use PlayerDetails::IncrementKeyCount as a decrement."); return(false); } if (Keys [(int)location] + value > MAXIMUM_KEY_COUNT) { Debug.Log("Keys at Location: " + location.ToString() + " has hit MAXIMUM_KEY_COUNT (" + MAXIMUM_KEY_COUNT + ")"); return(false); } else { Keys [(int)location]++; } ItterateThroughKeys(); return(true); }
private void CleanLevel(LevelCell[,] areaCells, IntVector2 offset) { List <LevelRoom> deadRooms = new List <LevelRoom>(); foreach (LevelRoom room in rooms) { if (room.cells.Count <= 4) { deadRooms.Add(room); bool roomCleaned = false; int cellIndex = 0; LevelCell cell = room.cells[0]; LevelDirection direction = 0; while (!roomCleaned && cellIndex < room.cells.Count) { cell = room.cells[cellIndex]; while ((int)direction < 4 && !roomCleaned) { if (cell.GetEdge(direction) is LevelPassage) { IntVector2 coordinates = cell.coordinates + direction.ToIntVector2(); LevelCell otherCell = areaCells[coordinates.x - offset.x, coordinates.z - offset.z]; if (otherCell.room != cell.room) { Assimilate(otherCell.room, cell.room); roomCleaned = true; } } direction++; } cellIndex++; } } } foreach (LevelRoom room in deadRooms) { rooms.Remove(room); Destroy(room); } }
public bool GetArtifact(LevelDirection location) { return(Artifacts [(int)location]); }
public override void Initialize(LevelCell cell, LevelCell otherCell, LevelDirection direction) { base.Initialize(cell, otherCell, direction); wall.GetComponent <Renderer>().material = cell.room.mats.wallMaterial; }
public static IntVector2 ToIntVector2(this LevelDirection direction) { return(vectors[(int)direction]); }
public static LevelDirection GetOpposite(this LevelDirection direction) { return(opposites[(int)direction]); }
public static Quaternion ToRotation(this LevelDirection direction) { return(rotations[(int)direction]); }
public void SetEdge(LevelDirection direction, LevelCellEdge edge) { edges[(int)direction] = edge; initializedEdgeCount += 1; }
public LevelCellEdge GetEdge(LevelDirection direction) { return(edges[(int)direction]); }
private void Awake() { m_Direction = LevelDirection.Instance; m_data = Resources.Load <PlayerData>("Prefabs/PlayerData"); }
public int GetKeyCount(LevelDirection location) { return(Keys [(int)location]); }