コード例 #1
0
        public static void Kill(StackableActorComponent actor, bool falling = false)
        {
            if (actor.LogicStateMachine.CurrentState == ActorStates.Dead)
            {
                return;
            }

            var position = actor.Owner.GetComponent <PositionComponent>();

            actor.SyncAngleWithSpeedVector = !falling;

            actor.LogicStateMachine.ChangeState(ActorStates.Dead);


            foreach (var camera in actor.Owner.Scene.GetEntityList <GameCamera>())
            {
                if (camera.Target == position)                 // If this camera follows actor.
                {
                    camera.Target = null;
                }
            }

            if (!falling)
            {
                SoundController.PlaySoundAt(Resources.Sounds.Death, position.Position);
            }
        }
コード例 #2
0
 void ResetAnimation(StackableActorComponent actor)
 {
     actor.CurrentSprite   = actor.MainSprite;
     actor.Animation       = 0;
     actor.SpriteAnimation = 0;
     actor.AnimationSpeed  = actor.WalkAnimationSpeed;
     actor.SpriteScale     = Vector2.One;
     actor.SpriteOffset    = Vector2.Zero;
 }
コード例 #3
0
        void Jump(PhysicsComponent physics, StackableActorComponent actor)
        {
            physics.Speed.Y = -actor.JumpSpeed;
            if (physics.StandingOn != null)
            {
                physics.Speed += physics.StandingOn.GetComponent <SolidComponent>().Speed;
            }
            actor.CanJump = false;
            actor.Jumping = true;

            SoundController.PlaySound(Resources.Sounds.Jump);
        }
コード例 #4
0
 public static void StackEntity(StackableActorComponent master, StackableActorComponent slave)
 {
     if (master.StackedNext != null)
     {
         StackEntity(master.StackedNext.GetComponent <StackableActorComponent>(), slave);
     }
     else
     {
         slave.StackedPrevious = master.Owner;
         master.StackedNext    = slave.Owner;
         slave.LogicStateMachine.ChangeState(ActorStates.Stacked);
     }
 }
コード例 #5
0
 void UpdateOrientation(StackableActorComponent actor)
 {
     if (actor.LeftAction != actor.RightAction)
     {
         if (actor.LeftAction)
         {
             actor.Orientation = -1;
         }
         if (actor.RightAction)
         {
             actor.Orientation = 1;
         }
     }
 }
コード例 #6
0
        bool UpdateAnimation(StateMachine <ActorAnimationStates> stateMachine, StackableActorComponent actor, ActorAnimationStates newState)
        {
            actor.Animation += TimeKeeper.GlobalTime(actor.AnimationSpeed);

            if (actor.Animation >= 1 || actor.Animation < 0)
            {
                actor.Animation -= 1;

                if (newState != stateMachine.CurrentState)
                {
                    stateMachine.ChangeState(newState);
                    return(true);
                }
            }
            return(false);
        }
コード例 #7
0
        void Uncrouch(PositionComponent position, PhysicsComponent physics, StackableActorComponent actor)
        {
            var colliderSize = physics.Collider.Size;
            var oldH         = colliderSize.Y;

            colliderSize.Y = actor.Height;

            physics.Collider.Size = colliderSize;

            position.Position.Y -= (colliderSize.Y - oldH) / 2;

            actor.Crouching = false;

            if (actor.StackedPrevious == null)
            {
                SoundController.PlaySound(Resources.Sounds.Crouch);
            }
        }
コード例 #8
0
 public static void Damage(StackableActorComponent actor)
 {
     // This later can be expanded to take away health.
     Kill(actor);
 }
コード例 #9
0
        void UpdateSpeed(StackableActorComponent actor, PhysicsComponent physics)
        {
            var horMovement = actor.RightAction.ToInt() - actor.LeftAction.ToInt();

            var sliding = false;

            if (
                horMovement == 0 ||
                (
                    Math.Abs(physics.Speed.X) > actor.MaxMovementSpeed &&
                    ((!actor.RightAction && !actor.LeftAction) || actor.Crouching)
                )
                )
            {
                // Slowing down.
                if (physics.Speed.X != 0)
                {
                    var spdSign = Math.Sign(physics.Speed.X);
                    physics.Speed.X -= TimeKeeper.GlobalTime(spdSign * actor.Deceleration);
                    if (Math.Sign(physics.Speed.X) != Math.Sign(spdSign))
                    {
                        physics.Speed.X = 0;
                    }
                }
                // Slowing down.


                sliding = (physics.Speed.X != 0 && actor.Crouching);
            }
            else
            {
                // Speeding up.
                if (Math.Abs(physics.Speed.X) < actor.MaxMovementSpeed || Math.Sign(physics.Speed.X) != Math.Sign(horMovement))
                {
                    physics.Speed.X += TimeKeeper.GlobalTime(horMovement * actor.Acceleration);

                    if (Math.Abs(physics.Speed.X) > actor.MaxMovementSpeed)
                    {
                        physics.Speed.X = horMovement * actor.MaxMovementSpeed;
                    }
                }
                // Speeding up.
            }


            var speedRatio = Math.Abs(physics.Speed.X / 2) / actor.MaxMovementSpeed;

            if (sliding)
            {
                if (actor.SlideSound == null)
                {
                    if (speedRatio > 1.1f)
                    {
                        actor.SlideSound = SoundController.PlaySound(Resources.Sounds.Slide);
                    }
                }
                else
                {
                    actor.SlideSound.Volume = Math.Min(1, speedRatio);
                }
            }

            if (actor.SlideSound != null && !sliding)
            {
                actor.SlideSound.Stop();
                actor.SlideSound = null;
            }
        }
コード例 #10
0
        void StackedUpdate(StackableActorComponent actor, float baseDirection, int stackIndex, Entity owner)
        {
            var position = actor.Owner.GetComponent <PositionComponent>();
            var physics  = actor.Owner.GetComponent <PhysicsComponent>();

            var masterPosition = actor.StackedPrevious.GetComponent <PositionComponent>();
            var masterPhysics  = actor.StackedPrevious.GetComponent <PhysicsComponent>();
            var masterActor    = actor.StackedPrevious.GetComponent <StackableActorComponent>();

            actor.StackOwner = owner;

            // Pendulum.

            // We are applying force to the pendulum, and it tries to push back.
            // Jiggly stacking stuff happens here.

            var pendulumForce       = (masterPosition.Position.X - masterPosition.PreviousPosition.X) * actor.PendulumForceMultiplier;
            var pendulumSpringForce = (float)Math.Pow(actor.StackDirectionOffset, 3) * actor.PendulumRigidity;

            actor.PendulumMomentum += TimeKeeper.GlobalTime(pendulumForce - pendulumSpringForce);
            actor.PendulumMomentum -= Math.Sign(actor.PendulumMomentum) * TimeKeeper.GlobalTime(actor.PendulumEnergyLossRate);

            if (Math.Abs(actor.PendulumMomentum) > actor.PendulumMomentumMax)
            {
                actor.PendulumMomentum = actor.PendulumMomentumMax * Math.Sign(actor.PendulumMomentum);
            }
            actor.StackDirectionOffset += TimeKeeper.GlobalTime(actor.PendulumMomentum);

            if (Math.Abs(actor.StackDirectionOffset) > actor.StackDirectionMaxOffset)
            {
                actor.StackDirectionOffset = actor.StackDirectionMaxOffset * Math.Sign(actor.StackDirectionOffset);
            }

            var dir = MathHelper.ToRadians(baseDirection + actor.StackDirectionOffset);

            // Pendulum.


            // Crouch transfer.
            if (masterActor.Crouching && !actor.Crouching)
            {
                Crouch(position, physics, actor);
            }
            if (!masterActor.Crouching && actor.Crouching)
            {
                Uncrouch(position, physics, actor);
            }
            // Crouch transfer.


            // Nice y delaying.
            actor.StackedTargetPosition = masterPosition.Position
                                          + new Vector2(
                (float)Math.Cos(dir),
                (float)-Math.Sin(dir)
                ) * (masterPhysics.Collider.Size.Y);


            // TODO: Figure out exact formula.
            position.Position.Y += TimeKeeper.GlobalTime((-position.Position.Y + actor.StackedTargetPosition.Y) / actor.StackPositionDelayDivider);
            //position.Position.Y += (-position.Position.Y + actor.StackedTargetPosition.Y) / actor.StackPositionDelayDivider;
            position.Position.X = actor.StackedTargetPosition.X;
            // Nice y delaying.



            if (actor.StackedNext != null)
            {
                StackedUpdate(
                    actor.StackedNext.GetComponent <StackableActorComponent>(),
                    baseDirection + actor.StackDirectionOffset,
                    stackIndex + 1,
                    owner
                    );
            }

            if (stackIndex > actor.StackLimit)
            {
                actor.LogicStateMachine.ChangeState(ActorStates.Dead);
            }
        }