private GameObject ChoosePathSprite(MapEvent.Initialized initializedEvent, int x, int y) { //Start of path if (x == 1 && y == 19) { return(pathLeftToBottom); } //End of path else if (x == 1 && y == 0) { return(pathLeftToRight); } //Other path tiles else { //Path to the left if (x != 0 && initializedEvent.MapCells[x - 1, y] is PathCell) { //Path above if (y != 19 && initializedEvent.MapCells[x, y + 1] is PathCell) { return(pathLeftToTop); } //Path to the right else if (x != 19 && initializedEvent.MapCells[x + 1, y] is PathCell) { return(pathLeftToRight); } //Must be path below else { return(pathLeftToBottom); } } //There exists a path to the top else if (y != 19 && initializedEvent.MapCells[x, y + 1] is PathCell) { //Path to the right if (x != 19 && initializedEvent.MapCells[x + 1, y] is PathCell) { return(pathTopToRight); } //Must be path below else { return(pathTopToBottom); } } //Must be path to the right and below else { return(pathRightToBottom); } } }
private void InitilizeWalls(MapEvent.Initialized initialized, WallsAggregate walls) { var mapCoords = Enumerable.Range(0, initialized.MapCells.GetLength(0)).SelectMany(x => Enumerable.Range(0, initialized.MapCells.GetLength(1)).Select(y => new MapCoordinate(x, y))); var initialWalls = mapCoords .Where(coord => initialized.MapCells[coord.X, coord.Y] is WallCell) .Select(coord => new WallParameters(coord)) .ToArray(); walls.Initialize(initialWalls); }
private void InitializeTowers(MapEvent.Initialized initialized, TowersAggregate towers) { var mapCoords = Enumerable.Range(0, initialized.MapCells.GetLength(0)).SelectMany(x => Enumerable.Range(0, initialized.MapCells.GetLength(1)).Select(y => new MapCoordinate(x, y))); var initialTowers = mapCoords .Where(coord => initialized.MapCells[coord.X, coord.Y] is TowerCell) .Select(coord => new TowerParameters(TowerIdentifier.Create(), coord, PickRandomTowerType())) .ToArray(); towers.Initialize(initialTowers); }
private void HandleMapInitializedEvent(MapEvent.Initialized initializedEvent) { _tiles = new GameObject[initializedEvent.MapCells.GetLength(0), initializedEvent.MapCells.GetLength(1)]; for (var x = 0; x < initializedEvent.MapCells.GetLength(0); x++) { for (var y = 0; y < initializedEvent.MapCells.GetLength(1); y++) { switch (initializedEvent.MapCells[x, y]) { case GroundCell cell: _tiles[x, y] = Instantiate(ground, new Vector3(x, y, 0), Quaternion.identity, transform); break; case TowerCell cell: break; case PathCell cell: var pathTile = ChoosePathSprite(initializedEvent, x, y); _tiles[x, y] = Instantiate(pathTile, new Vector3(x, y, 0), Quaternion.identity, transform); break; case WallCell cell: _tiles[x, y] = Instantiate(brokenWall, new Vector3(x, y, 0), Quaternion.identity, transform); break; case StartCell cell: _tiles[x, y] = Instantiate(spawner, new Vector3(x, y, 0), Quaternion.identity, transform); break; case GoalCell cell: _tiles[x, y] = Instantiate(castle, new Vector3(x, y, 0), Quaternion.identity, transform); break; case WaterCell cell: _tiles[x, y] = Instantiate(water, new Vector3(x, y, 0), Quaternion.identity, transform); break; default: throw new NotImplementedException("Unknown cell type"); } } } }
private void HandleMapInitialized(MapEvent.Initialized e) { _pathFinder.Initialize(e.MapCells, e.GoalCell); }