/// <summary>
        /// tillämpar rörelsen från <see cref="BeräknaRörelse(ref Vector2, out CollisionResult)()"/>
        /// till entiteten och uppdaterar TriggerHjälparen
        /// </summary>
        /// <param name="rörelse"> Rörelse.</param>
        public void TillämpaRörelsen(Vector2 rörelse)
        {
            // 2. flyttar entiteten till dennes nya position vid kollision annars förflyttas hela
            // mängden. rörelse uppdateras när en kollision inträffar
            Entity.Transform.Position += rörelse;

            // 3. gör en överlappningskontroll av alla Kolliderare som triggrar med alla bredphase
            // kolloider, trigger eller ingen trigger. Eventuella överlappningar resulterar med
            // att trigger Events blir anropad.
            TriggerHjälpare?.Update();
        }
Exemple #2
0
        public override void Update(GameTime gameTime, Level lvl)
        {
            CalculateVelocity(gameTime);
            HandleWallSliding(gameTime);

            HandleJumpInput();

            controller.Move(velocity);

            Transform.Position = ConvertUnits.ToDisplayUnits(CollisionBox.Position);

            if (controller.collisions.above || controller.collisions.below)
            {
                if (controller.collisions.slidingDown)
                {
                    velocity.Y -= controller.collisions.slopeNormal.Y * -gravity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                else
                {
                    velocity.Y = 0;
                }
            }

            trigger.Update();

            UpdateAnimation(gameTime);

            base.Update(gameTime, lvl);

            if (!context.lvl.LevelBounds.Contains(context.lvl.player.Transform.Position) && !context.transitionManager.isTransitioning)
            {
                context.lvl.SpawnPlayer(null);
            }

            PlayState.DebugMonitor.Clear();
            PlayState.DebugMonitor.AddDebugValue("Current Animation", CurrentAnimation);
            PlayState.DebugMonitor.AddDebugValue("Current State", CurrentState);
            PlayState.DebugMonitor.AddDebugValue("Position", Transform.Position);
            PlayState.DebugMonitor.AddDebugValue("Velocity", velocity);
            PlayState.DebugMonitor.AddDebugValue("Below", controller.collisions.below);
            PlayState.DebugMonitor.AddDebugValue("Left", controller.collisions.left);
            PlayState.DebugMonitor.AddDebugValue("Right", controller.collisions.right);
            PlayState.DebugMonitor.AddDebugValue("Above", controller.collisions.above);
            PlayState.DebugMonitor.AddDebugValue("Face Dir", controller.collisions.faceDirection);
            PlayState.DebugMonitor.AddDebugValue("Slope Angle", controller.collisions.slopeAngle);
            PlayState.DebugMonitor.AddDebugValue("Slope Normal", controller.collisions.slopeNormal);

            PlayState.DebugMonitor.AddDebugValue("Camera Focussed", context.camera.focussedOnPlayer);
            PlayState.DebugMonitor.AddDebugValue("Camera Position", context.camera.Position);

            PlayState.DebugMonitor.AddDebugValue("Kunai count", thrownObjects.Count());
        }
Exemple #3
0
        void IUpdatable.Update()
        {
            // handle movement and animations
            var    moveDir   = new Vector2(_xAxisInput.Value, 0);
            string animation = null;

            if (moveDir.X < 0)
            {
                if (_collisionState.Below)
                {
                    animation = "Run";
                }
                _animator.FlipX = true;
                _velocity.X     = -MoveSpeed;
            }
            else if (moveDir.X > 0)
            {
                if (_collisionState.Below)
                {
                    animation = "Run";
                }
                _animator.FlipX = false;
                _velocity.X     = MoveSpeed;
            }
            else
            {
                _velocity.X = 0;
                if (_collisionState.Below)
                {
                    animation = "Idle";
                }
            }

            if (_collisionState.Below && _jumpInput.IsPressed)
            {
                animation   = "Jumping";
                _velocity.Y = -Mathf.Sqrt(2f * JumpHeight * Gravity);
            }

            if (!_collisionState.Below && _velocity.Y > 0)
            {
                animation = "Falling";
            }

            // apply gravity
            _velocity.Y += Gravity * Time.DeltaTime;

            // move
            _mover.Move(_velocity * Time.DeltaTime, _boxCollider, _collisionState);

            // Update the TriggerHelper. This will check if our collider intersects with a
            // trigger-collider and call ITriggerListener if necessary.
            _triggerHelper.Update();

            if (_collisionState.Below)
            {
                _velocity.Y = 0;
            }

            if (animation != null && !_animator.IsAnimationActive(animation))
            {
                _animator.Play(animation);
            }
        }