Пример #1
0
    static public Vector2 DetectAxes(PlayerInputMethod inputMethod)
    {
        Vector2 axes = Vector2.zero;

        if (inputMethod == PlayerInputMethod.KeyboardMouse)
        {
            axes.x = Input.GetAxisRaw("Horizontal");
            axes.y = Input.GetAxisRaw("Vertical");
        }
        else if (inputMethod == PlayerInputMethod.Controller)
        {
            axes.x = Input.GetAxisRaw("J1X");
            axes.y = Input.GetAxisRaw("J1Y");
        }
        else if (inputMethod == PlayerInputMethod.Controller2)
        {
            axes.x = Input.GetAxisRaw("J2X");
            axes.y = Input.GetAxisRaw("J2Y");
        }

        return(axes);
    }
Пример #2
0
 public PlayerUser(SceneGame sc, UserInformation u, CoroutineFunction<PlayerUser> mop, CoroutineFunction<PlayerUser> sop, PlayerInputMethod im)
 {
     info = u;
     game = sc;
     ipmet = im;
     SourceUser = u.SourceUser;
     MovingOperation = mop(this);
     ShotOperation = sop(this);
     MyKind = ObjectKind.Player;
     DamageKind = ObjectKind.Enemy | ObjectKind.EnemyBullet;
     CollisionRadius = u.CollisionRadius;
     GrazeRadius = CollisionRadius * 1.5;
     ShotStrength = u.ShotStrength;
     ShotInterval = 2;
     Operatable = true;
     HasCollision = true;
     GrazePoint = u.GrazePoints;
     Task.Run(() =>
     {
         Image = UserImageManager.GetUserImage(SourceUser);
         IsImageLoaded = true;
     });
 }
Пример #3
0
    static public bool DetectAny(PlayerInputMethod inputMethod)
    {
        switch (inputMethod)
        {
        case PlayerInputMethod.KeyboardMouse:
            for (int i = 0; i < keyboardEnd; ++i)
            {
                if (Input.GetKeyDown((KeyCode)i))
                {
                    return(true);
                }
            }
            break;

        case PlayerInputMethod.Controller:
            for (int i = 0; i < 20; ++i)
            {
                if (Input.GetKeyDown((KeyCode)(joystickButtonBegin + i)))
                {
                    return(true);
                }
            }
            break;

        case PlayerInputMethod.Controller2:
            for (int i = 20; i < 40; ++i)
            {
                if (Input.GetKeyDown((KeyCode)(joystickButtonBegin + i)))
                {
                    return(true);
                }
            }
            break;
        }

        return(false);
    }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        switch (state)
        {
        case MainMenuState.Start: {
            Vector2 j = InputHelper.AnyDir();
            inputTimeout -= Time.deltaTime;

            if (inputTimeout <= 0f && j.y != 0f)
            {
                screenButtons[buttonSelected].Selected = false;
                buttonSelected = (buttonSelected + (int)j.y) % screenButtons.Length;
                if (buttonSelected < 0f)
                {
                    buttonSelected += screenButtons.Length;
                }
                print(buttonSelected);
                screenButtons[buttonSelected].Selected = true;

                inputTimeout = 0.2f;
            }

            if (InputHelper.AnyButton())
            {
                ButtonDown(screenButtons[buttonSelected].buttonName);
            }

            break;
        }

        case MainMenuState.Instructions:
            instructionTimeout -= Time.deltaTime;

            if (instructionTimeout <= 0f && InputHelper.AnyButton())
            {
                state = MainMenuState.Start;
            }
            break;

        case MainMenuState.PlayerJoin: {
            if (numPlayersDetected == 2)
            {
                // state = MainMenuState.CharacterSelect;
                //StartGame();
                pgs.invertAxes[0] = ControlMode.None;
                pgs.invertAxes[1] = ControlMode.None;

                playerReady[0] = false;
                playerReady[1] = false;

                state = MainMenuState.InvertAxis;
                return;
            }

            PlayerInputMethod im = InputHelper.DetectInput();
            if (im == PlayerInputMethod.None)
            {
                break;
            }

            if (!inputMethodsUsed[(int)im])
            {
                inputMethodsUsed[(int)im]            = true;
                pgs.inputMethods[numPlayersDetected] = im;
                pim[numPlayersDetected].text         = im.ToString();
                numPlayersDetected++;
                print("PlayerJoin im: " + im.ToString());
            }

            break;
        }

        case MainMenuState.InvertAxis: {
            Vector2[] axes = new Vector2[2];
            axes[0] = InputHelper.DetectAxes(pgs.inputMethods[0]);
            axes[1] = InputHelper.DetectAxes(pgs.inputMethods[1]);

            for (int pid = 0; pid < 2; pid++)
            {
                if (axes[pid].x != 0f)
                {
                    if (axes[pid].x > 0f)
                    {
                        pgs.invertAxes[pid] = ControlMode.Inverted;
                    }
                    else
                    {
                        pgs.invertAxes[pid] = ControlMode.Standard;
                    }
                }

                if (!playerReady[pid])
                {
                    switch (pgs.invertAxes[pid])
                    {
                    case ControlMode.None:
                        pia[pid].text = "Choose";
                        break;

                    case ControlMode.Standard:
                        pia[pid].text = "Standard";
                        break;

                    case ControlMode.Inverted:
                        pia[pid].text = "Inverted";
                        break;
                    }
                }
                else
                {
                    pia[pid].text = "Ready";
                }

                if (InputHelper.DetectAny(pgs.inputMethods[pid]) && axes[pid].x == 0f && pgs.invertAxes[pid] != ControlMode.None)
                {
                    playerReady[pid] = true;
                }
            }

            if (playerReady[0] && playerReady[1])
            {
                startgameCountdown -= Time.deltaTime;
                countdownText.text  = Mathf.Floor(startgameCountdown + 0.5f).ToString();

                if (startgameCountdown <= 0f)
                {
                    StartGame();
                }
            }

            break;
        }

        case MainMenuState.CharacterSelect:
            StartGame();
            break;
        }

        Vector3 cpos = Camera.main.transform.position;
        Vector3 diff = screens[(int)state].transform.position - cpos;

        if (diff.magnitude > 0.01f)
        {
            Camera.main.transform.position = cpos + diff * 0.1f;
        }
    }