private static void ApplyMirroring(AnimationComponent component)
 {
     if (component.CurrentEntityState.Orientation == Direction.Left)
     {
         component.BoundDrawComponent.FlipHorizontally = true;
     }
     else
     {
         component.BoundDrawComponent.FlipHorizontally = false;
     }
 }
Example #2
0
        private static bool HasDeathAnimation(Entity entity)
        {
            if (entity.Components.TryGetValue(typeof(AnimationComponent), out var component))
            {
                AnimationComponent animation = component as AnimationComponent;
                if (animation.CurrentEntityState.CurrentState != EntityState.Dying)
                {
                    return(animation.Animations.Exists(a => a.Trigger == EntityState.Dying));
                }
                return(animation.Animations.Exists(a => a.Trigger == EntityState.Dead));
            }

            return(false);
        }
Example #3
0
 private static void ExecuteDeathAnimation(Entity entity)
 {
     if (entity.Components.TryGetValue(typeof(AnimationComponent), out var component))
     {
         AnimationComponent animation = component as AnimationComponent;
         if (animation.CurrentEntityState.CurrentState != EntityState.Dying)
         {
             entity.StateComponent.TryToSetState(EntityState.Dying);
             entity.StateComponent.Dead = false; //Entity is kept alive until it plays its dying animation
         }
         else
         {
             entity.StateComponent.TryToSetState(EntityState.Dead);
         }
     }
 }
        private static void StartAnimation(AnimationComponent component, EntityState trigger, GameTime gameTime) //for now just randomize it
        {
            if (trigger == EntityState.Dying)
            {
            }
            List <Animation> animations = component.Animations.FindAll(a => a.Trigger == trigger);

            if (animations.Count == 0)
            {
                return;
            }

            Random random = new Random();

            component.CurrentAnimation = animations[random.Next(0, animations.Count - 1)];
            component.CurrentAnimation.StartTimeMilliseconds = gameTime.TotalGameTime.TotalMilliseconds;
            component.BoundDrawComponent.Texture             = component.CurrentAnimation.SpriteSheet;
        }
        private static void ProcessCurrentAnimation(AnimationComponent component, GameTime gameTime)
        {
            if (component.CurrentAnimation.Finished(gameTime))
            {
                if (component.CurrentAnimation.Trigger == EntityState.Dying)
                {
                    component.CurrentEntityState.Dead          = true;
                    component.CurrentEntityState.ReadyToRemove = true;
                    return;
                }
                if (component.CurrentAnimation.Looping)
                {
                    ReplayAnimation(component, gameTime);
                }
                else
                {
                    StartAnimation(component, component.CurrentAnimation.NextAnimationIdentifier, gameTime);
                }
            }

            ApplyAnimationRec(component, gameTime);
        }
 private static void StartAnimation(AnimationComponent component, String identifier, GameTime gameTime)
 {
     component.CurrentAnimation = component.Animations.Find(a => a.Identifier.Equals(identifier));
     component.CurrentAnimation.StartTimeMilliseconds = gameTime.TotalGameTime.TotalMilliseconds;
     component.BoundDrawComponent.Texture             = component.CurrentAnimation.SpriteSheet;
 }
 private static void ResetMirroring(AnimationComponent component)
 {
     component.BoundDrawComponent.FlipHorizontally = false;
 }
 private static void ApplyAnimationRec(AnimationComponent component, GameTime gameTime)
 {
     component.BoundDrawComponent.SourceRec = component.CurrentAnimation.GetSourceRec(gameTime);
 }
 private static void ReplayAnimation(AnimationComponent component, GameTime gameTime)
 {
     component.CurrentAnimation.StartTimeMilliseconds = gameTime.TotalGameTime.TotalMilliseconds;
 }