I’ve fixed the zooming issue and also implemented easing in and out.  The main thing remaining to add is Particle Animations; those may wait a couple of days as my main goal was to get the data-driven animation infrastructure in place and running.

You can tie an Animation to any Event; in the Xml snippet below, it’s triggered by the “StartResting” Event that’s associated with the “SelfAnimation” field of the Item which the Player is wielding:

    <Weapon Id="Axe1" Name="Rusty Hatchet of Resftul Mapping" Subclass="Axe" WeaponPower="10" ItemLevel="1" Level="1-3"
            Tile="AxeBeaked" Description="A rusty hatchet">
      <Event Type="StartResting" OnFireText="You sense the world around you" SelfAnimation="MoveTest">
        <MagicMapping Amount="1%"/>
      </Event>
    </Weapon>

Here’s a quick video clip of what the Animation from my previous post looks like:

The data-driven Animation classes themselves are straightforward; the only part worth calling out is that I leverage a set of override values (ForcedMoveAmount, ForcedScaleAmount, etc), and instead of a boolean for “ForceMove”, I use a ref-count like model which supports multiple Animations working on the same object at the same time. Here’s the complete code for AnimationKeyFrame_Move; most of it is just determining which easing type to use:

    class AnimationKeyFrame_Move : AnimationKeyFrame
    {
        public AnimationKeyFrame_Move(KeyframeAppliedTo appliedTo, int appliedToTileIndex)
            : base(appliedTo, appliedToTileIndex)
        {
        }
        public override void Render(int timeTick, float percentDone, GameObject performer, GameObject target)
        {
            switch (Easing)
            {
                case Easing.EaseOut:
                    performer.ForcedMoveAmount += (EndLoc - StartLoc) * percentDone * percentDone + StartLoc;
                    break;

                case Easing.EaseIn:
                    performer.ForcedMoveAmount += (StartLoc - EndLoc) * (1 - percentDone) * (1 - percentDone) + EndLoc;
                    break;

                case Easing.Linear:
                    performer.ForcedMoveAmount += StartLoc + (EndLoc - StartLoc) * percentDone;
                    break;
            }
        }

        public override void Start(GameObject performer, GameObject target)
        {
            // We're within the keyframe's slot - force a move.  Do this as a 'refcount' to
            // support multiple simultaneous animations
            performer.ForceMove++;
        }

        public override void End(GameObject performer, GameObject target)
        {
            performer.ForceMove--;
        }

        public Vector2 EndLoc;
        public Vector2 StartLoc;
    }

One bit of hackery to eventually replace is that I’ve modified the render loop to run as a series of render phases; this allows Animations to specify whether they should render on top of or underneath objects; it also ensures that tiles don’t draw over objects when the objects scale or move. I believe I can actually do away with the entire multipass approach and just leverage the depthbuffer using pre-defined depth values. For instance, if all tiles rendered at depth 1, and all objects rendered at depth .5, then an Animation can simply be rendered at .75 or .25 depending on whether it should appear under or over objects…

An interesting question that this raises: what happens if the user moves while a long animation is playing?  What if they perform the same Animation-generating Action multiple times in quick succession? Should the animation stop (jarring)?  Should the user not be allowed to move while animations are playing (forces slow gameplay)?  Should all animations be required to be short (limiting)?  I’m honestly not sure…  I ran into the same issue with the floating combat text – if the user attacks a bunch of times in succession then they get overlapping text.  I’m… not sure what the right answer is here yet.

Updated source: http://wanderlinggames.com/files/dungeon/dungeon-4-11-11.zip

Updated executable: http://wanderlinggames.com/files/dungeon/dungeonexe-4-11-11.zip

Advertisements