public virtual void Update(InputComponent input, PlayerFieldCharacter character)
        {
            var characterCollider = character.CharacterComponent;

            if (input.Interact && RequiresInteraction)
            {
                var startPos   = character.Entity.Transform.Position + new Vector3(0, 0.5f, 0);
                var forwardvec = startPos + (character.GetForwardVector() * 2.0f);
                var hitresult  = this.GetSimulation().Raycast(startPos, forwardvec, CollisionFilterGroups.SensorTrigger, CollisionFilterGroupFlags.SensorTrigger);
                if (hitresult.Collider == _collider && (this.Entity.Transform.Position - character.Entity.Transform.Position).LengthSquared() < _minimumDistance)
                {
                    //Ensure character and eventbox are facing each other when interacting.
                    forwardvec.Normalize();
                    var eventNormal     = Entity.Transform.RotationEulerXYZ.Forward();
                    var characterNormal = forwardvec;
                    var isFacing        = Vector3.Dot(eventNormal, characterNormal).RoughlyEquals(-1.0f);
                    if (isFacing)
                    {
                        Execute(input, character);
                    }
                }
            }
            else
            {
                foreach (var collision in _collider.Collisions)
                {
                    if ((collision.ColliderA == characterCollider || collision.ColliderB == characterCollider) && !RequiresInteraction)
                    {
                        Execute(input, character);
                    }
                }
            }
        }
        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 override void Start()
        {
            base.Start();
            this.Paused = true;
            Instance    = this;
            _input      = new InputComponent();
            using (var db = new XenogearsDBContext())
            {
                this.XGCharacters = db.Characters.Include(x => x.RawAnimationsData).ToDictionary(x => x.Name, x => x);
                this.XGGameStates = db.GameStates.ToDictionary(x => x.Name, x => x);
            }
            this.GameState = this.XGGameStates["GameStart"];

            _fieldPlayerPrefab = Content.Load <Prefab>("Prefabs/FieldPlayer");

            //Load up initial debug scene on game start.
            UpdateScene(new SceneChangeArgs()
            {
                SceneName            = "DebugScene",
                SceneChangeId        = 1,
                PlayerFieldCharacter = new FieldCharacterSerialization()
                {
                    XGCharacterName = "Fei"
                }
            });
        }
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);
 }
        protected override void Execute(InputComponent input, PlayerFieldCharacter character)
        {
            base.Execute(input, character);
            if (this.NextSceneName.NullIfEmpty() == null)
            {
                return;
            }
            Core.Instance.UpdateScene(new SceneChangeArgs()

            {
                SceneName            = NextSceneName,
                SceneChangeId        = NextSceneChangeId,
                PlayerFieldCharacter = character.Serialize()
            });
        }
        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;
        }
Exemple #7
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 Update(InputComponent input, PlayerFieldCharacter character)
 {
     base.Update(input, character);
 }
 protected virtual void Execute(InputComponent input, PlayerFieldCharacter character)
 {
 }