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 #2
0
        public virtual void Update(InputComponent input)
        {
            if (!_camera.Enabled) // Scene change disabled camera temporarily.
            {
                _camera.Enabled = true;
            }

            CameraDirectionChanged = false;
            if (_currentDirectionDegrees == _newDirectionDegrees)
            {
                if (input.RotateCameraLeft)
                {
                    _newDirection        = CameraDirection.Previous();
                    _newDirectionDegrees = _currentDirectionDegrees + 45;
                }
                else if (input.RotateCameraRight)
                {
                    _newDirection        = CameraDirection.Next();
                    _newDirectionDegrees = _currentDirectionDegrees - 45;
                }
            }
            if (_currentDirectionDegrees != _newDirectionDegrees)
            {
                var deltaTime         = Game.UpdateTime.Elapsed.TotalSeconds;
                var desiredQuaternion = Quaternion.RotationY(_newDirectionDegrees * (float)(Math.PI / 180));
                var amount            = (float)Math.Clamp(_currentLerpAmount + (1.5 * deltaTime), 0, 1);
                _cameraTarget.Rotation = Quaternion.Lerp(_currentQuaternion, desiredQuaternion, amount);
                _currentLerpAmount     = amount;
                if (amount >= 0.6f && CameraDirection != _newDirection)
                {
                    CameraDirection        = _newDirection;
                    CameraDirectionChanged = true;
                }
                if (amount == 1.0f)
                {
                    _currentLerpAmount       = 0;
                    _currentDirectionDegrees = _newDirectionDegrees;
                    _currentQuaternion       = _cameraTarget.Rotation;
                    PreviousCameraDirection  = CameraDirection;
                }
            }
        }
        public override void Start()
        {
            if (this.Initialized)
            {
                return;
            }
            base.Start();
            this.XGCharacter = Core.Instance.XGCharacters[this.XGCharacterName];
            this.Direction   = ECameraDirection.North;

            _spriteComponent    = Entity.GetComponentInChildren <SpriteComponent>();
            _characterComponent = Entity.Get <CharacterComponent>();
            _animations         = new Dictionary <(EActionTypes, ECameraDirection), List <IndividualAnimation> >();

            _spriteComponent.SpriteProvider           = BuildSpriteSheet();
            _spriteComponent.SpriteType               = SpriteType.Sprite;
            _spriteComponent.IgnoreDepth              = false;
            _spriteComponent.Entity.Transform.Scale.Y = 2.5f;
            _characterComponent.FallSpeed             = 50f;
            _characterComponent.JumpSpeed             = 5f;
            _characterComponent.Gravity               = new Vector3(0, -12f, 0);
            _unmodifiedPosition = _spriteComponent.Entity.Transform.Position;
            _characterComponent.UpdatePhysicsTransformation();
        }
        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)];