Beispiel #1
0
        private void Update()
        {
            if (GameManager.IsGamePaused)
            {
                return;
            }

            // Get input associated with the player's controller
            playerInput = InputHelper.GetPlayerInput(PlayerID);

            if (IsDashing)
            {
                _rigidbody.velocity = transform.up * DashSpeed * CONST.PIXELS_PER_UNIT;
                _animator.SetBool("moving", true);
            }
            else
            {
                if (!CanDash)
                {
                    DashBar.rectTransform.localScale = new Vector3((Time.time - lastDash) / DashCooldown, 1, 1);
                }

                if (playerInput.HorizontalMovement != 0)
                {
                    _rigidbody.angularVelocity = 0;
                    var amountToRotate = -playerInput.HorizontalMovement * RotationPerSecond * Time.deltaTime;
                    var newAngle       = transform.localRotation.eulerAngles.z + amountToRotate;
                    transform.localRotation = Quaternion.Euler(new Vector3(0, 0, newAngle));
                }

                if (playerInput.Dashing && CanDash)
                {
                    lastDash  = Time.time + DashDuration;
                    IsDashing = true;
                    GameManager.Instance.PlaySound("superthrusty");
                }

                var aimVec = playerInput.GetNormalizedAim(transform.position, Camera.main);
                if (aimVec.x != 0 || aimVec.y != 0)
                {
                    GunArmSprite.transform.eulerAngles = new Vector3(0, 0, Mathf.Atan2(aimVec.y, aimVec.x) * Mathf.Rad2Deg);
                    var gangle = GunArmSprite.transform.localEulerAngles.z;
                    if (gangle >= 90 && gangle <= 270)
                    {
                        BodySprite.transform.localScale   = new Vector3(-1, 1, 1);
                        GunArmSprite.transform.localScale = new Vector3(1, -1, 1);
                    }
                    else
                    {
                        BodySprite.transform.localScale   = new Vector3(1, 1, 1);
                        GunArmSprite.transform.localScale = new Vector3(1, 1, 1);
                    }
                }

                if (playerInput.Shooting)
                {
                    if (Time.time - _lastShot > ShotCoolDown)
                    {
                        _lastShot = Time.time;
                        var bullet = (Projectile)GameManager.Instance.GetBullet();
                        bullet.transform.position = ShootiePoint.position;
                        bullet.SetDir(GunArmSprite.transform.right);
                        bullet.Player           = this;
                        _rigidbody.velocity    += (Vector2)GunArmSprite.transform.right * -CONST.PIXELS_PER_UNIT;
                        bullet.gameObject.layer = gameObject.layer;
                        GameManager.Instance.PlaySound("shootie");
                    }
                }

                if (playerInput.Jump)
                {
                    var velocity = _rigidbody.velocity;
                    velocity += (Vector2)transform.up * AccelerationPerSecond * CONST.PIXELS_PER_UNIT;

                    var maxSpeed = MaxSpeed * CONST.PIXELS_PER_UNIT;
                    if (velocity.sqrMagnitude > maxSpeed * maxSpeed)
                    {
                        velocity = velocity.normalized * maxSpeed;
                    }

                    _rigidbody.velocity = velocity;

                    ParticleSystem.Emit(1);
                    _animator.SetBool("moving", true);
                }
                else
                {
                    _animator.SetBool("moving", false);
                }
            }

            // Aim Bar
            var hits = Physics2D.RaycastAll(ShootiePoint.position, GunArmSprite.transform.right, 1000);

            if (hits.Length > 0)
            {
                foreach (var hit in hits)
                {
                    if (hit.collider.gameObject == this.gameObject)
                    {
                        continue;
                    }
                    if (hit.collider.gameObject.tag == "shooties")
                    {
                        continue;
                    }

                    var hitDist = hit.distance;
                    AimBar.rectTransform.localScale = new Vector3(hitDist / 1000f, 1, 1);
                    break;
                }
            }
            else
            {
                AimBar.rectTransform.localScale = new Vector3(1, 1, 1);
            }
        }
Beispiel #2
0
        private void Update()
        {
            if (_gameState == GameState.Playing)
            {
                UpdateScores();
                for (int i = 0; i < 4; i++)
                {
                    var input = InputHelper.GetPlayerInput(i);
                    if (input.Menu)
                    {
                        ChangeState(GameState.Paused);
                    }
                }
            }
            else if (_gameState == GameState.CharSel)
            {
                for (int i = 0; i < 4; i++)
                {
                    var pInput = InputHelper.GetPlayerInput(i);
                    GamSetts.PlayersEnabled[pInput.PlayerID] = !string.IsNullOrWhiteSpace(pInput.PlayerDevice);

                    if (pInput.Back)
                    {
                        if (GamSetts.PlayerTeams[pInput.PlayerID] != -1)
                        {
                            GamSetts.PlayerTeams[pInput.PlayerID] = -1;
                        }
                        else
                        {
                            InputHelper.DisconnectPlayerDevice(pInput.PlayerID);
                            continue;
                        }
                    }

                    if (pInput.Menu && GamSetts.PlayerTeams[pInput.PlayerID] != -1 && VerifySettings())
                    {
                        GotoGameSetties();
                        break;
                    }

                    var movement = new Vector2(pInput.HorizontalMovement, pInput.VerticalMovement);
                    if (movement.sqrMagnitude > 0.5f)
                    {
                        if (Mathf.Abs(movement.x) > Mathf.Abs(movement.y))
                        {
                            if (movement.x > 0)
                            {
                                GamSetts.PlayerTeams[pInput.PlayerID] = 2;
                            }
                            else if (movement.x < 0)
                            {
                                GamSetts.PlayerTeams[pInput.PlayerID] = 1;
                            }
                        }
                        else
                        {
                            if (movement.y < 0)
                            {
                                GamSetts.PlayerTeams[pInput.PlayerID] = 3;
                            }
                            else if (movement.y > 0)
                            {
                                GamSetts.PlayerTeams[pInput.PlayerID] = 0;
                            }
                        }
                    }
                }
                UpdatePlayerIcons();
                StartButt.interactable = VerifySettings();
            }
            else if (_gameState == GameState.GamSetties)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (!GamSetts.PlayersEnabled[i])
                    {
                        continue;
                    }
                    var input = InputHelper.GetPlayerInput(i);

                    if (Mathf.Abs(input.VerticalMovement) > 0.5f)
                    {
                        ChangeGameSetting(input.VerticalMovement);
                        break;
                    }
                    if (Mathf.Abs(input.HorizontalMovement) > 0.5f)
                    {
                        ChangeGameSettingValue(input.HorizontalMovement);
                        break;
                    }
                }

                UpdateGameSettyScreen();
            }
        }