Example #1
0
        /// <summary>
        /// Update the values of the animation.<br />
        /// If "random" was used, on each start of a new animation this will change so the expression must be evaluated again.<br />
        /// Total steps are also calculated, so it has a better performance by playing it.
        /// </summary>
        /// <param name="id">ID of the Animation.</param>
        private void UpdateAnimationValues(int id)
        {
            bool       bUpdated = false;
            TAnimation ani      = SheepAnimations[id];

            if (ani.Sequence.Repeat.IsDynamic)
            {
                // Calculate the total steps, based on the repeat values.
                ani.Sequence.TotalSteps = ani.Sequence.CalculateTotalSteps();
                bUpdated = true;
            }
            if (ani.Start.Interval.IsDynamic || ani.Start.X.IsDynamic || ani.Start.Y.IsDynamic)
            {
                ani.Start.Interval.Value = ani.Start.Interval.GetValue();
                ani.Start.X.Value        = ani.Start.X.GetValue();
                ani.Start.Y.Value        = ani.Start.Y.GetValue();
                bUpdated = true;
            }
            if (ani.End.Interval.IsDynamic || ani.End.X.IsDynamic || ani.End.Y.IsDynamic)
            {
                ani.End.Interval.Value = ani.End.Interval.GetValue();
                ani.End.X.Value        = ani.End.X.GetValue();
                ani.End.Y.Value        = ani.End.Y.GetValue();
                bUpdated = true;
            }

            // If a value was changed, overwrite the old structure with the new one.
            if (bUpdated)
            {
                SheepAnimations[id] = ani;
            }
        }
Example #2
0
 /// <summary>
 /// Get the structure of the animation.
 /// </summary>
 /// <param name="id">ID of the wanted animation.</param>
 /// <returns>Structure with all information about this animation.</returns>
 public TAnimation GetAnimation(int id)
 {
     if (!SheepAnimations.ContainsKey(id))
     {
         TAnimation tempAnimation = new TAnimation("NULL", 0);
         tempAnimation.Start.Interval.Value = 1000;
         tempAnimation.End.Interval.Value   = 1000;
     }
     return(SheepAnimations[id]);
 }
Example #3
0
 /// <summary>
 /// After adding the animation and filling data, this function must be called to save values.
 /// </summary>
 /// <param name="animation">Structure of an animation.</param>
 /// <param name="ID">ID of the animation to save in.</param>
 public void SaveAnimation(TAnimation animation, int ID)
 {
     SheepAnimations[ID] = animation;
 }
Example #4
0
        /// <summary>
        /// Load the animations (read them from XML file)
        /// </summary>
        /// <param name="animations">Animation class where the animations should be saved</param>
        public void LoadAnimations(Animations animations)
        {
            // for each animation
            foreach (XmlData.AnimationNode node in AnimationXML.Animations.Animation)
            {
                TAnimation ani = animations.AddAnimation(node.Id, node.Id.ToString());
                ani.Border  = node.Border != null;
                ani.Gravity = node.Gravity != null;

                ani.Name = node.Name;
                switch (ani.Name)
                {
                case "fall": animations.AnimationFall = node.Id; break;

                case "drag": animations.AnimationDrag = node.Id; break;

                case "kill": animations.AnimationKill = node.Id; break;

                case "sync": animations.AnimationSync = node.Id; break;
                }

                ani.Start.X        = GetXMLCompute(node.Start.X, "animation " + node.Id + ": node.start.X");
                ani.Start.Y        = GetXMLCompute(node.Start.Y, "animation " + node.Id + ": node.start.Y");
                ani.Start.Interval = GetXMLCompute(node.Start.Interval, "animation " + node.Id + ": node.start.Interval");
                ani.Start.OffsetY  = node.Start.OffsetY;
                ani.Start.Opacity  = node.Start.Opacity;

                ani.End.X        = GetXMLCompute(node.End.X, "animation " + node.Id + ": node.end.X");
                ani.End.Y        = GetXMLCompute(node.End.Y, "animation " + node.Id + ": node.end.Y");
                ani.End.Interval = GetXMLCompute(node.End.Interval, "animation " + node.Id + ": node.end.Interval");
                ani.End.OffsetY  = node.End.OffsetY;
                ani.End.Opacity  = node.End.Opacity;

                ani.Sequence.RepeatFrom = node.Sequence.RepeatFromFrame;
                ani.Sequence.Action     = node.Sequence.Action;
                ani.Sequence.Repeat     = GetXMLCompute(node.Sequence.RepeatCount, "animation " + node.Id + ": node.sequence.Repeat");
                ani.Sequence.Frames.AddRange(node.Sequence.Frame);
                if (ani.Sequence.RepeatFrom > 0)
                {
                    ani.Sequence.TotalSteps = ani.Sequence.Frames.Count + (ani.Sequence.Frames.Count - ani.Sequence.RepeatFrom - 1) * ani.Sequence.Repeat.Value;
                }
                else
                {
                    ani.Sequence.TotalSteps = ani.Sequence.Frames.Count + ani.Sequence.Frames.Count * ani.Sequence.Repeat.Value;
                }
                if (node.Sequence.Next != null)
                {
                    foreach (XmlData.NextNode nextNode in node.Sequence.Next)
                    {
                        TNextAnimation.TOnly where;
                        switch (nextNode.OnlyFlag)
                        {
                        case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break;

                        case "window": where = TNextAnimation.TOnly.WINDOW; break;

                        case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break;

                        case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break;

                        case "vertical": where = TNextAnimation.TOnly.VERTICAL; break;

                        default: where = TNextAnimation.TOnly.NONE; break;
                        }

                        ani.EndAnimation.Add(
                            new TNextAnimation(
                                nextNode.Value,
                                nextNode.Probability,
                                where
                                )
                            );
                    }
                }

                if (ani.Border)
                {
                    foreach (XmlData.NextNode nextNode in node.Border.Next)
                    {
                        TNextAnimation.TOnly where;
                        switch (nextNode.OnlyFlag)
                        {
                        case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break;

                        case "window": where = TNextAnimation.TOnly.WINDOW; break;

                        case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break;

                        case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break;

                        case "vertical": where = TNextAnimation.TOnly.VERTICAL; break;

                        default: where = TNextAnimation.TOnly.NONE; break;
                        }
                        ani.Border = true;
                        ani.EndBorder.Add(
                            new TNextAnimation(
                                nextNode.Value,
                                nextNode.Probability,
                                where
                                )
                            );
                    }
                }

                if (ani.Gravity)
                {
                    foreach (XmlData.NextNode nextNode in node.Gravity.Next)
                    {
                        TNextAnimation.TOnly where;
                        switch (nextNode.OnlyFlag)
                        {
                        case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break;

                        case "window": where = TNextAnimation.TOnly.WINDOW; break;

                        case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break;

                        case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break;

                        case "vertical": where = TNextAnimation.TOnly.VERTICAL; break;

                        default: where = TNextAnimation.TOnly.NONE; break;
                        }
                        ani.Gravity = true;
                        ani.EndGravity.Add(
                            new TNextAnimation(
                                nextNode.Value,
                                nextNode.Probability,
                                where
                                )
                            );
                    }
                }

                animations.SaveAnimation(ani, node.Id);
            }

            // for each spawn
            if (AnimationXML.Spawns.Spawn != null)
            {
                foreach (XmlData.SpawnNode node in AnimationXML.Spawns.Spawn)
                {
                    TSpawn ani = animations.AddSpawn(
                        node.Id,
                        node.Probability);

                    ani.Start.X = GetXMLCompute(node.X, "spawn " + node.Id + ": node.X");
                    ani.Start.Y = GetXMLCompute(node.Y, "spawn " + node.Id + ": node.X");
                    ani.Next    = node.Next.Value;

                    animations.SaveSpawn(ani, node.Id);
                }
            }

            // for each child
            if (AnimationXML.Childs.Child != null)
            {
                foreach (XmlData.ChildNode node in AnimationXML.Childs.Child)
                {
                    TChild aniChild = animations.AddChild(node.Id);
                    aniChild.AnimationID = node.Id;

                    aniChild.Position.X = GetXMLCompute(node.X, "child " + node.Id + ": node.X");
                    aniChild.Position.Y = GetXMLCompute(node.Y, "child " + node.Id + ": node.Y");
                    aniChild.Next       = node.Next;

                    animations.SaveChild(aniChild, node.Id);
                }
            }

            // for each sound
            if (AnimationXML.Sounds != null && AnimationXML.Sounds.Sound != null)
            {
                foreach (XmlData.SoundNode node in AnimationXML.Sounds.Sound)
                {
                    animations.AddSound(node.Id, node.Probability, node.Loop, node.Base64);
                }
            }
        }