Play spurt animation on each growth step.

This commit is contained in:
Paul Chote
2017-02-05 13:23:48 +00:00
parent b018c3d837
commit cc3c618d60
4 changed files with 36 additions and 31 deletions

View File

@@ -32,6 +32,9 @@ namespace OpenRA.Mods.D2k.Traits
[SequenceReference]
public readonly string[] GrowthSequences = { "grow1", "grow2", "grow3" };
[SequenceReference]
public readonly string SpurtSequence = "spurt";
[Desc("The range of time (in ticks) that the spicebloom will take to grow until it blows up.")]
public readonly int[] Lifetime = { 1000, 3000 };
@@ -50,7 +53,7 @@ namespace OpenRA.Mods.D2k.Traits
[Desc("The maximum distance in cells that spice may be expelled.")]
public readonly int Range = 5;
public object Create(ActorInitializer init) { return new SpiceBloom(init, this); }
public object Create(ActorInitializer init) { return new SpiceBloom(init.Self, this); }
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
{
@@ -63,29 +66,34 @@ namespace OpenRA.Mods.D2k.Traits
public class SpiceBloom : ITick, INotifyKilled
{
readonly Actor self;
readonly SpiceBloomInfo info;
readonly ResourceType resType;
readonly ResourceLayer resLayer;
readonly AnimationWithOffset anim;
readonly Animation body;
readonly Animation spurt;
readonly int growTicks;
int ticks;
public SpiceBloom(ActorInitializer init, SpiceBloomInfo info)
int ticks;
int bodyFrame = 0;
bool showSpurt = true;
public SpiceBloom(Actor self, SpiceBloomInfo info)
{
this.info = info;
self = init.Self;
resLayer = self.World.WorldActor.Trait<ResourceLayer>();
resType = self.World.WorldActor.TraitsImplementing<ResourceType>().First(t => t.Info.Type == info.ResourceType);
var render = self.Trait<RenderSprites>();
anim = new AnimationWithOffset(new Animation(init.Self.World, render.GetImage(self)), null, () => self.IsDead);
render.Add(anim);
var rs = self.Trait<RenderSprites>();
body = new Animation(self.World, rs.GetImage(self));
rs.Add(new AnimationWithOffset(body, null, () => self.IsDead));
growTicks = self.World.SharedRandom.Next(info.Lifetime[0], info.Lifetime[1]);
anim.Animation.Play(info.GrowthSequences[0]);
body.Play(info.GrowthSequences[0]);
spurt = new Animation(self.World, rs.GetImage(self));
rs.Add(new AnimationWithOffset(spurt, null, () => !showSpurt));
spurt.PlayThen(info.SpurtSequence, () => showSpurt = false);
}
void ITick.Tick(Actor self)
@@ -102,8 +110,15 @@ namespace OpenRA.Mods.D2k.Traits
self.Kill(self);
else
{
var index = info.GrowthSequences.Length * ticks / growTicks;
anim.Animation.Play(info.GrowthSequences[index]);
var newBodyFrame = info.GrowthSequences.Length * ticks / growTicks;
if (newBodyFrame != bodyFrame)
{
bodyFrame = newBodyFrame;
body.Play(info.GrowthSequences[bodyFrame]);
showSpurt = true;
spurt.PlayThen(info.SpurtSequence, () => showSpurt = false);
}
}
}