Exemplo n.º 1
0
    /// <summary>
    /// Awake function to Create the appropriate number of players depending on
    /// whether there are 1 or two players setup for play from the lobby.
    /// </summary>
    void Awake()
    {
        //pauseCanvas.enabled = false;
        //pauseCanvas.SetActive(false);

        switch (StaticSpawnController.GetSetPlayers())
        {
        case 0:    //no players added.
            Debug.Log("Entry Error at Lobby. Generic First player added.");
            //Adding the new character for testing of levels.
            CreatePlayer1();
            //CreatePlayer2();
            break;

        case 1:    //just the first player
            CreatePlayer1();
            break;

        case 2:    //just the second player added
            CreatePlayer2();
            break;

        case 3:    //both players added
            CreatePlayer1();
            CreatePlayer2();
            break;

        default:    //error with read
            Debug.Log("Error reading set players. First Player added.");
            CreatePlayer1();
            break;
        }
    }
Exemplo n.º 2
0
    /// <summary>
    ///
    /// </summary>
    // Update is called once per frame
    void Update()
    {
        switch (StaticSpawnController.GetSetPlayers())
        {
        case 0:    //neither player is active. all items are blanked out
            player1Join.SetActive(false);
            player2Join.SetActive(false);
            startCommand.SetActive(false);
            break;

        case 1:    //player one is active while player 2 is not
            player1Join.SetActive(true);
            player2Join.SetActive(false);
            startCommand.SetActive(true);
            break;

        case 2:    //player two is active while player 1 is not
            player1Join.SetActive(false);
            player2Join.SetActive(true);
            startCommand.SetActive(true);
            break;

        case 3:    //player one and two are both active.
            player1Join.SetActive(true);
            player2Join.SetActive(true);
            startCommand.SetActive(true);
            break;

        default:
            break;
        }
    }
Exemplo n.º 3
0
 /// <summary>
 /// starts with setting all highlights to false and sets the player to inactive.
 /// </summary>
 void Start()
 {
     StartHighlight.enabled   = false;
     OptionsHighlight.enabled = false;
     BackHighlight.enabled    = false;
     QuitHighlight.enabled    = false;
     StaticSpawnController.ActivatePlayer(playerIndex, false);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Loads the First Level
 /// </summary>
 public static void _Level1Scene()
 {
     if (StaticSpawnController.GetSetPlayers() != 0)
     {
         Debug.Log("Starting Level...");
         SceneManager.LoadScene("test_level_FINAL");
     }
     else
     {
         Debug.Log("Needs at least one player entered.");
     }
 }
Exemplo n.º 5
0
    /// <summary>
    /// reads controller inputs
    /// </summary>
    void Update()
    {
        //grab the current state
        currentState = GamePad.GetState(playerIndex);
        //if start button was just pressed.
        if (currentState.Buttons.Start == ButtonState.Pressed && previousState.Buttons.Start == ButtonState.Released)
        {
            //call activate button.
            Debug.Log("Start Button Pressed.");
            ActivateButton();
        }

        //check to see if the player pushed the A button
        if (currentState.Buttons.A == ButtonState.Pressed)
        {
            //set current player as active.
            int activateCheck = StaticSpawnController.GetSetPlayers();
            StaticSpawnController.ActivatePlayer(playerIndex, true);

            //if is player 1 and not active or is player 2 and not active
            if ((playerIndex == PlayerIndex.One && activateCheck != 1 && activateCheck != 3) ||
                (playerIndex == PlayerIndex.Two && activateCheck != 2 && activateCheck != 3))
            {
                //set the toSelect button so start button presses can now be used
                toSelect = StartGameButton;
                //set start hi
                StartHighlight.enabled = true;
            }
        }

        //NOTE:  Doesn't work with some XInput emulated device drivers like the popular PS3 Controller one
        //destroy the player instance if the controller disconnects
        if (currentState.IsConnected == false)
        {
            //if player controller disconnects at the lobby, remove them from the active script.
            StaticSpawnController.ActivatePlayer(playerIndex, false);
            if (StaticSpawnController.GetSetPlayers() == 0)
            {
                toSelect = null;
                StartHighlight.enabled = false;
            }
            //text.enabled = true;
            return;
        }
        else
        {
            //call action selection
            ActionSelection();


            //remove the player call if the player pushed the Back button
            if (currentState.Buttons.Back == ButtonState.Pressed)
            {
                //check for players
                int removeCheck = StaticSpawnController.GetSetPlayers();
                //if appropriate player is activated when they hit the back button,
                if ((playerIndex == PlayerIndex.One && removeCheck != 0 && removeCheck != 2) ||
                    (playerIndex == PlayerIndex.Two && removeCheck != 0 && removeCheck != 1))
                {
                    //set that player to false
                    StaticSpawnController.ActivatePlayer(playerIndex, false);
                    //text.enabled = true;
                    //set screen to null the toSelect button and highlighters if there
                    //are no active players
                    if (StaticSpawnController.GetSetPlayers() == 0)
                    {
                        toSelect = null;
                        StartHighlight.enabled = false;
                    }
                    return;
                }
            }
            //update packet numbers
            if (currentState.PacketNumber > lastPacketNumber)
            {
                lastPacketNumber = currentState.PacketNumber;
                lastPacketTime   = Time.time;
            }
            else
            {
                //NOTE:  Doesn't work with some XInput emulated device drivers like the popular PS3 Controller one
                if (Time.time - lastPacketTime > 10)
                {
                    //controller has been idle for 10 seconds
                }
            }
        }
        //Set the previous state to the current state and run the set Highlighter.
        previousState = currentState;
        SetHighlighter();
    }