public void ReturnHook(PieceData piece) { // Refernece to the board TaoexBoard tb = GameObject.Find("Taoex").GetComponent <TaoexBoard>(); TileNode[] wayCrossTiles = tb.WayCrossTiles; // Closest tile information float closestDistance = float.MaxValue; TileNode closestTile = null; for (int i = 0; i < 6; i++) { // Find empty way crosses if (wayCrossTiles[i].tower != null) { continue; } // Get the closest way cross float distance = Vector3.Distance(piece.getObj().transform.position, wayCrossTiles[i].transform.position); if (distance < closestDistance) { Debug.Log(i + " : " + distance); closestDistance = distance; closestTile = wayCrossTiles[i]; } } // If there is no available way cross, try the center if (closestTile == null && (tb.GetTiles()[13, 11].tower == null || tb.GetTiles()[13, 11].tower == attacker)) { closestTile = tb.GetTiles()[13, 11]; } if (closestTile != null) { // Return the hook closestTile.tower = new PieceTower(tb.HookPlayer, piece, closestTile); //piece.MoveTo(closestTile.transform.position); } else { Destroy(piece.getObj()); Debug.Log("Couldn't find a tile to put the hook back onto"); } }
/** * Button's on click event */ void ButtonOnClick() { // Reference to the board TaoexBoard tb = GameObject.Find("Taoex").GetComponent <TaoexBoard>(); // Position of the camera is based on a tile on the board Vector3 start = tb.GetTiles()[(int)startTile.x, (int)startTile.y].gameObject.transform.position; // Focus of the camera is the center tile Vector3 end = tb.GetTiles()[13, 11].gameObject.transform.position; // Set the new position and focus of the camera cameraControl.SetPosition(start); cameraControl.SetFocus(end); // Vector from start to end Vector3 direction = end - start; direction.y = 0f; direction.Normalize(); // Move the camera back cameraControl.Move(direction, -400f); }
/// <summary> /// Generates all twelve starting pieces for the player. /// </summary> /// <param name="player">the player to generate pieces for</param> public void GeneratePlacementPieces(Player player) { // Directions as ints int N = 0, NE = 1, SE = 2, S = 3, SW = 4, NW = 5; // List of pieces to place List <PieceData> pieces = new List <PieceData>(); PieceCreator pieceCreator = GameObject.Find("Taoex").GetComponent <PieceCreator>(); // Create the pieces for (int dir = 0; dir < 6; dir++) { pieces.Add(pieceCreator.CreatePiece(player.colour, dir, 2)); pieces.Add(pieceCreator.CreatePiece(player.colour, dir, 3)); } // Reference to the board for getting way cross coordinates TaoexBoard board = GameObject.Find("Taoex").GetComponent <TaoexBoard>(); Vector3 center = GameObject.Find("Compass").transform.position; Vector3[] crosses = new Vector3[6]; // Positions of the way crosses crosses[0] = board.GetTiles()[13, 5].BasePosition; // S crosses[1] = board.GetTiles()[7, 8].BasePosition; // SW crosses[2] = board.GetTiles()[7, 14].BasePosition; // NW crosses[3] = board.GetTiles()[13, 17].BasePosition; // N crosses[4] = board.GetTiles()[19, 14].BasePosition; // NE crosses[5] = board.GetTiles()[19, 8].BasePosition; // SE // Pieces per direction are in sets of two, so we need to offset them float offset = 0f; float angleOffset = 0f; // Counter for the piece number for the current direction int count = 0; foreach (PieceData piece in pieces) { // Setup the textures piece.SetupTextures(); // Placement piece component so that the piece can handle click events correctly player.PlacementPieces.Add(piece.getObj().AddComponent <PlacementPiece>()); piece.getObj().GetComponent <PlacementPiece>().Piece = piece; // Spawn position of the piece Vector3 spawnPosition; Transform pieceTrans = piece.getObj().transform; // Direction of the piece int direction = piece.direction; // Spawn position starts at the way cross spawnPosition = crosses[direction]; // Vector going outward from the center to the cross Vector3 centerToCross = spawnPosition - center; centerToCross.Normalize(); // Move the spawn position back and up spawnPosition += centerToCross * 500f; spawnPosition.y += 40f; // Spawn the piece texture there piece.getObj().transform.position = spawnPosition; // Make the piece look towards the center pieceTrans.LookAt(center); // Move along the side of the board using uvn coordinates pieceTrans.InverseTransformDirection(pieceTrans.position); pieceTrans.Translate(offset - 400f + playerPlacementOffset, 0, 0f); pieceTrans.TransformDirection(pieceTrans.position); // Rotate the pieces piece.getObj().transform.eulerAngles = new Vector3(0, angleOffset, 0); // Save the transform piece.getObj().GetComponent <PlacementPiece>().PlacementPosition = piece.getObj().transform.position; piece.getObj().GetComponent <PlacementPiece>().PlacementRotation = piece.getObj().transform.eulerAngles; // Increment the offset offset += 75f; count++; // If this is the second piece, reset offsets for the next set of two if (count % 2 == 0) { offset = 0f; } if (count % 2 == 0) { angleOffset += 60f; } } // Next player's offset playerPlacementOffset += 200f; }
/// <summary> /// Initalize this instance. /// </summary> public void Initalize() { turnIndex = -1; totalTurns = 0; currentCycle = 1; moveHistory = new List <PieceMove>(); state = State.Placement; rand = new System.Random(); #region quick ini players if (players == null) { // ini players players = new Player[3]; // player 1 players[0] = new LocalHumanPlayer(); players[0].colour = Player.PlayerColour.Brown; players[0].playerName = players[0].colour + ""; // player 2 players[1] = new LocalHumanPlayer(); players[1].colour = Player.PlayerColour.Blue; players[1].playerName = players[1].colour + ""; // player 3 players[2] = new LocalHumanPlayer(); players[2].colour = Player.PlayerColour.Green; players[2].playerName = players[2].colour + ""; } #endregion #region generate and attach score displays to player for (int i = 0; i < players.Length; i++) { GameObject display = Instantiate(Resources.Load("Prefabs/UI/ScoreDisplay")) as GameObject; display.transform.SetParent(GameObject.Find("UICanvas").transform, false); // positioning the display RectTransform rect = display.GetComponent <RectTransform>(); Vector3 pos = new Vector3(rect.anchoredPosition3D.x, rect.anchoredPosition3D.y); Vector3 offset = new Vector3( -(45f * (players.Length / 2f)) + (45f * i) + (10f * i), 0f); pos += offset; rect.anchoredPosition3D = pos; // setting display colour display.GetComponent <Image>().color = players[i].getRealColor(); players[i].scoreDisplay = display; players[i].updateScore(); } #endregion // Generate placement pieces for each player foreach (Player p in players) { GeneratePlacementPieces(p); } // Initialize the placement tiles TaoexBoard board = GameObject.Find("Taoex").GetComponent <TaoexBoard>(); placementTiles = new List <TileNode>(); // Add all edge tiles to the placement tiles list for (int i = 0; i < board.edgeTiles.GetLength(0); i++) { for (int j = 0; j < board.edgeTiles.GetLength(1); j++) { placementTiles.Add(board.edgeTiles[i, j]); } } if (randomPlacement) { // randomly places the pieces RandomPlacement(); } // increments the turn from -1 to 0 which is the first player NextTurn(); }