Esempio n. 1
0
    void ReadInputs()
    {
        movement.UseThroughGround = (input.Movement.y >= -0.02f);
        if (!disabled)
        {
            onMovement.Invoke(input.Movement);
        }
        else
        {
            onMovement.Invoke(new Vector2(0, 0));
            return;
        }

        if (input.Jump)
        {
            onJump.Invoke();
        }
        if (input.Defuse)
        {
            if (sendDefuse.Invoke())
            {
                //Defused all the bombs
                GameSceneController.Instance.NextLevel();
            }
        }

        gunController.OpenWeaponWheel(input.SelectWeapon);

        Vector2 shoot = gunController.ShootInput(input.Shoot);

        animator.UpdateAnimator(movement.Controller.Rigidbody.velocity, shoot, movement.Controller.IsGrounded);
    }
Esempio n. 2
0
 private void OnJump()
 {
     if (IsGrounded())
     {
         OnJumpAction?.Invoke();
     }
 }
Esempio n. 3
0
        private void Awake()
        {
            _playerControls = new PlayerControls();

            _playerControls.Player.Move.performed += ctx => HorizontalAxisInput = ctx.ReadValue <float>();

            _playerControls.Player.Jump.performed += ctx => OnJumpAction?.Invoke();

            _playerControls.Player.AimDirection.performed += ctx => LookDirection = Camera.main.ScreenToWorldPoint(ctx.ReadValue <Vector2>());

            _playerControls.Player.Shoot.performed += ctx => OnAttackAction?.Invoke();
        }
 private void StartJump()
 {
     if (!_isJump /*&& !isSliding*/)
     {
         _isJump = true;
         jumpEffect.Play();
         OnJumpAction?.Invoke();
         if (_isSliding)
         {
             _slideBreak = true;
             _animator.SetSlideAnimation(false);
         }
         _jumpY           = 0;
         _collider.height = _defaultColliderHeight / 2;
         _animator.SetJumpAnimation(true);
         SetPlayerMovementType(MovementType.Jump);
         StartCoroutine(HandleJump());
         if (_followCamera.followType != PlayerFollowCamera.FollowType.DeathLoop)
         {
             _followCamera.SetFollowType(PlayerFollowCamera.FollowType.Jump);
         }
     }
 }
Esempio n. 5
0
        public void Update(GameTime gameTime)
        {
            if (IsStatic)
            {
                return;
            }

            var moveSpeedX        = 0f;
            var moveSpeedY        = 0f;
            var addJumpAfterClear = false;

            if (Gravity && _level.ApplyGravity)
            {
                moveSpeedY += _level.GravitySpeed;
            }

            foreach (var action in _nextPhysicsActions)
            {
                switch (action)
                {
                case PhysicsActions.MoveLeft:
                    moveSpeedX -= MoveSpeed;
                    break;

                case PhysicsActions.MoveRight:
                    moveSpeedX += MoveSpeed;
                    break;

                case PhysicsActions.MoveUp:
                    moveSpeedY -= MoveSpeed;
                    break;

                case PhysicsActions.MoveDown:
                    moveSpeedY += MoveSpeed;
                    break;

                case PhysicsActions.Jump:
                case PhysicsActions.ForceJump: {
                    if (_level.ApplyGravity)
                    {
                        if (!_jumpData.IsJumping)
                        {
                            if (Gravity)
                            {
                                if (action != PhysicsActions.ForceJump)
                                {
                                    if (!Move(false, 0f, 1f))
                                    {
                                        continue;
                                    }
                                }

                                _jumpData.IsJumping    = true;
                                _jumpData.TargetHeight = Entity.Box.Position.Y.Round() - JumpHeight;

                                Gravity = false;

                                moveSpeedY        = _level.GravitySpeed;
                                addJumpAfterClear = true;

                                OnJumpAction.Invoke(Entity);
                            }
                        }
                        else
                        {
                            // Vérifie si l'entité est arrivé à la bonne hauteur de saut ou s'il rencontre un obstacle au-dessus de lui
                            if (Entity.Box.Position.Y <= _jumpData.TargetHeight || Move(false, 0f, -1f))
                            {
                                Gravity             = true;
                                _jumpData.IsJumping = false;
                            }
                            else
                            {
                                moveSpeedY        = -_level.GravitySpeed;
                                addJumpAfterClear = true;
                            }
                        }
                    }
                }
                break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            _nextPhysicsActions.Clear();

            // TODO moveSpeedX *= Utility.GetDeltaTime() * Constants.PhysicsDeltaSpeed

            if (Movement == MovementType.Smooth)
            {
                moveSpeedX =
                    MathHelper.Lerp(
                        (_actualMoveSpeedX / Constants.PhysicsEpsilon).Round() * Constants.PhysicsEpsilon,
                        moveSpeedX, 0.2f);
                moveSpeedY =
                    MathHelper.Lerp(
                        (_actualMoveSpeedY / Constants.PhysicsEpsilon).Round() * Constants.PhysicsEpsilon,
                        moveSpeedY, 0.2f);
            }

            _actualMoveSpeedX = moveSpeedX;
            _actualMoveSpeedY = moveSpeedY;

            var lastPos = Entity.Box.Position;

            Move(true, moveSpeedX, moveSpeedY);

            if (Entity.Box.Position.EqualsEpsilon(lastPos, Constants.PhysicsEpsilon))
            {
                OnNothingAction.Invoke(Entity);
            }

            if (addJumpAfterClear)
            {
                _nextPhysicsActions.Add(PhysicsActions.Jump);
            }
        }
 private void OnJumpActionInvoker() => OnJumpAction?.Invoke();