Exemple #1
0
        protected override void DetermineSprite(FieldCamera camera)
        {
            var x = _movementComponent.RawDirection.X;
            var z = _movementComponent.RawDirection.Z * -1;

            EActionTypes newAnimationName;

            if (_movementComponent.Jumping)
            {
                newAnimationName = EActionTypes.Jump;
            }
            else if (z == 0 && x == 0)
            {
                newAnimationName = EActionTypes.Idle;
            }
            else if (_movementComponent.Running)
            {
                newAnimationName = EActionTypes.Run;
            }
            else
            {
                newAnimationName = EActionTypes.Walk;
            }

            var newDirection = _nextAnimation?.Direction ?? _previousAnimation.Direction;

            newDirection = CalculateDirection(x, z, newDirection);

            if (z == 0 && x == 0 && camera.CameraDirectionChanged)
            {
                newDirection = camera.CameraDirection.Next() == camera.PreviousCameraDirection ? newDirection.Next() : newDirection.Previous();
            }

            var actualAnimations = _animations[(newAnimationName, newDirection)];
        public virtual void Update(InputComponent input, FieldCamera camera)
        {
            _spriteComponent.Entity.Transform.Position = _unmodifiedPosition;
            MoveCharacter();
            DetermineSprite(camera);
            _unmodifiedPosition = _spriteComponent.Entity.Transform.Position;
            _currentTicks      += Game.UpdateTime.Elapsed.TotalMilliseconds;
            if (_currentTicks >= 125) // Each animation takes 0.125 seconds to complete. Only change sprite after this time elapsed
            {
                var spriteProvider = _spriteComponent.SpriteProvider as SpriteFromSheet;
                spriteProvider.CurrentFrame = _nextAnimation.SpriteSheetId;
                _previousAnimation          = _nextAnimation;
                _nextAnimation = null;
                _currentTicks  = 0;
            }
            this.Direction = _previousAnimation.Direction;

            _spriteComponent.Entity.Transform.Rotation = camera.CameraTarget.Rotation; // Keep sprite rotated towards camera. TODO: Update Sprite's Y Value to scale properly with camera angle.
            var cameraEntity = Core.Instance.MainCamera.Entity.Transform;
            var direction    = (Entity.Transform.Position - cameraEntity.LocalToWorld(cameraEntity.Position));

            direction.Normalize();

            _spriteComponent.Entity.Transform.Position -= 0.3f * direction;
        }
Exemple #3
0
        public void Update(InputManager input, FieldCamera camera, CharacterComponent _character)
        {
            var gamepad = input.DefaultGamePad;

            if (gamepad == null)
            {
                return;
            }
            Vector2 leftStick = gamepad.State.LeftThumb;

            leftStick.X = Math.Abs(leftStick.X) < DeadZone ? 0 : leftStick.X;
            leftStick.Y = Math.Abs(leftStick.Y) < DeadZone ? 0 : leftStick.Y;
            if (leftStick.X < 0)
            {
                leftStick.X = -1;
            }
            if (leftStick.X > 0)
            {
                leftStick.X = 1;
            }
            if (leftStick.Y < 0)
            {
                leftStick.Y = -1;
            }
            if (leftStick.Y > 0)
            {
                leftStick.Y = 1;
            }
            this.Direction = new Vector3(leftStick.X, 0, -leftStick.Y);

            leftStick.Y = leftStick.Y * -1;
            var rotatedDirection = leftStick.Rotate((double)camera.CameraDirection * 45);

            this.DirectionCameraRelative = new Vector3((float)Math.Round(rotatedDirection.X), 0, (float)Math.Round(rotatedDirection.Y));

            this.Cancel = gamepad.IsButtonPressed(GamePadButton.B);
            if (!this.Cancel)
            {
                this.Interact = gamepad.IsButtonPressed(GamePadButton.A);
            }
            this.Run       = gamepad.IsButtonDown(GamePadButton.B);
            this.BeginJump = gamepad.IsButtonPressed(GamePadButton.Y) && !Jumping && _character.IsGrounded;
            if (this.BeginJump)
            {
                this.Jumping = true;
            }
            this.OpenMenu         = gamepad.IsButtonPressed(GamePadButton.Y);
            this.RotateCameraLeft = gamepad.IsButtonPressed(GamePadButton.LeftShoulder);
            if (!this.RotateCameraLeft)
            {
                this.RotateCameraRight = gamepad.IsButtonPressed(GamePadButton.RightShoulder);
            }
        }
Exemple #4
0
 public override void Update(InputComponent input, FieldCamera camera)
 {
     _movementComponent.RawDirection = input.Direction;
     _movementComponent.Direction    = input.DirectionCameraRelative;
     _movementComponent.BeginJump    = input.BeginJump;
     if (input.BeginJump)
     {
         _movementComponent.Jumping = input.BeginJump;
     }
     _movementComponent.Running = input.Run;
     base.Update(input, camera);
     input.Jumping  = _movementComponent.Jumping;
     this.Direction = CalculateDirection(_movementComponent.Direction.X, _movementComponent.Direction.Z * -1, this.Direction);
 }
        public override void Update(InputComponent input, FieldCamera camera)
        {
            ExecuteAction();
            base.Update(input, camera);

            bool isCollidingWithPlayer = _characterComponent.Collisions.FirstOrDefault(x => x.ColliderB.Entity == Core.Instance.Player.Entity) != null;

            if (_currentAction != null && _currentTicks == 0 && !isCollidingWithPlayer)
            {
                _currentAction.CurrentFrame++;
                if (_currentAction.CurrentFrame > _currentAction.Frames - 1)
                {
                    _currentAction = null;
                }
            }
            this.Direction = _previousAnimation.Direction;
        }
        protected override void DetermineSprite(FieldCamera camera)
        {
            ECameraDirection direction = (ECameraDirection)(((0).LoopAdd(-(int)camera.CameraDirection, 7, 0).LoopAdd((int)_currentAction.Direction, 7, 0)));

            bool isCollidingWithPlayer = _characterComponent.Collisions.FirstOrDefault(x => x.ColliderB.Entity == Core.Instance.Player.Entity || x.ColliderA.Entity == Core.Instance.Player.Entity) != null;
            var  actualAnimations      = _animations[(isCollidingWithPlayer ? EActionTypes.Idle : _currentAction.Action, direction)];