Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        stateHandeler = new StateHandeler(states, startingState);
        RegisterEvents();

        gr = gameRulesPrefab.GetComponent <GameRules>();
        gr.Init(stateHandeler);

        BuildGame();

        nextState = stateHandeler.StateChange();
    }
Example #2
0
    void Update()
    {
        if (stateHandeler == null)
        {
            return;
        }

        if (stateHandeler.currentState.ID == "Start")
        {
            CheckForPlayers();
        }

        if (stateHandeler.currentState.ID == "Lobby")
        {
            var elapse = lobbyTimer.RecordTime(Time.fixedDeltaTime);
            int ct     = (int)currentLobbyTime - (int)elapse;

            lobbyTimerText.text = ":" + ct;

            if (lobbyTimer.IsDone())
            {
                nextState = stateHandeler.StateChange();
            }
        }

        if (stateHandeler.currentState.ID == "SetUp")
        {
            if (!gameStartTimer.IsDone())
            {
                var elapse = gameStartTimer.RecordTime(Time.fixedDeltaTime);
                int ct     = (int)currentMathcStartTime - (int)elapse;
                launchText.text = ":" + ct;
            }

            if (gameStartTimer.IsDone() && !allPlayersReady)
            {
                allPlayersReady = true;
                player1Ready    = true;
                player2Ready    = true;

                var roll = Random.Range(0, 1);
                Debug.Log(roll);
                UnityEngine.InputSystem.Gamepad ag = roll > .5f ? Gamepad.all[0] : Gamepad.all[1];
                SetActivePlayer(ag);
                StartMatch();
            }

            var p1South = Gamepad.all[0].buttonSouth.ReadValue() > 0 ? true : false;
            var p2South = Gamepad.all[1].buttonSouth.ReadValue() > 0 ? true : false;

            if (p1South && !allPlayersReady)
            {
                allPlayersReady = true;
                player1Ready    = true;
                player2Ready    = true;

                SetActivePlayer(Gamepad.all[0]);
                StartMatch();
            }

            if (p2South && !allPlayersReady)
            {
                allPlayersReady = true;
                player1Ready    = true;
                player2Ready    = true;

                SetActivePlayer(Gamepad.all[1]);
                StartMatch();
            }
        }

        if (stateHandeler.currentState.ID == "Main")
        {
            UpdatePlayerStats();

            if (!matchTimer.IsDone())
            {
                var elapse = matchTimer.RecordTime(Time.fixedDeltaTime);
                int ct     = (int)currentMatchTimer - (int)elapse;
                matchTimerText.text = ":" + ct;

                var rte             = roundTimer.RecordTime(Time.fixedDeltaTime);
                var timeLeftInround = currentRoundTimer - rte;

                if (roundTimer.IsDone())
                {
                    if (activePlayer.id == player1.id)
                    {
                        player1.SetActiveTeam(false);
                        player2.SetActiveTeam(true);
                        activePlayer = player2;
                    }
                    else if (activePlayer.id == player2.id)
                    {
                        player2.SetActiveTeam(false);
                        player1.SetActiveTeam(true);
                        activePlayer = player1;
                    }
                    SetActivePlayer(activePlayer);
                    currentRoundTimer = roundTimerInSeconds;
                    roundTimer.SetTimer(roundTimerInSeconds);
                }

                //spawn mobs
            }
        }
    }