private void RandomizeSwipes(VPlayer player)
    {
        // First Swipe
        int    i       = Random.Range(0, swipesAvailable.Count);
        string element = swipesAvailable[i];

        swipesUsed.Add(element);
        swipesAvailable.Remove(element);
        player.ShowElement("Bottom_Left");
        player.ChangeElementText("Bottom_Left", element);

        // Second Swipe
        i       = Random.Range(0, swipesAvailable.Count);
        element = swipesAvailable[i];
        swipesUsed.Add(element);
        swipesAvailable.Remove(element);
        player.ShowElement("Bottom_Right");
        player.ChangeElementText("Bottom_Right", element);
    }
    private void RandomizeButtons(VPlayer player)
    {
        // First Button
        int    i       = Random.Range(0, buttonsAvailable.Count);
        string btnText = buttonsAvailable[i];

        buttonsUsed.Add(btnText);
        buttonsAvailable.Remove(btnText);
        player.ShowElement("Top_Left");
        player.ChangeElementText("Top_Left", btnText);
        // Move button to correct spot.

        // Second Button
        i       = Random.Range(0, buttonsAvailable.Count);
        btnText = buttonsAvailable[i];
        buttonsUsed.Add(btnText);
        buttonsAvailable.Remove(btnText);
        player.ShowElement("Top_Right");
        player.ChangeElementText("Top_Right", btnText);
        // Move button to correct spot.
    }
Ejemplo n.º 3
0
        /// <summary>
        /// 'Volplane.OnConnect()' method from the Volplane framework
        /// OnConnect is called when a new AirConsole player joins the session.
        /// </summary>
        /// <param name="player">The player object of the connected device.</param>
        private void OnConnect(VPlayer player)
        {
            // Set player inactive if it is active and game not started yet
            if (player.IsActive && !gameStarted)
            {
                player.SetActive(false);
            }

            // You will not receive any input from inactive players.
            // By default every new connected player will be set as inactive, with the exception
            // of the game master. The game master (AirConsoles master device) is the one who is able
            // to navigate on the AirConsole platform.

            // Display a text on the controller indicating which racket this player will play
            if (player.PlayerId == 0)
            {
                player.ChangeElementText("infoText", "You are on the left...");
            }
            else
            {
                player.ChangeElementText("infoText", "You are on the right...");
            }

            // In this example, the player with the id 0 will play the left racket, the player
            // with the id 1 will play the right one.
            // Remember: The game master may not necessarily have an id of 0. The player id are ordered
            // by whichever device connects first. However player ids can be hardcoded. For example if
            // the game master has the player id 3 and suddenly looses connection, on a rejoin, the
            // controller will be reassigned to this id and player object.

            // Update pause text with the current player count
            pauseText.text = string.Format("{0} Players connected\nWaiting for more players...", PlayerCount);

            // When two players are connected and game has not started yet
            // -> let's go
            if ((PlayerCount == 2) && !gameStarted)
            {
                StartGame();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 'MonoBehaviour.Update()' method from Unity
        /// Update is called every frame, if the MonoBehaviour is enabled.
        /// </summary>
        private void Update()
        {
            // Switch through the possible player colors (left)
            if (VInput.GetButtonDown(playerId, "colorChangeLeft"))
            {
                if (currentColor == PlayerColors.Red)
                {
                    currentColor = PlayerColors.Black;
                }
                else
                {
                    currentColor--;
                }

                ApplyColor(currentColor);
            }

            // Switch through the possible player colors (right)
            if (VInput.GetButtonDown(playerId, "colorChangeRight"))
            {
                if (currentColor == PlayerColors.Black)
                {
                    currentColor = PlayerColors.Red;
                }
                else
                {
                    currentColor++;
                }

                ApplyColor(currentColor);
            }

            // Toggle this players ready state
            if (VInput.GetButtonDown(playerId, "submitButton"))
            {
                // Get the Volplane player object from this player
                VPlayer thisDevice = GetPlayer(playerId);

                if (!IsReady)
                {
                    // This player is ready!

                    // Hide elements for choosing colors and indicate that the player is ready
                    thisDevice.HideElement("colorChangeLeft");
                    thisDevice.HideElement("colorChangeRight");
                    thisDevice.HideElement("colorText");
                    thisDevice.ChangeElementText("infoText", "Waiting for game to start...");
                    thisDevice.ChangeElementText("submitButton", "Cancel");

                    if (playerText != null)
                    {
                        playerText.text = GetPlayer(playerId).Nickname + "\n(Ready)";
                    }

                    IsReady = true;

                    // Try to start the game by calling the lobbys 'StartGame()' method
                    GameObject.FindWithTag("Lobby").GetComponent <Lobby>().StartGame();
                }
                else
                {
                    // This player is still not ready after all...

                    // Give the player ability to choose its color again
                    thisDevice.ShowElement("colorChangeLeft");
                    thisDevice.ShowElement("colorChangeRight");
                    thisDevice.ShowElement("colorText");
                    thisDevice.ChangeElementText("infoText", "Choose your color!");
                    thisDevice.ChangeElementText("submitButton", "Ready");

                    if (playerText != null)
                    {
                        playerText.text = GetPlayer(playerId).Nickname + "\n(Waiting)";
                    }

                    IsReady = false;
                }
            }

            // Players can move when game starts
            // -> the element 'joystick' lies on the game view
            transform.Translate(new Vector3(
                                    VInput.GetAxis(playerId, "joystick", VInput.Axis.Horizontal),
                                    0f,
                                    VInput.GetAxis(playerId, "joystick", VInput.Axis.Vertical)
                                    ).normalized * 0.1f);
        }