예제 #1
0
    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");
        }
    }
예제 #2
0
    /**
     * 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);
    }
예제 #3
0
    /// <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;
    }