Example #1
0
    //Handles spawning Finite State machine for all players
    void FiniteStateMachine(PlayerData data)
    {
        playingState playerState     = data.State;
        float        inactivityTimer = data.InactivityTimer;
        int          playerNumber    = data.PlayerID;

        //Handles InActive state => Started Pressed, goes to Active
        if (data.State == playingState.InActive)
        {
            bool playerStartPressed = Input.GetButton("Start" + playerNumber);
            if (playerStartPressed)
            {
                if (!data.IsCreated)
                {
                    SpawnPlayer(data);
                }
                data.State = playingState.Active;
            }
        }

        //Handles Active state => If x time inActivity go to InBetween
        if (playerState == playingState.Active)
        {
            float playerActivity = Input.GetAxis("Horizontal" + playerNumber);

            //reset if there's activity.
            if (playerActivity != 0)
            {
                data.InactivityTimer = 0;
            }
            //else keep counting
            else
            {
                data.InactivityTimer += Time.deltaTime;
            }

            //go to inbetween if we're past our limit.
            if (inactivityTimer >= MaxInactivitySeconds)
            {
                data.InactivityTimer = 0;
                data.State           = playingState.InBetween;
            }
        }

        //Handles InBetween state => Cleans up unused player
        if (playerState == playingState.InBetween)
        {
            data.Player.SetActive(false);
            data.State = playingState.InActive;
            _activePlayers.Remove(data);
            int team = data.PC.TeamID;
            _teamSizes[team]--;
        }
    }
Example #2
0
    //Handles spawning Finite State machine for all players
    void FiniteStateMachine(ref playingState player_State, ref float inactivity_timer, int playerNumber)
    {
        //Handles InActive state => Started Pressed, goes to Active
        if (player_State == playingState.InActive)
        {
            bool player_StartPressed = Input.GetButton("Start" + playerNumber);
            if (player_StartPressed)
            {
                SpawnPlayer(playerNumber);
                player_State = playingState.Active;
            }
        }

        //Handles Active state => If x time inActivity go to InBetween
        if (player_State == playingState.Active)
        {
            float player_activity = Input.GetAxis("Horizontal" + playerNumber);
            if (player_activity != 0)
            {
                inactivity_timer = 0;
            }
            else
            {
                inactivity_timer += Time.deltaTime;
            }

            if (inactivity_timer >= maxInactivitytime)
            {
                inactivity_timer = 0;
                player_State     = playingState.InBetween;
            }
        }

        //Handles InBetween state => Cleans up unused player
        if (player_State == playingState.InBetween)
        {
            foreach (GameObject player in spawnedPlayers)
            {
                PlayerController playerScript = player.GetComponent("PlayerController") as PlayerController;
                if (playerScript.PlayerNumber == playerNumber)
                {
                    player.SetActive(false);
                    player_State = playingState.InActive;
                    return;
                }
            }
        }
    }