public override void _Ready() { TileMap = (HexTileMap)GetNode("HexTileMap"); Hovered = (Sprite)GetNode("Hovered"); Selected = (Sprite)GetNode("Selected"); // Inicia o TileManager foreach (Vector2 cell in TileMap.GetUsedCells()) { TileManager.Tiles[cell.x, cell.y] = new Tile(Terrain.GetTerrain(TileMap.GetCellv(cell))); } // Adiciona a primeira unidade do jogo Unit newUnit = UnitManager.CreateUnit(UnitType.Goblin); newUnit.Position = TileMap.TileSize / 2; AddChild(newUnit); }
// This function is called whenever the user clicks on the scene. The function uses Case-switch statements to determine what type of object was clicked. private void OnMouseUp() { object[] tiles = GameObject.FindGameObjectsWithTag("Tile"); // The Case-switch statement used in order to determine what type of gameobject was clicked. Uses the description property in order to determine the type of gameobject. switch (gameObject.GetComponent <Properties>().description) { case "Player_Piece_Chief": case "Player_Piece_Hunter": case "Player_Piece_Archer": case "Player_Piece_Dragon": case "Player_Piece_Traitor": movementManager.CheckTileColour(gameObject, tiles, prevPiece); // Checks to see if the piece has already been activated. If so, nothing happens, otherwise the game will highlight the available moves with said piece. if (gameObject.GetComponent <Player_Piece_Properties>().activated == true) { return; } if (gameObject == prevPiece) { foreach (GameObject tile in tiles) { if (tile.GetComponent <Renderer>().material.color == colourManager.babyBlue || tile.GetComponent <Renderer>().material.color == colourManager.turqoise || tile.GetComponent <Renderer>().material.color == Color.yellow) { colourManager.CompleteAction(gameObject); movementManager.ClearHighlights(tiles); return; } } if (gameObject.GetComponent <Properties>().description == "Player_Piece_Traitor") { colourManager.CompleteAction(gameObject); movementManager.ClearHighlights(tiles); } movementManager.ClearHighlights(tiles); prevPiece = null; } else { foreach (GameObject tile in tiles) { if (tile.GetComponent <Renderer>().material.color == colourManager.babyBlue || tile.GetComponent <Renderer>().material.color == Color.green) { return; } } movementManager.HighlightMovement(gameObject.GetComponent <Properties>().CurrentTile, gameObject.GetComponent <Player_Piece_Properties>().movementSpeed, gameObject); prevPiece = gameObject; } break; case "Traitor": // While the traitor piece is inactive, do not have any interactions with it. break; // If a tile is clicked and the current available moves are highlighted, then the piece GameObject will do a certain action depending on the colour of the highlight. case "Tile": object[] pieces = GameObject.FindGameObjectsWithTag("Player_Piece"); if (gameObject.GetComponent <Renderer>().material.color == Color.yellow) { unitManager.CreateUnit(gameObject, unitPiece); movementManager.ClearHighlights(tiles); unitPiece = null; } else if (gameObject.GetComponent <Renderer>().material.color == colourManager.turqoise) { movementManager.ClearHighlights(tiles); colourManager.CompleteAction(prevPiece); } else if (gameObject.GetComponent <Renderer>().material.color == Color.green) { movementManager.ManageMovement(gameObject, tiles, prevPiece); movementManager.HighlightAttackRange(gameObject.GetComponent <Properties>().CurrentTile, prevPiece.GetComponent <Player_Piece_Properties>().attackRange, pieces, prevPiece); } else if (gameObject.GetComponent <Renderer>().material.color == colourManager.babyBlue) { movementManager.ManageMovement(gameObject, tiles, repositionPiece); colourManager.CompleteAction(prevPiece); repositionPiece = null; } break; default: Debug.Log("ERROR"); break; } }
//Button Handlers for red, blue, white and green public void CreateRedPressed() { unitManager.CreateUnit("Red"); }