/// <summary> /// Set the next animation, once the last one was finished. /// </summary> /// <param name="list">List of animations that can be executed.</param> /// <param name="where">Where the pet is "walking"</param> /// <returns>ID of the next animation to play. -1 if there is no animation.</returns> private int SetNextGeneralAnimation(List <TNextAnimation> list, TNextAnimation.TOnly where) { int iDefaultID = -1; if (list.Count > 0) // Find the next animation only if there is at least 1 animation in the list { int iVal; int iSum = 0; int iRandMax = 0; foreach (TNextAnimation anim in list) { if (anim.only != TNextAnimation.TOnly.NONE && (anim.only & where) == 0) { continue; } iRandMax += anim.Probability; } iVal = rand.Next(0, iRandMax); foreach (TNextAnimation anim in list) { if (anim.only != TNextAnimation.TOnly.NONE && (anim.only & where) == 0) { continue; } iSum += anim.Probability; if (iSum >= iVal) { iDefaultID = anim.ID; break; } } // If an animation was found, re-calculate the values (if there are some Random values, they must be evaluated again) if (iDefaultID > 0) { UpdateAnimationValues(iDefaultID); if (SheepSound.ContainsKey(iDefaultID)) { if (rand.Next(0, 100) < SheepSound[iDefaultID].Probability) { SheepSound[iDefaultID].Play(SheepSound[iDefaultID].Loop); } } } return(iDefaultID); } else { StartUp.AddDebugInfo(StartUp.DEBUG_TYPE.warning, "no next animation found"); return(-1); // a new spawn is requested } }
/// <summary> /// Start the next animation once the gravity was detected. /// </summary> /// <param name="animationID">ID of the animation.</param> /// <param name="where">Where the pet is "walking"</param> /// <returns>ID of the next animation to play. -1 if there is no animation.</returns> public int SetNextGravityAnimation(int animationID, TNextAnimation.TOnly where) { StartUp.AddDebugInfo(StartUp.DEBUG_TYPE.info, "gravity detected"); return(SetNextGeneralAnimation(SheepAnimations[animationID].EndGravity, where)); }
/// <summary> /// Start the next animation once the sequence was over. /// </summary> /// <param name="animationID">ID of the animation.</param> /// <param name="where">Where the pet is "walking"</param> /// <returns>ID of the next animation to play. -1 if there is no animation.</returns> public int SetNextSequenceAnimation(int animationID, TNextAnimation.TOnly where) { StartUp.AddDebugInfo(StartUp.DEBUG_TYPE.info, "animation is over"); return(SetNextGeneralAnimation(SheepAnimations[animationID].EndAnimation, where)); }
/// <summary> /// Start the next animation once the gravity was detected. /// </summary> /// <param name="animationID">ID of the animation.</param> /// <param name="where">Where the pet is "walking"</param> /// <returns>ID of the next animation to play. -1 if there is no animation.</returns> public int SetNextGravityAnimation(int animationID, TNextAnimation.TOnly where) { return(SetNextGeneralAnimation(SheepAnimations[animationID].EndGravity, where)); }
/// <summary> /// Start the next animation once the sequence was over. /// </summary> /// <param name="animationID">ID of the animation.</param> /// <param name="where">Where the pet is "walking"</param> /// <returns>ID of the next animation to play. -1 if there is no animation.</returns> public int SetNextSequenceAnimation(int animationID, TNextAnimation.TOnly where) { return(SetNextGeneralAnimation(SheepAnimations[animationID].EndAnimation, where)); }
/// <summary> /// Start the next animation once a border was detected. /// </summary> /// <param name="animationID">ID of the Animation.</param> /// <param name="where">Where the pet is "walking".</param> /// <returns>ID of the next animation to play. -1 if there is no animation.</returns> public int SetNextBorderAnimation(int animationID, TNextAnimation.TOnly where) { return(SetNextGeneralAnimation(SheepAnimations[animationID].EndBorder, where)); }
public void loadAnimations(Animations animations) { XmlNodeList nodes = xmlDoc.SelectNodes("//pet:animations/pet:animation", xmlNS); foreach (XmlNode node in nodes) { int id = int.Parse(node.Attributes["id"].InnerText); TAnimation ani = animations.AddAnimation(id, id.ToString()); ani.Border = false; ani.Gravity = false; foreach (XmlNode node2 in node.ChildNodes) { switch (node2.Name) { case "name": ani.Name = node2.InnerText; switch (ani.Name) { case "fall": animations.AnimationFall = id; break; case "drag": animations.AnimationDrag = id; break; case "kill": animations.AnimationKill = id; break; case "sync": animations.AnimationSync = id; break; } break; case "start": ani.Start.X.Compute = node2.SelectSingleNode(".//pet:x", xmlNS).InnerText; ani.Start.X.Random = (ani.Start.X.Compute.IndexOf("random") >= 0); ani.Start.X.Value = parseValue(ani.Start.X.Compute); ani.Start.Y.Compute = node2.SelectSingleNode(".//pet:y", xmlNS).InnerText; ani.Start.Y.Random = (ani.Start.Y.Compute.IndexOf("random") >= 0); ani.Start.Y.Value = parseValue(ani.Start.Y.Compute); ani.Start.Interval.Compute = node2.SelectSingleNode(".//pet:interval", xmlNS).InnerText; ani.Start.Interval.Random = (ani.Start.Interval.Compute.IndexOf("random") >= 0); ani.Start.Interval.Value = parseValue(ani.Start.Interval.Compute); break; case "end": ani.End.X.Compute = node2.SelectSingleNode(".//pet:x", xmlNS).InnerText; ani.End.X.Random = (ani.End.X.Compute.IndexOf("random") >= 0); ani.End.X.Value = parseValue(ani.End.X.Compute); ani.End.Y.Compute = node2.SelectSingleNode(".//pet:y", xmlNS).InnerText; ani.End.Y.Random = (ani.End.Y.Compute.IndexOf("random") >= 0); ani.End.Y.Value = parseValue(ani.End.Y.Compute); ani.End.Interval.Compute = node2.SelectSingleNode(".//pet:interval", xmlNS).InnerText; ani.End.Interval.Random = (ani.End.Interval.Compute.IndexOf("random") >= 0); ani.End.Interval.Value = parseValue(ani.End.Interval.Compute); break; case "sequence": ani.Sequence.RepeatFrom = int.Parse(node2.Attributes["repeatfrom"].InnerText); ani.Sequence.Repeat.Compute = node2.Attributes["repeat"].InnerText; if (node2.SelectSingleNode(".//pet:action", xmlNS) != null) { ani.Sequence.Action = node2.SelectSingleNode(".//pet:action", xmlNS).InnerText; } ani.Sequence.Repeat.Random = (ani.Sequence.Repeat.Compute.IndexOf("random") >= 0); ani.Sequence.Repeat.Value = parseValue(ani.Sequence.Repeat.Compute); foreach (XmlNode node3 in node2.SelectNodes(".//pet:frame", xmlNS)) { ani.Sequence.Frames.Add(int.Parse(node3.InnerText)); } 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; } foreach (XmlNode node3 in node2.SelectNodes(".//pet:next", xmlNS)) { TNextAnimation.TOnly where = TNextAnimation.TOnly.NONE; if (node3.Attributes["only"] != null) { switch (node3.Attributes["only"].InnerText) { 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; } } ani.EndAnimation.Add( new TNextAnimation( int.Parse(node3.InnerText), int.Parse(node3.Attributes["probability"].InnerText), where ) ); } break; case "border": foreach (XmlNode node3 in node2.SelectNodes(".//pet:next", xmlNS)) { TNextAnimation.TOnly where = TNextAnimation.TOnly.NONE; if (node3.Attributes["only"] != null) { switch (node3.Attributes["only"].InnerText) { 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; } } ani.Border = true; ani.EndBorder.Add( new TNextAnimation( int.Parse(node3.InnerText), int.Parse(node3.Attributes["probability"].InnerText), where ) ); } break; case "gravity": foreach (XmlNode node3 in node2.SelectNodes(".//pet:next", xmlNS)) { TNextAnimation.TOnly where = TNextAnimation.TOnly.NONE; if (node3.Attributes["only"] != null) { switch (node3.Attributes["only"].InnerText) { 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; } } ani.Gravity = true; ani.EndGravity.Add( new TNextAnimation( int.Parse(node3.InnerText), int.Parse(node3.Attributes["probability"].InnerText), where ) ); } break; } } animations.SaveAnimation(ani, id); } nodes = xmlDoc.SelectNodes("//pet:animations/pet:spawn", xmlNS); foreach (XmlNode node in nodes) { int id = int.Parse(node.Attributes["id"].InnerText); TSpawn ani = animations.AddSpawn(id, int.Parse(node.Attributes["probability"].InnerText), id.ToString()); foreach (XmlNode node2 in node.ChildNodes) { switch (node2.Name) { case "x": ani.Start.X.Compute = node2.InnerText; ani.Start.X.Random = (ani.Start.X.Compute.IndexOf("random") >= 0); ani.Start.X.Value = parseValue(ani.Start.X.Compute); break; case "y": ani.Start.Y.Compute = node2.InnerText; ani.Start.Y.Random = (ani.Start.Y.Compute.IndexOf("random") >= 0); ani.Start.Y.Value = parseValue(ani.Start.Y.Compute); break; case "direction": string sDirection = node2.InnerText; ani.MoveLeft = (sDirection == "left"); break; case "next": ani.Next = int.Parse(node2.InnerText); break; } } animations.SaveSpawn(ani, id); } }