Exemplo n.º 1
0
    public Vector2 FindNearest(Vector2 pos)
    {
        // Find the hex that overlaps a certain x,y point
        //Debug.Log(pos);
        nearestHex = HexCoord.AtPosition(pos);
        Vector2 hexPos = nearestHex.Position();

        return hexPos;
    }
Exemplo n.º 2
0
    // Used when a piece moves to update the lists
    public void MovePiece(HexCoord prevHex, HexCoord newHex, UnitColor color, UnitType type, GameObject obj)
    {
        if (type == UnitType.Beetle) //If beetle then we need to update lists differently
        {
            if (occupiedList.Contains(newHex)) //If beetle is moving on top of another piece
            {
                beetleDict[newHex]++;   //Add beetle on top
                CoverPieceBelow(obj.transform.position);
                //Don't add beetle to occupied list since hex is already occupied
            }
            else //If new hex is unoccupied then add beetle to occupied list
            {
                occupiedList.Add(newHex);
                colorDict[newHex] = color;
                typeDict[newHex] = type;
            }
            if (beetleDict[prevHex] > 0)    //If moving a beetle from a stacked position
            {
                beetleDict[prevHex]--;      //Decrement beetle count at previous hex
                UncoverPieceBelow(new Vector3(prevHex.Position().x, prevHex.Position().y, 5.0f)); //Define ray starting point far enough above prev position
            }
            else  //Only remove prevHex from lists if no other piece is at previous position
            {
                occupiedList.Remove(prevHex);
                colorDict.Remove(prevHex);
                typeDict.Remove(prevHex);
            }
        }
        else //If any other move type then change lists and dict as normal;
        {
            occupiedList.Remove(prevHex);
            colorDict.Remove(prevHex);
            typeDict.Remove(prevHex);
            beetleDict.Remove(prevHex);

            occupiedList.Add(newHex);
            colorDict[newHex] = color;
            typeDict[newHex] = type;
            beetleDict[newHex] = 0;
        }
    }
Exemplo n.º 3
0
 // Outline a single hex
 public void OutlineHexTall(HexCoord hex)
 {
     outlineObject = (GameObject)Instantiate(outlinePrefabTall);
     outlineObject.transform.position = hex.Position();
 }
Exemplo n.º 4
0
    // Outline a single hex
    public void ShowLastMove(HexCoord strt, HexCoord curr)
    {
        ClearLastMove();
        outlineObject = (GameObject)Instantiate(outlinePrefabTall);
        outlineObject.transform.position = curr.Position();

        HighlightStart(strt);
    }
Exemplo n.º 5
0
    public void HighlightStart(HexCoord startHex)
    {
        if (startHighlight != null)
            Destroy(startHighlight);

        startHighlight = (GameObject)Instantiate(highlightPrefab);
        startHighlight.GetComponent<HighlightController>().StartHex();
        startHighlight.transform.position = startHex.Position();
    }
Exemplo n.º 6
0
    //NOT USED
    public void HighlightNearestDeprecated(Vector2 pos)
    {
        // Find the hex that overlaps a certain x,y point
        //Debug.Log(pos);
        nearestHex = HexCoord.AtPosition(pos);
        Vector2 hexPos = nearestHex.Position();
        GameObject hexDisp = null;

        //Brute force method to get hex display associated with a certain HexCoord
        int i = 0;
        //int ind = 0;
        float smallestDist = Mathf.Infinity;
        foreach(Transform child in HexDisplays.transform)
        {
            float dist = Vector2.SqrMagnitude(hexPos - (Vector2)child.position);

            if (dist < smallestDist){
                smallestDist = dist;
                //ind = i;
                hexDisp = child.gameObject;
            }
            i++;
        }

        //Highlight the hex
        if (hexDisp != null && hexDisp != prevHexDisp) {
            if (prevHexDisp != null)
            {
                prevHexDisp.GetComponent<HexDisplayControl>().Highlight(false);
            }
            hexDisp.GetComponent<HexDisplayControl>().Highlight(true);

            prevHexDisp = hexDisp;
        }
    }
Exemplo n.º 7
0
    public void HighlightNearest(Vector2 pos)
    {
        nearestHex = HexCoord.AtPosition(pos);
        Vector2 hexPos = nearestHex.Position();

        if (nearestHex != prevHighlightedHex)
        {
            if (prevHighlight != null)
            {
                Destroy(prevHighlight);
            }
            GameObject highlight = (GameObject)Instantiate(highlightPrefab);
            highlight.GetComponent<HighlightController>().IneligibleHex();
            highlight.transform.position = hexPos;
            prevHighlight = highlight;
            prevHighlightedHex = nearestHex;
        }
    }
Exemplo n.º 8
0
    // Find the hex that overlaps a certain x,y point
    public void HighlightHex(HexCoord hex)
    {
        Vector2 hexPos = hex.Position();
        GameObject hexDisp = null;

        //Brute force method to get hex display associated with a certain HexCoord
        int i = 0;
        float smallestDist = Mathf.Infinity;
        foreach (Transform child in HexDisplays.transform)
        {
            float dist = Vector2.SqrMagnitude(hexPos - (Vector2)child.position);

            if (dist < smallestDist)
            {
                smallestDist = dist;
                hexDisp = child.gameObject;
            }
            i++;
        }

        //Highlight the hex
        if (hexDisp != null)
        {
            hexDisp.GetComponent<HexDisplayControl>().Highlight(true);
        }
    }
    //Moves piece to target hex. Used for undoing moves and moving piece back to start position. Checks for beetle stacking at target hex
    void SnapToHex(HexCoord hex)
    {
        Vector3 snapPos = hex.Position();
        snapPos.z = 3.0f;                                       //Move up high first to avoid collisions with other pieces
        this.transform.position = snapPos;                      //Snap to x,y position of target hex
        //this.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, 0f));    //Snap to default rotation

        //For beetles the target hex might be occupied. In that case, fix the z distance and don't allow gravity. Also make sure it's a beetle that's coming from the board. If coming from the dugout then treat as a normal piece
        if (specificBehavior.type == BoardManager.UnitType.Beetle && specificBehavior.active == BoardManager.Active.Board)
        {
            if (boardManager.beetleDict[hex] > 0) //Check if there was a stacked beetle at target hex
            {
                Vector3 temp = this.transform.position;
                int numBeetles = boardManager.beetleDict[hex];
                temp.z = 0.2f + 0.4f * (numBeetles);          //Position will scale up if there are multiple beetles
                this.transform.position = temp;
                this.transform.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            }
            else
            {
                this.transform.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY;

            }
        }
        // If piece is not a beetle then treat it normally
        else
        {
            this.transform.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY;
        }

        currentHex = hexController.GetNearestHex(this.transform.position);
    }