Beispiel #1
0
        public static BlowEffect FillWithMetadata(BlowEffect blow, BlowEffectMetadata metadata, ContentManager contentManager)
        {
            blow.MovingParts = new List<Animation>();
            blow.PartVelocity = metadata.PartVelocity;
            blow.Law = metadata.Law;

            var contentMetaData = new AnimatedObjectMetadata()
            {
                Size = new Vector2(0, 0),
                CollisionRectangle = new Rectangle(0, 0, 0, 0),
                Animations = new List<AnimationMetadata>()
            };
            var animations = new List<Animation>();
            var partsCount = Random.Next(metadata.MaxMovingParts - metadata.MinMovingParts) + metadata.MinMovingParts;
            AnimatedObject content = null;
            AnimationMetadata centerAnimationMetadata;

            if (metadata.CenterTextureName != string.Empty)
            {
                centerAnimationMetadata = new AnimationMetadata()
                {
                    TextureName = metadata.CenterTextureName,
                    Name = "Center",
                    FramesPerRow = metadata.CenterFrameCount,
                    Interval = metadata.CenterInterval,
                    IsLooped = metadata.IsCenterLooped,
                    SourceOffset = new Vector2(0, 0),
                    LastFrameHoldOnTime = 0,
                    Size = new Vector2(0, 0)
                };

                contentMetaData.Animations.Add(centerAnimationMetadata);
                content = AnimatedObject.FromMetadata(contentMetaData, contentManager);

                blow.Content = content;
                blow.Content.AddAnimationRule("Center", () => !blow._isFinished);
            }

            for (var i = 1; i <= partsCount; i++)
            {

                float radius = Random.Next(metadata.MovingPartsDispertion);
                float randomX = Random.Next(metadata.MovingPartsDispertion - 1) * (Random.Next(3) > 1 ? -1 : 1);
                float randomY = (float)Math.Sqrt(radius * radius - randomX * randomX) * (Random.Next(3) > 1 ? -1 : 1);

                var partAnimationMetaData = new AnimationMetadata()
                {
                    TextureName = metadata.MovingPartsTextureName,
                    Name = "Part_" + i,
                    FramesPerRow = metadata.MovingPartsFramesCount,
                    Interval = Random.Next(metadata.MovingPartsIntervalTop - metadata.MovingPartsIntervalBottom) + metadata.MovingPartsIntervalBottom,
                    IsLooped = metadata.AreMovingPartsLooped,
                    SourceOffset = new Vector2(randomX, randomY),
                    LastFrameHoldOnTime = 0,
                    Size = new Vector2(0, 0)
                };

                if (blow.Content == null)
                {
                    contentMetaData.Animations.Add(partAnimationMetaData);
                    content = AnimatedObject.FromMetadata(contentMetaData, contentManager);
                    blow.Content = content;

                    continue;
                }

                var partAnimation = Animation.FromMetadata(partAnimationMetaData, contentManager);

                blow.Content.Animations.Add(partAnimation);
                blow.MovingParts.Add(partAnimation);
                blow.Content.AddAnimationRule(partAnimation.Name, () => !blow._isFinished);
            }

            return blow;
        }
Beispiel #2
0
        public static Animation FromMetadata(AnimationMetadata metadata, ContentManager contentManager)
        {
            var animation = new Animation
            {
                Name = metadata.Name,
                Texture = contentManager.Load<Texture2D>(metadata.TextureName),
                FramesPerRow = metadata.FramesPerRow,
                Interval = metadata.Interval,
                SourceOffset = metadata.SourceOffset,
                Size = (metadata.Size.X <= 0.001 || metadata.Size.Y <= 0.001) ? (Vector2?) null : metadata.Size,
                LastFrameHoldOnTime = metadata.LastFrameHoldOnTime,
                IsLooped = metadata.IsLooped
            };

            animation.FrameDimensions =  new Point(animation.Texture.Width / animation.FramesPerRow, animation.Texture.Height);

            return animation;
        }