예제 #1
0
 bool OrtogonalCheck(PlayerScript player, TileScript tileSelect)
 {
     if (player.GetWidth() + 1 == tileSelect.GetWidth() || player.GetWidth() - 1 == tileSelect.GetWidth())
     {
         if (player.GetHeigth() == tileSelect.GetHeigth())
         {
             return(true);
         }
     }
     else
     {
         if (player.GetHeigth() + 1 == tileSelect.GetHeigth() || player.GetHeigth() - 1 == tileSelect.GetHeigth())
         {
             if (player.GetWidth() == tileSelect.GetWidth())
             {
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (gameStatus == GameStatusEnum.Game)
        {
            if (Input.GetMouseButtonDown(0) && players[playerTurn].GetComponent <PlayerScript>().CurrentMovementPlayer > 0)
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    TileScript tileSelect = null;
                    if (hit.collider.gameObject.GetComponent <TileScript>() != null)
                    {
                        tileSelect = hit.collider.gameObject.GetComponent <TileScript>();
                        Debug.Log(tileSelect.GetWidth() + " " + tileSelect.GetHeigth());
                        bool approvedMove = OrtogonalCheck(players[playerTurn].GetComponent <PlayerScript>(), tileSelect);
                        if (hit.collider.gameObject.transform.childCount == 1 && approvedMove)
                        {
                            players[playerTurn].GetComponent <PlayerScript>().CurrentMovementPlayer -= 1;
                            gameStatus = GameStatusEnum.MovementPlayer;
                            players[playerTurn].GetComponent <PlayerScript>().SetDestinyPlayer(hit.collider.gameObject);
                            bool isColetable = players[playerTurn].GetComponent <PlayerScript>().CollectColetable();
                            if (isColetable)
                            {
                                numberCollectable--;
                                int percentual = PercentualRateCollectable();
                                if (percentual <= 10)
                                {
                                    RefillColletable();
                                }
                                gameCanvas.PlayerMovementUI(players[playerTurn].GetComponent <PlayerScript>().CurrentMovementPlayer, turno.ToString());
                                if (playerTurn == 0)
                                {
                                    gameCanvas.Player1UI(players[playerTurn].GetComponent <PlayerScript>());
                                }
                                else
                                {
                                    gameCanvas.Player2UI(players[playerTurn].GetComponent <PlayerScript>());
                                }
                            }
                            gameCanvas.PlayerMovementUI(players[playerTurn].GetComponent <PlayerScript>().CurrentMovementPlayer, turno.ToString());
                        }
                        else
                        {
                            Debug.Log("Nao Posso mover");
                        }
                    }
                }
            }
        }
        if (gameStatus == GameStatusEnum.MovementPlayer)
        {
            if (!players[playerTurn].GetComponent <PlayerScript>().IsMove)
            {
                if (OrtogonalCheckBattle(players))
                {
                    gameCanvas.ActivateBattleUI(players, playerTurn);
                    if (playerTurn == 0)
                    {
                        battleSystem.InitiateBattleSystem(3, players[0].GetComponent <PlayerScript>(), players[1].GetComponent <PlayerScript>());
                    }
                    else
                    {
                        battleSystem.InitiateBattleSystem(3, players[1].GetComponent <PlayerScript>(), players[0].GetComponent <PlayerScript>());
                    }
                    gameStatus = GameStatusEnum.Battle;
                }
                else
                {
                    gameStatus = GameStatusEnum.Game;
                    if (players[playerTurn].GetComponent <PlayerScript>().CurrentMovementPlayer == 0)
                    {
                        players[playerTurn].GetComponent <PlayerScript>().ReinitiateAttack();
                        ChangeTurn();
                        ChangeCamFollow();
                        gameCanvas.PlayerMovementUI(players[playerTurn].GetComponent <PlayerScript>().CurrentMovementPlayer, turno.ToString());
                        gameCanvas.Player1UI(players[0].GetComponent <PlayerScript>());
                        gameCanvas.Player2UI(players[1].GetComponent <PlayerScript>());
                    }
                }
            }
        }
        if (gameStatus == GameStatusEnum.Battle)
        {
            if (!gameCanvas.battleCanvas.activeSelf)
            {
                if (players[playerTurn].GetComponent <PlayerScript>().CurrentMovementPlayer == 0)
                {
                    players[playerTurn].GetComponent <PlayerScript>().ReinitiateAttack();
                    ChangeTurn();
                    ChangeCamFollow();
                    gameCanvas.PlayerMovementUI(players[playerTurn].GetComponent <PlayerScript>().CurrentMovementPlayer, turno.ToString());
                }
                gameCanvas.Player1UI(players[0].GetComponent <PlayerScript>());
                gameCanvas.Player2UI(players[1].GetComponent <PlayerScript>());

                if (players[0].GetComponent <PlayerScript>().CurrentHealthPlayer <= 0 || players[1].GetComponent <PlayerScript>().CurrentHealthPlayer <= 0)
                {
                    gameCanvas.ActiveEndGameUI();
                    if (players[0].GetComponent <PlayerScript>().CurrentHealthPlayer <= 0)
                    {
                        gameCanvas.WinnerUIEndGame(players[1].GetComponent <PlayerScript>());
                    }
                    else
                    {
                        gameCanvas.WinnerUIEndGame(players[0].GetComponent <PlayerScript>());
                    }
                }
                else
                {
                    gameStatus = GameStatusEnum.Game;
                }
            }
        }
    }