public void GenerateMap() { Vector3Int topLeftSpawnTileBottomTile = StaticGridManager.GetSingleton().topLeftSpawnTile + Vector3Int.down; Vector3Int topLeftSpawnTileRightTile = StaticGridManager.GetSingleton().topLeftSpawnTile + Vector3Int.right; Vector3Int topRightSpawnTileBottomTile = StaticGridManager.GetSingleton().topRightSpawnTile + Vector3Int.down; Vector3Int topRightSpawnTileLeftTile = StaticGridManager.GetSingleton().topRightSpawnTile + Vector3Int.left; Vector3Int bottomLeftSpawnTileTopTile = StaticGridManager.GetSingleton().bottomLeftSpawnTile + Vector3Int.up; Vector3Int bottomLeftSpawnTileRightTile = StaticGridManager.GetSingleton().bottomLeftSpawnTile + Vector3Int.right; Vector3Int bottomRightSpawnTileTopTile = StaticGridManager.GetSingleton().bottomRightSpawnTile + Vector3Int.up; Vector3Int bottomRightSpawnTileLeftTile = StaticGridManager.GetSingleton().bottomRightSpawnTile + Vector3Int.left; TileDef.TileType[,] tileTypes = new TileDef.TileType[StaticGridManager.GetSingleton().width, StaticGridManager.GetSingleton().height]; for (int x = 0; x < StaticGridManager.GetSingleton().width; ++x) { for (int y = StaticGridManager.GetSingleton().height - 1; y >= 0; --y) { Vector3Int cellPosition = new Vector3Int(x, y, 0); if (!StaticGridManager.GetSingleton().collidableGroundTilemap.HasTile(cellPosition)) { Vector3 cellWorldPosition = StaticGridManager.GetSingleton().nonCollidableGroundTilemap.GetCellCenterWorld(cellPosition); bool isSpawnTile = cellPosition == StaticGridManager.GetSingleton().topLeftSpawnTile || cellPosition == StaticGridManager.GetSingleton().topRightSpawnTile || cellPosition == StaticGridManager.GetSingleton().bottomLeftSpawnTile || cellPosition == StaticGridManager.GetSingleton().bottomRightSpawnTile || cellPosition == topLeftSpawnTileBottomTile || cellPosition == topLeftSpawnTileRightTile || cellPosition == topRightSpawnTileBottomTile || cellPosition == topRightSpawnTileLeftTile || cellPosition == bottomLeftSpawnTileTopTile || cellPosition == bottomLeftSpawnTileRightTile || cellPosition == bottomRightSpawnTileTopTile || cellPosition == bottomRightSpawnTileLeftTile; if (!isSpawnTile && Random.value <= bricksProbability) { networkManager.AddObject((int)CustomNetworkManager.SpawnPrefabs.BricksTile, cellWorldPosition); } else { Vector3Int topCellPosition = new Vector3Int(x, y + 1, 0); TileDef.TileType topTileType = tileTypes[topCellPosition.x, topCellPosition.y]; if (topTileType == TileDef.TileType.Bricks) { networkManager.AddObject((int)CustomNetworkManager.SpawnPrefabs.GrassWithShadowTile, cellWorldPosition); } else { networkManager.AddObject((int)CustomNetworkManager.SpawnPrefabs.GrassTile, cellWorldPosition); } tileTypes[x, y] = TileDef.TileType.Grass; } } } } }
bool RunTheGauntlet() { TileDef.TileType[] pieceTypes = new TileDef.TileType[] { TileDef.TileType.pawn, TileDef.TileType.knight, TileDef.TileType.bishop, TileDef.TileType.rook, TileDef.TileType.queen, TileDef.TileType.king }; // Loop over the piece tyeps for (int i = 0; i < pieceTypes.Length; i++) { TileDef.TileType pieceType = pieceTypes[i]; // Loop over the board for (int y = 0; y < GameConstants.BOARD_H; y++) { for (int x = 0; x < GameConstants.BOARD_W; x++) { // Inspect the piece there TileDef piece = BoardManager.Instance.GetTile(x, y); if (piece.owner == TileDef.TileOwner.black && piece.type == pieceType) { DrawPieceHighlights(x, y, piece); if (GAME_ENEMY_THREATEN == true) { // Clear others and redraw for special fx ClearHighlights(); DrawPieceHighlights(x, y, piece); GAME_ENEMY_SOLDIER_X = x; GAME_ENEMY_SOLDIER_Y = y; return(true); } } } } } // Don't let the player see the mess we made ClearHighlights(); return(false); }
void DrawPieceHighlights(int x, int y, TileDef piece) { Debug.LogWarning("type: " + piece.type + "\n"); bool me = (piece.owner == TileDef.TileOwner.white); TileDef.TileType type = piece.type; int dir = me ? 1 : -1; int pawnRow = me ? GameConstants.BOARD_H - 2 : 1; // Pawn if (type == TileDef.TileType.pawn) { if (me) { // Move forward if (IsClear(x, y - 1 * dir)) { HighlightPotentialMove(piece, x, y - 1 * dir); // Double move on starting row if (y == pawnRow) { if (IsClear(x, y - 2 * dir)) { HighlightPotentialMove(piece, x, y - 2 * dir); // Double move on first row } } } // Capture right if (!IsClear(x + 1, y - 1 * dir)) { HighlightPotentialMove(piece, x + 1, y - 1 * dir); } // Capture left if (!IsClear(x - 1, y - 1 * dir)) { HighlightPotentialMove(piece, x - 1, y - 1 * dir); } } else { HighlightPotentialMove(piece, x + 1, y - 1 * dir); HighlightPotentialMove(piece, x - 1, y - 1 * dir); } } // Knight if (type == TileDef.TileType.knight) { HighlightPotentialMove(piece, x + 1, y - 2 * dir); HighlightPotentialMove(piece, x + 1, y + 2 * dir); HighlightPotentialMove(piece, x - 1, y - 2 * dir); HighlightPotentialMove(piece, x - 1, y + 2 * dir); HighlightPotentialMove(piece, x + 2, y - 1 * dir); HighlightPotentialMove(piece, x + 2, y + 1 * dir); HighlightPotentialMove(piece, x - 2, y - 1 * dir); HighlightPotentialMove(piece, x - 2, y + 1 * dir); } if (type == TileDef.TileType.bishop || type == TileDef.TileType.queen) { DrawPieceHighlightTravel(piece, x, y, 1, 1); DrawPieceHighlightTravel(piece, x, y, 1, -1); DrawPieceHighlightTravel(piece, x, y, -1, 1); DrawPieceHighlightTravel(piece, x, y, -1, -1); } if (type == TileDef.TileType.rook || type == TileDef.TileType.queen) { for (var i = 1; i < 8; i++) { DrawPieceHighlightTravel(piece, x, y, 1, 0); DrawPieceHighlightTravel(piece, x, y, -1, 0); DrawPieceHighlightTravel(piece, x, y, 0, 1); DrawPieceHighlightTravel(piece, x, y, 0, -1); } } if (type == TileDef.TileType.king) { HighlightPotentialMove(piece, x + 1, y + 1); HighlightPotentialMove(piece, x + 0, y + 1); HighlightPotentialMove(piece, x - 1, y + 1); HighlightPotentialMove(piece, x + 1, y + 0); HighlightPotentialMove(piece, x - 1, y + 0); HighlightPotentialMove(piece, x + 1, y - 1); HighlightPotentialMove(piece, x + 0, y - 1); HighlightPotentialMove(piece, x - 1, y - 1); } }