Esempio n. 1
0
        public static AnimatedObject FromMetadata(AnimatedObjectMetadata metadata, ContentManager contentManager)
        {
            var animatedObject = new AnimatedObject
            {
                Animations = metadata.Animations.Select(x => Animation.FromMetadata(x, contentManager)).ToList(),
                Size = (metadata.Size.X <= 0.001 || metadata.Size.Y <= 0.001) ? (Vector2?) null : metadata.Size
            };

            animatedObject.BoundingRectangle = animatedObject.GetCompositeFrameSize();
            animatedObject.AutoSize = new Vector2(animatedObject.BoundingRectangle.Width, animatedObject.BoundingRectangle.Height);
            animatedObject.CollisionRectangle = metadata.CollisionRectangle.X <= 0.001 ||
                metadata.CollisionRectangle.Y <= 0.001
                ? animatedObject.BoundingRectangle
                : metadata.CollisionRectangle;

            return animatedObject;
        }
Esempio n. 2
0
        public static BlowEffect FillWithMetadata(BlowEffect blow, BlowEffectMetadata metadata, ContentManager contentManager)
        {
            blow.MovingParts = new List<Animation>();
            blow.PartVelocity = metadata.PartVelocity;
            blow.Law = metadata.Law;
            blow._type = metadata.Type;
            blow.MetaData = metadata;

            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;
        }