void Awake()
    {
        //accesses the location of white pieces
        whitePieces = GameObject.Find("White Pieces").GetComponent<whitePieceTracker>();

        //accesses the location of black pieces
        blackPieces = GameObject.Find("Black Pieces").GetComponent<blackPieceTracker>();

        //accesses the tiles
        boardTiles = GameObject.Find("BoardCreator").GetComponent<boardCreationScript>();
        tileMover = GameObject.Find("BoardCreator").GetComponent<alphaMovementScript>();

        //accesses the current turn
        turn = GameObject.Find("Piece Parent").GetComponent<turnTracker>();

        //turns off the piece's halo
        (gameObject.GetComponent("Halo") as Behaviour).enabled = false;

        //saves the pawn's original position
        homePosX = gameObject.transform.position.x;
        homePosY = gameObject.transform.position.y;

        //accesses piece's location
        coordinates = gameObject.GetComponent<positionScript>();

        myKing = GameObject.Find("Black King").GetComponent<kingMovement>();
        pieceColor = gameObject.transform.tag;
        gameObject.GetComponent<positionScript>().pieceColor = pieceColor;
        gameObject.GetComponent<positionScript>().pieceTag = pieceTag;
        coordinates.xHome = homePosX;
        coordinates.yHome = homePosY;
    }
Esempio n. 2
0
    // —————
    // ————— Figure out which position to go to next.
    // —————
    void getNextPosition(int _goWhere, string _displayText)
    {
        // print("go Move!" + _goWhere + " " + _displayText);

        // Update State Machine
        currentPosition = _goWhere;
        movementState   = moveHolder.MOVING;

        // ————— Cycle through positions until we found the next one
        if (whereToMoveTo == Vector3.zero)
        {
            foreach (positionScript ps in positions)
            {
                if (_goWhere == ps.id)
                {
                    whereToMoveTo  = ps.transform.position;
                    scriptOfTarget = ps;
                    scriptOfTarget.changeDisplayText(_displayText);
                    break;
                }
            }
            if (whereToMoveTo == Vector3.zero)   // catch error where the id is out of range
            {
                print("Error found!");
                whereToMoveTo = positions[0].transform.position; // go to first position as fallback
            }
        }
        // ————— set next look rotation
        getNextRotationHolder.position = transform.position;
        getNextRotationHolder.rotation = transform.rotation;
        getNextRotationHolder.LookAt(whereToMoveTo);
    }
 public void deactivateHalo(GameObject piece)
 {
     pieceLocator = piece.GetComponent<positionScript>();
     if (checkActivePiece(piece) == false) {
         (piece.GetComponent("Halo") as Behaviour).enabled = false;
         pieceLocator.timeToDeactivate = true;
     }
 }
    void Awake()
    {
        //creates the array to reference tiles
        tiles = new GameObject[boardWidth, boardHeight];
        tileLocations = new Vector3[boardWidth,boardHeight];
        tileColors = new Color [boardWidth, boardHeight];
        GameObject border;
        //creates the board and stores each tile within the array
        for (int x = 0; x<boardWidth; x++)
        {

            border = (GameObject) Instantiate(vertBorder, new Vector3 (x * 3 + 1.5F, 10.5F, -1), Quaternion.identity);
            border.transform.parent = borderParent.transform;
            border = (GameObject) Instantiate(horBorder, new Vector3 (10.5F, x*3 + 1.5F, -1), Quaternion.identity);
            border.transform.parent = borderParent.transform;
            for (int y = 0; y < boardHeight; y++)
            {
                tiles [x,y] = (GameObject) Instantiate(tileCube, new Vector3 (x *3, y * 3, 0), Quaternion.identity);
                tiles [x,y].transform.parent = tileParent.transform;
                (tiles [x,y].GetComponent("Halo") as Behaviour).enabled = false;
                tileLocations [x,y] = tiles[x,y].transform.position;
           			    pieceLocation = tiles[x,y].GetComponent<positionScript>();
                pieceLocation.xPos = x;
                pieceLocation.yPos = y;
                tileColors [x,y] = Color.white;
                tiles[x,y].tag = "No Piece";

            }
        }
        border = (GameObject) Instantiate(vertBorder, new Vector3 (-1.5F, 10.5F, -1), Quaternion.identity);
        border.transform.parent = borderParent.transform;
        border = (GameObject) Instantiate(horBorder, new Vector3 (10.5F, -1.5F, -1), Quaternion.identity);
        border.transform.parent = borderParent.transform;
        //turns the even squares black
        for (int x = 1; x<boardWidth; x+=2)
        {
            for (int y = 1; y < boardHeight; y+=2)
            {
                tiles [x,y].transform.renderer.material.color = Color.black;
                tileColors [x,y] = Color.black;
            }
        }

        //turns the odd squares black
        for (int x = 0; x<boardWidth; x+=2)
        {
            for (int y = 0; y < boardHeight; y+=2)
            {
                tiles [x,y].transform.renderer.material.color = Color.black;
                tileColors [x,y] = Color.black;
            }
        }
    }
    void Awake()
    {
        //stores piece's color
        pieceColor = gameObject.transform.tag;
        if (pieceColor == "Black") {
            myKing = GameObject.Find("Black King").GetComponent<kingMovement>();
        } else if (pieceColor == "White") {
            myKing = GameObject.Find("White King").GetComponent<kingMovement>();
        }

        //turns off the piece's halo
        (gameObject.GetComponent("Halo") as Behaviour).enabled = false;

        //accesses the location of white pieces
        whitePieces = GameObject.Find("White Pieces").GetComponent<whitePieceTracker>();

        //accesses the location of black pieces
        blackPieces = GameObject.Find("Black Pieces").GetComponent<blackPieceTracker>();

        //accesses the tiles
        boardTiles = GameObject.Find("BoardCreator").GetComponent<boardCreationScript>();
        tileMover = GameObject.Find("BoardCreator").GetComponent<alphaMovementScript>();

        //accesses the current turn
        turn = GameObject.Find("Piece Parent").GetComponent<turnTracker>();

        //accesses piece's location
        homePosX = gameObject.transform.position.x;
        homePosY = gameObject.transform.position.y;
        gameObject.GetComponent<positionScript>().xHome = homePosX;
        gameObject.GetComponent<positionScript>().yHome = homePosY;
        coordinates = gameObject.GetComponent<positionScript>();

        //creates the move and attack square arrays
        attackSquares = new GameObject[maxMoveSquares];
        diagMoveSquaresUpLeft = new GameObject[maxMoveSquares];
        diagMoveSquaresUpRight = new GameObject[maxMoveSquares];
        diagMoveSquaresDownLeft = new GameObject[maxMoveSquares];
        diagMoveSquaresDownRight = new GameObject[maxMoveSquares];
        attackSquaresColor = new Color[maxMoveSquares];

        gameObject.GetComponent<positionScript>().pieceColor = pieceColor;
        gameObject.GetComponent<positionScript>().pieceTag = pieceTag;
    }
    void Awake()
    {
        //turns off the piece's halo
        (gameObject.GetComponent("Halo") as Behaviour).enabled = false;

        //accesses the location of white pieces
        whitePieces = GameObject.Find("White Pieces").GetComponent<whitePieceTracker>();

        //accesses the location of black pieces
        blackPieces = GameObject.Find("Black Pieces").GetComponent<blackPieceTracker>();

        //accesses the tiles
        boardTiles = GameObject.Find("BoardCreator").GetComponent<boardCreationScript>();
        tileMover = GameObject.Find("BoardCreator").GetComponent<alphaMovementScript>();

        //accesses the current turn
        turn = GameObject.Find("Piece Parent").GetComponent<turnTracker>();

        //accesses piece's location
        coordinates = gameObject.GetComponent<positionScript>();

        //sets the original position
        homePosX = gameObject.transform.position.x;
        homePosY = gameObject.transform.position.y;

        //creates the arrays to track movesquares
        squareColors = new Color[maxMoveSquares];
        squares = new GameObject[maxMoveSquares];
        checkSquareColors = new Color[maxMoveSquares + 1];
        checkSquares = new GameObject[maxMoveSquares + 1];

        //stores the pieces color
        pieceColor = gameObject.transform.tag;
        coordinates.pieceColor = pieceColor;
        coordinates.pieceTag = pieceTag;
        coordinates.xHome = homePosX;
        coordinates.yHome = homePosY;
    }
    // Use this for initialization
    void Awake()
    {
        pieceColor = gameObject.transform.tag;
        if (pieceColor == "Black") {
            myKing = GameObject.Find("Black King").GetComponent<kingMovement>();
        } else if (pieceColor == "White") {
            myKing = GameObject.Find("White King").GetComponent<kingMovement>();
        }
        //turns off the piece's halo
        (gameObject.GetComponent("Halo") as Behaviour).enabled = false;

        //accesses the location of white pieces
        whitePieces = GameObject.Find("White Pieces").GetComponent<whitePieceTracker>();

        //accesses the location of black pieces
        blackPieces = GameObject.Find("Black Pieces").GetComponent<blackPieceTracker>();

        //accesses the tiles
        boardTiles = GameObject.Find("BoardCreator").GetComponent<boardCreationScript>();
        tileMover = GameObject.Find("BoardCreator").GetComponent<alphaMovementScript>();

        //accesses the current turn
        turn = GameObject.Find("Piece Parent").GetComponent<turnTracker>();

        //saves the pawn's original position and accesses its current one
        homePosX = gameObject.transform.position.x;
        homePosY = gameObject.transform.position.y;
        coordinates = gameObject.GetComponent<positionScript>();

        //creates the arrays for moveSquares
        vertMoveSquaresUp = new GameObject[maxMoveSquares];
        vertMoveSquaresDown = new GameObject[maxMoveSquares];
        horMoveSquaresLeft = new GameObject[maxMoveSquares];
        horMoveSquaresRight = new GameObject[maxMoveSquares];
        attackSquares = new GameObject[maxAttackSquares];
        attackSquaresColor = new Color[maxAttackSquares];

        gameObject.GetComponent<positionScript>().pieceColor = pieceColor;
        gameObject.GetComponent<positionScript>().pieceTag = pieceTag;
    }
 public void updateLocation(GameObject piece, string tileTag)
 {
     pieceLocator = piece.GetComponent<positionScript>();
     for (int x = 0; x < 8; x++) {
         for (int y = 0; y < 8; y++) {
             if (matchPosition(piece, coordinates.tiles[x,y])) {
                 tileLocator = coordinates.tiles[x,y].GetComponent<positionScript>();
                 boardTiles.tiles[pieceLocator.xPos, pieceLocator.yPos].transform.tag = "No Piece";
                 pieceLocator.xPos = tileLocator.xPos;
                 pieceLocator.yPos = tileLocator.yPos;
                 boardTiles.tiles[pieceLocator.xPos, pieceLocator.yPos].transform.tag = pieceLocator.pieceColor + " " +tileTag;
             }
         }
     }
 }