Exemplo n.º 1
0
    private void player3AvatarSelectionListener()
    {
        if (GamepadManagement.getStateByUserNumber(2).DPad.Left == ButtonState.Released && GamepadManagement.getPrevStateByUserNumber(2).DPad.Left == ButtonState.Pressed)
        {
            //Toggle off the current avatar
            avatars3[indexAvatar3].SetActive(false);

            indexAvatar3--;
            if (indexAvatar3 < 0)
            {
                indexAvatar3 = avatars3.Length - 1;
            }

            //Toggle on the new avatar
            avatars3[indexAvatar3].SetActive(true);
        }
        if (GamepadManagement.getStateByUserNumber(2).DPad.Right == ButtonState.Released && GamepadManagement.getPrevStateByUserNumber(2).DPad.Right == ButtonState.Pressed)
        {
            //Toggle off the current avatar
            avatars3[indexAvatar3].SetActive(false);

            indexAvatar3++;
            if (indexAvatar3 >= avatars3.Length)
            {
                indexAvatar3 = 0;
            }

            //Toggle on the new avatar
            avatars3[indexAvatar3].SetActive(true);
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //GamepadManagement.getStateByUserNumber(2).DPad.Left == XInputDotNetPure.ButtonState.Pressed

        if (GamepadManagement.GamepadConnectedNumber() + 1 == 1)
        {
            hide1.SetActive(true);
            hide2.SetActive(true);
            hide3.SetActive(true);
        }
        if (GamepadManagement.GamepadConnectedNumber() + 1 == 2)
        {
            hide1.SetActive(false);
            hide2.SetActive(true);
            hide3.SetActive(true);
        }
        if (GamepadManagement.GamepadConnectedNumber() + 1 == 3)
        {
            hide1.SetActive(false);
            hide2.SetActive(false);
            hide3.SetActive(true);
        }
        if (GamepadManagement.GamepadConnectedNumber() + 1 == 4)
        {
            hide1.SetActive(false);
            hide2.SetActive(false);
            hide3.SetActive(false);
        }

        if (GamepadManagement.GamepadConnectedNumber() + 1 == 4)
        {
            player4AvatarSelectionListener();
        }
        if (GamepadManagement.GamepadConnectedNumber() + 1 >= 3)
        {
            player3AvatarSelectionListener();
        }
        if (GamepadManagement.GamepadConnectedNumber() + 1 >= 2)
        {
            player2AvatarSelectionListener();
        }
        if (GamepadManagement.GamepadConnectedNumber() + 1 >= 1)
        {
            player1AvatarSelectionListener();
        }

        if (GamepadManagement.GamepadConnectedNumber() + 1 < 2)
        {
            start.interactable = false;
        }
        else
        {
            start.interactable = true;
        }

        if (Input.GetButtonDown("Cancel"))
        {
            SceneManager.LoadScene("createMultiLocal");
        }
    }
Exemplo n.º 3
0
    private void player4AvatarSelectionListener()
    {
        if (GamepadManagement.getStateByUserNumber(3).DPad.Left == ButtonState.Released && GamepadManagement.getPrevStateByUserNumber(3).DPad.Left == ButtonState.Pressed)
        {
            //Toggle off the current avatar
            avatars4[indexAvatar4].SetActive(false);

            indexAvatar4--;
            if (indexAvatar4 < 0)
            {
                indexAvatar4 = avatars4.Length - 1;
            }

            //Toggle on the new avatar
            avatars4[indexAvatar4].SetActive(true);
        }
        if (GamepadManagement.getStateByUserNumber(3).DPad.Left == ButtonState.Released && GamepadManagement.getPrevStateByUserNumber(3).DPad.Left == ButtonState.Pressed)
        {
            //Toggle off the current avatar
            avatars4[indexAvatar4].SetActive(false);

            indexAvatar4++;
            if (indexAvatar4 >= avatars4.Length)
            {
                indexAvatar4 = 0;
            }

            //Toggle on the new avatar
            avatars4[indexAvatar4].SetActive(true);
        }
    }
Exemplo n.º 4
0
    public void goToNextScene()
    {
        if (cooperationMode.isOn)
        {
            LevelParam.Set("mode", "coop");
            if (difficultyNormal.isOn)
            {
                LevelParam.Set("difficulty", "normal");
            }
            else
            {
                LevelParam.Set("difficulty", "hard");
            }
        }
        else
        {
            LevelParam.Set("mode", "versus");
        }

        LevelParam.Set("levelNumber", indexLevel + 1.ToString());
        int numberOfPlayer = 1 + GamepadManagement.GamepadConnectedNumber();

        LevelParam.Set("numberOfPlayer", "" + numberOfPlayer);

        SceneManager.LoadScene("avatarSelection", LoadSceneMode.Additive);
    }
Exemplo n.º 5
0
    void Update()
    {
        Item item = inventory.GetCurrentItem();

        if (item != null)
        {
            spriteRenderer.sprite = item.descriptionSprite;
        }
        else
        {
            spriteRenderer.sprite = null;
        }

        Vector2 mousePos;

        if (userNumber == 0) //Mouse
        {
            mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }
        else //Gamepad
        {
            mousePos = new Vector2(character.position.x + GamepadManagement.getStateByUserNumber(userNumber).ThumbSticks.Right.X, character.position.y + GamepadManagement.getStateByUserNumber(userNumber).ThumbSticks.Right.Y);
        }



        direction = (mousePos - character.position).normalized;

        if (userNumber == 0) //Mouse
        {
            angle = GetAngle(character.position, mousePos);
            //Debug.Log("Mouse angle = " + GetAngle(character.position, mousePos));
        }
        else //Gamepad
        {
            Vector2 stickVector = new Vector2(character.position.x + GamepadManagement.getStateByUserNumber(userNumber).ThumbSticks.Right.X, character.position.y + GamepadManagement.getStateByUserNumber(userNumber).ThumbSticks.Right.Y);
            angle = GetAngle(character.position, stickVector);
            //Debug.Log("Gamepad angle = " + GetAngle(character.position, new Vector2(character.position.x + GamepadManagement.getStateByUserNumber(userNumber).ThumbSticks.Right.X, character.position.y + GamepadManagement.getStateByUserNumber(userNumber).ThumbSticks.Right.Y)));
        }


        angle = (playerController.facingRight) ? -angle : angle;
        sight.transform.rotation = Quaternion.Euler(0f, 0f, angle);
        if (playerController.facingRight)
        {
            direction.x = Mathf.Abs(direction.x);
        }
        else
        {
            if (direction.x > 0)
            {
                direction.x -= 2 * direction.x;
            }
        }
        sight.transform.position = (Vector3)(direction / 2 + character.position);
    }
Exemplo n.º 6
0
    public void StartGame()
    {
        int nb_players = GamepadManagement.GamepadConnectedNumber() + 1;

        LevelParam.Set("color1", indexAvatar1.ToString());
        LevelParam.Set("color2", indexAvatar2.ToString());
        if (nb_players > 2)
        {
            LevelParam.Set("color3", indexAvatar3.ToString());
        }
        if (nb_players > 3)
        {
            LevelParam.Set("color4", indexAvatar4.ToString());
        }


        SceneManager.LoadScene("sandbox");
    }
Exemplo n.º 7
0
    private void moveManagement()
    {
        GameInputManager.direction = 0;

        //Keyboard only for player 1
        if (userNumber == 0)
        {
            if (Input.GetKey(GameInputManager.GIM.left))
            {
                GameInputManager.direction = -1;
            }
            if (Input.GetKey(GameInputManager.GIM.right))
            {
                GameInputManager.direction = 1;
            }

            wantToJump = player.Move(GameInputManager.direction, wantToJump);
        }
        else
        {
            //DPad or Joystick choice
            if (GamepadManagement.getStateByUserNumber(userNumber).ThumbSticks.Left.X == 0)
            {
                //DPad
                if (GamepadManagement.getStateByUserNumber(userNumber).DPad.Left == ButtonState.Pressed)
                {
                    GameInputManager.direction = -1;
                }

                if (GamepadManagement.getStateByUserNumber(userNumber).DPad.Right == ButtonState.Pressed)
                {
                    GameInputManager.direction = 1;
                }

                wantToJump = player.Move(GameInputManager.direction, wantToJump);
            }
            else
            {
                //Joystick
                wantToJump = player.Move(GamepadManagement.getStateByUserNumber(userNumber).ThumbSticks.Left.X, wantToJump);
            }
        }
    }
Exemplo n.º 8
0
 private void Update()
 {
     if (!wantToJump && !Dead)
     {
         // Read the jump input in Update so button presses aren't missed.
         if (userNumber == 0) //Keyboard (Player 1)
         {
             wantToJump = Input.GetKeyDown(GameInputManager.GIM.jump);
         }
         else
         {
             //Gamepad
             if (wantToJump == false)
             {
                 wantToJump = (GamepadManagement.getStateByUserNumber(userNumber).Triggers.Left >= 0.1 && GamepadManagement.getPrevStateByUserNumber(userNumber).Triggers.Left == 0);
             }
         }
     }
 }
Exemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        Item item = inventory.GetCurrentItem();

        if (item != null && !GetComponent <PlayerHealth>().isDead)
        {
            GameObject current = item.itemObject;
            fireRate = current.GetComponent <Shoot>().fireRate;


            if (fireRate == 0)
            {
                if (userNumber == 0) //Player 1 with keyboard+mouse
                {
                    if (Input.GetButtonDown("Fire"))
                    {
                        startFire = Time.time;
                    }
                    if (Input.GetButtonUp("Fire"))
                    {
                        if (current.GetComponent <Shoot>().shoot(item.name, userNumber, startFire - Time.time, character.transform.position, character, playerController.facingRight) == 0)
                        {
                            //Debug.Log("Remove Object");
                            inventory.DestroyCurrentItem();
                        }
                    }
                }
                else //Player 2/3/4 with gamepad
                {
                    if (GamepadManagement.getStateByUserNumber(userNumber).Triggers.Right != 0 && GamepadManagement.getPrevStateByUserNumber(userNumber).Triggers.Right == 0)
                    {
                        startFire = Time.time;
                    }
                    if (GamepadManagement.getStateByUserNumber(userNumber).Triggers.Right == 0 && GamepadManagement.getPrevStateByUserNumber(userNumber).Triggers.Right != 0)
                    {
                        if (current.GetComponent <Shoot>().shoot(item.name, userNumber, startFire - Time.time, character.transform.position, character, playerController.facingRight) == 0)
                        {
                            //Debug.Log("Remove Object");
                            inventory.DestroyCurrentItem();
                        }
                    }
                }
            }
            else
            {
                if (Time.time > timeToFire)
                {
                    if (userNumber == 0) //Player 1 with keyboard+mouse
                    {
                        if (Input.GetButtonDown("Fire"))
                        {
                            startFire     = Time.time;
                            ClickedButton = true;
                        }
                        if (Input.GetButtonUp("Fire") && ClickedButton)
                        {
                            if (current.GetComponent <Shoot>().shoot(item.name, userNumber, startFire - Time.time, character.transform.position, character, playerController.facingRight) == 0)
                            {
                                //Debug.Log("Remove Object");
                                inventory.DestroyCurrentItem();
                            }
                            timeToFire    = Time.time + fireRate;
                            ClickedButton = false;
                        }
                    }
                    else //Player 2/3/4 with gamepad
                    {
                        if (GamepadManagement.getStateByUserNumber(userNumber).Triggers.Right != 0 && GamepadManagement.getPrevStateByUserNumber(userNumber).Triggers.Right == 0)
                        {
                            startFire = Time.time;
                        }
                        if (GamepadManagement.getStateByUserNumber(userNumber).Triggers.Right == 0 && GamepadManagement.getPrevStateByUserNumber(userNumber).Triggers.Right != 0)
                        {
                            if (current.GetComponent <Shoot>().shoot(item.name, userNumber, startFire - Time.time, character.transform.position, character, playerController.facingRight) == 0)
                            {
                                //Debug.Log("Remove Object");
                                inventory.DestroyCurrentItem();
                            }
                            timeToFire += fireRate;
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 10
0
    public int shoot(string weapon, int playerNumber, float time, Vector3 position, Rigidbody2D character, bool FacingRight)
    {
        Debug.Log("J'ai encore :" + Ammo + " ");
        Debug.Log("Item: " + weapon);
        Vector2 mousePos;

        if (playerNumber == 0) //Mouse
        {
            mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }
        else //Gamepad
        {
            mousePos = new Vector2(character.position.x + GamepadManagement.getStateByUserNumber(playerNumber).ThumbSticks.Right.X, character.position.y + GamepadManagement.getStateByUserNumber(playerNumber).ThumbSticks.Right.Y);
        }

        Vector2 direction = (mousePos - character.position).normalized;

        float angle = GetAngle(character.position, mousePos);

        angle = (FacingRight) ? -angle : 180 + angle;

        if (FacingRight)
        {
            direction.x = Mathf.Abs(direction.x);
        }
        else
        {
            if (direction.x > 0)
            {
                direction.x -= 2 * direction.x;
            }
        }

        if (time < -1.2f)
        {
            time = -1.2f;
        }



        if (weapon.Equals("Shotgun"))
        {
            for (int i = -3; i <= 3; i++)
            {
                if (i != 0)
                {
                    GameObject projectile = Instantiate(Resources.Load(AmmoObject, typeof(GameObject)), (Vector2)position + direction + new Vector2(0, i * 0.15f), Quaternion.Euler(0f, 0f, angle)) as GameObject;
                    projectile.GetComponent <Rigidbody2D>().velocity = (direction + new Vector2(0, i * 0.15f)) * (minShootVelocity + projectile.GetComponent <Shotgun_Attack>().shootVelocity);
                }
            }
        }

        if (weapon.Equals("Bow"))
        {
            GameObject projectile = Instantiate(Resources.Load(AmmoObject, typeof(GameObject)), (Vector2)position + direction, Quaternion.Euler(0f, 0f, angle)) as GameObject;
            projectile.GetComponent <Rigidbody2D>().velocity = direction * (minShootVelocity + projectile.GetComponent <ArrowAttack>().shootVelocity * -time);
        }

        Ammo = Ammo - 1;
        return(Ammo);
    }