public void AddBlow(BlowType blowType, BlowEffect blow) { BlowCache.Add(new BlowEffectBox() { BlowType = blowType, BlowEffect = blow }); }
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; }