Inheritance: MonoBehaviour
 void Start()
 {
     agent      = GetComponent <NavMeshAgent>();
     agentSpeed = agent.speed;
     //agent.autoBraking = false;
     zoneControl      = zone.GetComponent <ZoneScript>();
     playerController = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerController>();
     //GotoNextPoint();
     gameController = playerController.gameObject.GetComponent <GameController>();
 }
Exemplo n.º 2
0
 public ZoneScript FindNextZone(ref ZoneScript TargetZone)
 {
     if (player1Turn)
     {
         if (Input.GetButtonDown("Up"))
         {
             TargetZone = SelectZone(TargetZone.column, TargetZone.row + 1);
         }
         else if (Input.GetButtonDown("Down"))
         {
             TargetZone = SelectZone(TargetZone.column, TargetZone.row - 1);
         }
         else if (Input.GetButtonDown("Right"))
         {
             TargetZone = SelectZone((char)(TargetZone.column + (char)1), TargetZone.row);
         }
         else if (Input.GetButtonDown("Left"))
         {
             TargetZone = SelectZone((char)(TargetZone.column - (char)1), TargetZone.row);
         }
     }
     else
     {
         if (Input.GetButtonDown("Up"))
         {
             TargetZone = SelectZone(TargetZone.column, TargetZone.row - 1);
         }
         else if (Input.GetButtonDown("Down"))
         {
             TargetZone = SelectZone(TargetZone.column, TargetZone.row + 1);
         }
         else if (Input.GetButtonDown("Right"))
         {
             TargetZone = SelectZone((char)(TargetZone.column - (char)1), TargetZone.row);
         }
         else if (Input.GetButtonDown("Left"))
         {
             TargetZone = SelectZone((char)(TargetZone.column + (char)1), TargetZone.row);
         }
     }
     if (Input.GetButtonDown("Select"))
     {
         zoneSelect = false;
     }
     else if (Input.GetButtonDown("Cancel"))
     {
         pieceSelect = true;
         TargetZone  = null;
         zoneSelect  = false;
     }
     return(TargetZone.GetComponent <ZoneScript>());
 }
Exemplo n.º 3
0
    public static PawnBehaviourScript FindContainedPiece(GameObject zone)
    {
        ZoneScript z = zone.GetComponent <ZoneScript>();

        PawnBehaviourScript[] p = FindObjectsOfType <PawnBehaviourScript>();
        foreach (PawnBehaviourScript piece in p)
        {
            if (piece.currentCol == z.column && piece.currentRow == z.row)
            {
                return(piece);
            }
        }
        return(null);
    }
 void Start()
 {
     // Initialize variables
     player            = GameObject.FindGameObjectWithTag("Player");
     playerController  = player.GetComponent <PlayerController>();
     playerPosition    = player.GetComponent <Transform>();
     startingPosition  = transform.position;
     agent             = GetComponent <NavMeshAgent>();
     agentSpeed        = agent.speed;
     agent.autoBraking = false;
     active            = false;
     agent.speed       = 0;
     zoneControl       = zone.GetComponent <ZoneScript>();
 }
Exemplo n.º 5
0
 void SetDefaultPiece()
 {
     GameObject[] DefaultPiece = GameObject.FindGameObjectsWithTag("King");
     foreach (var king in DefaultPiece)
     {
         if (player1Turn && king.GetComponent <PawnBehaviourScript>().colour == "White")
         {
             SelectedPiece = king;
             SelectedZone  = FindContainingZone(king);
         }
         else if (!player1Turn && king.GetComponent <PawnBehaviourScript>().colour == "Black")
         {
             SelectedPiece = king;
             SelectedZone  = FindContainingZone(king);
         }
     }
 }
Exemplo n.º 6
0
    public void Move(char col, int row)
    {
        GameController.FindContainingZone(this.gameObject).occupado       = false;
        GameController.FindContainingZone(this.gameObject).containedPiece = null;
        ZoneScript TargetZone = GameController.SelectZone(col, row);

        if (TargetZone.occupado)
        {
            PawnBehaviourScript targetPiece = GameController.SelectPiece(col, row);
            targetPiece.gameObject.SetActive(false);
            Destroy(targetPiece.gameObject);
        }
        this.transform.position = TargetZone.gameObject.transform.position;
        this.currentCol         = col;
        this.currentRow         = row;
        //Destroy (this.gameObject);
    }
Exemplo n.º 7
0
        public Zone(byte[][] Zone)
        {
            // A ZO is comprised of 4-5 files.

            // Array 0 is [Map Info]
            ZD = new ZoneData(Zone[0]);
            // Array 1 is [Overworld Entities & their Scripts]
            Entities = new ZoneEntities(Zone[1]);
            // Array 2 is [Map Script]
            MapScript = new ZoneScript(Zone[2]);
            // Array 3 is [Wild Encounters]
            Encounters = new ZoneEncounters(Zone[3]);
            // Array 4 is [???] - May not be present in all.
            if (Zone.Length <= 4) 
                return;
            File5 = new ZoneUnknown(Zone[4]);
        }
Exemplo n.º 8
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Environment")
        {
            ZoneScript zs = other.GetComponent <ZoneScript>();
            wind = zs.WindDIR;
            float x = Vector3.Dot(wind, transform.forward);
            float z = Vector3.Dot(wind, transform.right);
            hair.SetFloat("WindMagnitude", zs.MAGNITUDE);
            hair.SetFloat("WindZ", -x);
            hair.SetFloat("WindX", z);

            cape.externalAcceleration = zs.Wind;
            cape.randomAcceleration   = zs.WindRANDOM;
            zswind   = zs.Wind;
            zdrandom = zs.WindRANDOM;
        }
    }
Exemplo n.º 9
0
        public Zone(byte[][] Zone)
        {
            // A ZO is comprised of 4-5 files.

            // Array 0 is [Map Info]
            Info = new ZoneInfo(Zone[0]);
            // Array 1 is [Overworld Entities & their Scripts]
            Entities = new ZoneEntities(Zone[1]);
            // Array 2 is [Map Script]
            MapScript = new ZoneScript(Zone[2]);
            // Array 3 is [Wild Encounters]
            Encounters = new ZoneEncounters(Zone[3]);
            // Array 4 is [???] - May not be present in all.
            if (Zone.Length <= 4)
                return;
            File5 = new ZoneUnknown(Zone[4]);
        }
Exemplo n.º 10
0
    public void FindNextPiece()
    {
        if (SelectedZone != null)
        {
            Touch  touch     = new Touch();
            string direction = "";
            if (Input.touchCount > 0)
            {
                touch = Input.GetTouch(0);
                switch (touch.phase)
                {
                case TouchPhase.Began:
                    break;

                case TouchPhase.Moved:
                    if (!swiped)
                    {
                        if (touch.deltaPosition.x < 0 && Mathf.Abs(touch.deltaPosition.x) <= Mathf.Abs(touch.deltaPosition.y))
                        {
                            direction = "left";
                        }
                        else if (touch.deltaPosition.x > 0 && Mathf.Abs(touch.deltaPosition.x) <= Mathf.Abs(touch.deltaPosition.y))
                        {
                            direction = "right";
                        }
                        else if (touch.deltaPosition.y > 0 && Mathf.Abs(touch.deltaPosition.x) > Mathf.Abs(touch.deltaPosition.y))
                        {
                            direction = "up";
                        }
                        else if (touch.deltaPosition.y < 0 && Mathf.Abs(touch.deltaPosition.x) > Mathf.Abs(touch.deltaPosition.y))
                        {
                            direction = "down";
                        }
                        swiped = true;
                    }
                    break;

                case TouchPhase.Ended:
                    if (!swiped && touch.deltaTime > 1f)
                    {
                        direction = "select";
                    }
                    break;

                default:
                    break;
                }
            }

            if (player1Turn)
            {
                if (Input.GetButtonDown("Up") || direction == "up" && SelectedZone.row <= 8)
                {
                    SelectedZone = SelectZone(SelectedZone.column, SelectedZone.row + 1);
                }
                else if (Input.GetButtonDown("Down") || direction == "down" && SelectedZone.row > 0)
                {
                    SelectedZone = SelectZone(SelectedZone.column, SelectedZone.row - 1);
                }
                else if (Input.GetButtonDown("Right") || direction == "right" && SelectedZone.column != 'H')
                {
                    SelectedZone = SelectZone((char)(SelectedZone.column + (char)1), SelectedZone.row);
                }
                else if (Input.GetButtonDown("Left") || direction == "left" && SelectedZone.column != 'A')
                {
                    SelectedZone = SelectZone((char)(SelectedZone.column - (char)1), SelectedZone.row);
                }
                if (Input.GetButtonDown("Select") && SelectedZone.occupado && SelectedZone.containedPiece.colour == "White")
                {
                    SelectedPiece = SelectedZone.containedPiece.gameObject;
                    pieceSelect   = false;
                    zoneSelect    = true;
                }
            }
            else
            {
                if (Input.GetButtonDown("Down"))
                {
                    SelectedZone = SelectZone(SelectedZone.column, SelectedZone.row + 1);
                }
                else if (Input.GetButtonDown("Up"))
                {
                    SelectedZone = SelectZone(SelectedZone.column, SelectedZone.row - 1);
                }
                else if (Input.GetButtonDown("Left"))
                {
                    SelectedZone = SelectZone((char)(SelectedZone.column + (char)1), SelectedZone.row);
                }
                else if (Input.GetButtonDown("Right"))
                {
                    SelectedZone = SelectZone((char)(SelectedZone.column - (char)1), SelectedZone.row);
                }
                if (Input.GetButtonDown("Select") && SelectedZone.occupado && SelectedZone.containedPiece.colour == "Black")
                {
                    SelectedPiece = SelectedZone.containedPiece.gameObject;
                    pieceSelect   = false;
                    zoneSelect    = true;
                }
            }
        }
        else if (SelectedPiece != null)
        {
            SelectedZone = FindContainingZone(SelectedPiece);
        }
    }
Exemplo n.º 11
0
    void GetPlayerMove()
    {
        // TODO Controller input
        if (Mathf.Abs(Input.GetAxis("Vertical")) == 1.0F || Mathf.Abs(Input.GetAxis("Horizontal")) == 1.0F)
        {
            Debug.Log("Sorry, controller input not yet supported.");
        }


        // Select default piece (king), if none selected
        if (SelectedPiece == null)
        {
            SetDefaultPiece();
        }
        // Game is over if a king can't be selected
        if (SelectedPiece == null)
        {
            GameOver();
        }

        PawnBehaviourScript piece = SelectedPiece.GetComponent <PawnBehaviourScript>();

        try
        {
            if (pieceSelect)
            {
                FindNextPiece();
            }
            else if (zoneSelect)
            {
                // Default zone is one contining selected piece
                if (TargetZone == null)
                {
                    TargetZone = SelectZone(piece.currentCol, piece.currentRow);
                }
                FindNextZone(ref TargetZone);

                //A piece and zone have been selected
                if (!pieceSelect && !zoneSelect)
                {
                    if (piece.CheckMove(TargetZone))
                    {
                        piece.Move(TargetZone.column, TargetZone.row);
                        TargetZone.AcceptPiece(piece);
                        //                            string move = piece.name + "," + TargetZone.column + TargetZone.row + "\n";
                        // TODO SaveLoad.Update(move);
                        piece         = null;
                        TargetZone    = null;
                        SelectedZone  = null;
                        SelectedPiece = null;
                        pieceSelect   = true;
                        if (player1Turn)
                        {
                            Player(2);
                        }
                        else
                        {
                            Player(1);
                        }
                    }
                    else
                    {
                        Debug.Log("Not a valid move");
                        TargetZone = SelectZone(piece.currentCol, piece.currentRow);
                        zoneSelect = true;
                    }
                }
            }
        }
        catch (System.NullReferenceException ex)
        {
            Debug.Log("Nope, nothing there. " + ex.HelpLink);
            nope.Play();
        }
        catch (System.Exception ex)
        {
            Debug.Log("Something went wrong between selecting a zone/piece and making a move. " + ex.HelpLink);
        }
    }
Exemplo n.º 12
0
    public bool CheckMove(ZoneScript target)
    {
        int distanceCol = Mathf.Abs((int)currentCol - (int)target.column);
        int distanceRow = Mathf.Abs(currentRow - target.row);

        switch (this.tag)
        {
        case "Pawn":
            /*** Pawn taking another piece ***/
            //Either side of the pawn and occupied
            if ((target.column == currentCol + (char)1 || target.column == currentCol - (char)1) && target.occupado)
            {
                // Pawn is white and target is diagonal in correct direction
                if (colour == "White" && target.row == currentRow + 1)
                {
                    // Target is black
                    if (target.containedPiece.colour == "Black")
                    {
                        firstMove = false;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                // Pawn is black and target is diagonal in correct direction
                else if (colour == "Black" && target.row == currentRow - 1)
                {
                    // Target is white
                    if (target.containedPiece.colour == "White")
                    {
                        firstMove = false;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            /*** Pawn moving straight***/
            else if (target.column == currentCol)
            {
                // Pawn is white and moving one place
                if (colour == "White" && target.row == currentRow + 1)
                {
                    if (!target.occupado)
                    {
                        firstMove = false;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                // Pawn is white, on its first turn and moving two places
                else if (colour == "White" && target.row == currentRow + 2 && firstMove)
                {
                    // Check two places are clear
                    if (IsOccupied(target.column, target.row - 1) || IsOccupied(target.column, target.row))
                    {
                        return(false);
                    }
                    else
                    {
                        firstMove = false;
                        return(true);
                    }
                }
                // Pawn is black and moving one place
                else if (colour == "Black" && target.row == currentRow - 1)
                {
                    if (!target.occupado)
                    {
                        firstMove = false;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                // Pawn is black, on its first turn and moving two places
                else if (colour == "Black" && target.row == currentRow - 2 && firstMove)
                {
                    // Check two places are clear
                    if (IsOccupied(target.column, target.row + 1) || IsOccupied(target.column, target.row))
                    {
                        return(false);
                    }
                    else
                    {
                        firstMove = false;
                        return(true);
                    }
                }
                return(false);
            }
            break;

        case "Rook":
            /*** Rook movement ***/
            // Rook isn't trying to take a piece of the same colour
            if (target.occupado && target.containedPiece.colour == colour)
            {
                return(false);
            }
            // Target is in same row
            if (target.row == currentRow)
            {
                // Check places between piece and target are vacant
                int distance = ((int)target.column - (int)currentCol);
                for (int i = 1; i < Mathf.Abs(distance); i++)
                {
                    if (distance > 0)
                    {
                        if (IsOccupied((char)(currentCol + (char)i), currentRow))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (IsOccupied((char)(currentCol - (char)i), currentRow))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            // Target is in same column
            else if (target.column.Equals(currentCol))
            {
                // Check places between piece and target are vacant
                int distance = target.row - currentRow;
                for (int i = 1; i < Mathf.Abs(distance); i++)
                {
                    if (distance > 0)
                    {
                        if (IsOccupied(currentCol, currentRow + i))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (IsOccupied(currentCol, currentRow - i))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            break;

        case "Bishop":
            /*** Bishop movement ***/
            // Bishop isn't trying to take a piece of the same colour
            if (target.occupado && target.containedPiece.colour == colour)
            {
                return(false);
            }
            // Target is diagonal to bishop
            if (distanceCol == distanceRow)
            {
                // Determine direction of target
                if ((int)currentCol < target.column && currentRow < target.row)
                {     // up-left
                    for (int i = 1; i < distanceCol; i++)
                    {
                        if (IsOccupied((char)(currentCol + (char)i), currentRow + i))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else if ((int)currentCol > target.column && currentRow < target.row)
                {     // up-right
                    for (int i = 1; i < distanceCol; i++)
                    {
                        if (IsOccupied((char)(currentCol - (char)i), currentRow + i))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else if ((int)currentCol < target.column && currentRow > target.row)
                {     // down-left
                    for (int i = 1; i < distanceCol; i++)
                    {
                        if (IsOccupied((char)(currentCol + (char)i), currentRow - i))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else
                {     // down-right
                    for (int i = 1; i < distanceCol; i++)
                    {
                        if (IsOccupied((char)(currentCol - (char)i), currentRow - i))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            }
            break;

        case "Knight":
            /*** Knight movement ***/
            // Knight isn't trying to take a piece of the same colour
            if (target.occupado && target.containedPiece.colour == colour)
            {
                return(false);
            }
            int vertDistance = Mathf.Abs((int)currentCol - (int)target.column);
            int horDistance  = Mathf.Abs(currentRow - target.row);
            if ((vertDistance == 1 && horDistance == 2) || (vertDistance == 2 && horDistance == 1))
            {
                return(true);
            }
            break;

        case "Queen":
            /*** Queen movement ***/
            // Queen isn't trying to take a piece of the same colour
            if (target.occupado && target.containedPiece.colour == colour)
            {
                return(false);
            }
            // Target is in same row
            if (target.row == currentRow)
            {
                // Check places between piece and target are vacant
                int distance = ((int)target.column - (int)currentCol);
                for (int i = 1; i < Mathf.Abs(distance); i++)
                {
                    if (distance > 0)
                    {
                        if (IsOccupied((char)(currentCol + (char)i), currentRow))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (IsOccupied((char)(currentCol - (char)i), currentRow))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            // Target is in same column
            else if (target.column.Equals(currentCol))
            {
                // Check places between piece and target are vacant
                int distance = (target.row - currentRow);
                for (int i = 1; i < Mathf.Abs(distance); i++)
                {
                    if (distance > 0)
                    {
                        if (IsOccupied((char)currentCol, currentRow + i))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (IsOccupied((char)(currentCol), currentRow - i))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            // Target is diagonal to queen
            else if (distanceCol == distanceRow)
            {
                // Determine direction of target
                if ((int)currentCol < target.column && currentRow < target.row)
                {     // up-left
                    for (int i = 1; i < distanceCol; i++)
                    {
                        if (IsOccupied((char)(currentCol + (char)i), currentRow + i))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else if ((int)currentCol > target.column && currentRow < target.row)
                {     // up-right
                    for (int i = 1; i < distanceCol; i++)
                    {
                        if (IsOccupied((char)(currentCol - (char)i), currentRow + i))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else if ((int)currentCol < target.column && currentRow > target.row)
                {     // down-left
                    for (int i = 1; i < distanceCol; i++)
                    {
                        if (IsOccupied((char)(currentCol + (char)i), currentRow - i))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else
                {     // down-right
                    for (int i = 1; i < distanceCol; i++)
                    {
                        if (IsOccupied((char)(currentCol - (char)i), currentRow - i))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            }
            break;

        case "King":
            /*** King movement ***/
            // King isn't trying to take a piece of the same colour
            if (target.occupado && target.containedPiece.colour == colour)
            {
                return(false);
            }
            if ((distanceCol == 0 && distanceRow == 1) || (distanceCol == 1 && distanceRow == 0) || (distanceCol == 1 && distanceRow == 1))
            {
                return(true);
            }
            break;

        default:
            break;
        }
        return(false);
    }