コード例 #1
0
        /// <summary>
        /// Moves the currently active Animation one ticks further in its sequence.
        /// </summary>
        public void Update()
        {
            if (CurrentAnimation == null || CurrentElement == null)
            {
                return;
            }

            m_finishedanimation = false;
            ++m_animationtime;

            if (m_elementswitchtime == -1)
            {
                return;
            }

            if (m_elementswitchtime > 1)
            {
                --m_elementswitchtime;
            }
            else
            {
                AnimationElement newlement = CurrentAnimation.GetNextElement(CurrentElement.Id);

                if (newlement.Id <= CurrentElement.Id)
                {
                    m_animationinloop   = true;
                    m_finishedanimation = true;
                }

                m_currentelement    = newlement;
                m_elementswitchtime = CurrentElement.Gameticks;
            }
        }
コード例 #2
0
ファイル: MugenTest.cs プロジェクト: xubingyue/xnamugen
        void DrawElement(Vector2 location, Animations.AnimationElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            Vector2 scale = new Vector2(1, 1);

            Video.DrawState drawstate = m_sprites.SetupDrawing(element.SpriteId, location, element.Offset, scale, SpriteEffects.None);
            drawstate.Blending = element.Blending;
            drawstate.Use();

            /*
             * Drawing.Sprite sprite = m_sprites.GetSprite(element.SpriteId);
             * if (sprite != null)
             * {
             *      Vector2 spritelocation = Video.Renderer.GetDrawLocation(sprite.Size, location, (Vector2)sprite.Axis - element.Offset, scale, SpriteEffects.None);
             *      drawstate.Reset();
             *      drawstate.Mode = DrawMode.OutlinedRectangle;
             *      drawstate.AddData(spritelocation, new Rectangle(0, 0, sprite.Size.X, sprite.Size.Y), Color.Gray);
             *      drawstate.Scale = scale;
             *      drawstate.Use();
             * }
             *
             * drawstate.Reset();
             * drawstate.Mode = DrawMode.OutlinedRectangle;
             *
             * foreach (Animations.Clsn clsn in element)
             * {
             *      Rectangle rect = clsn.MakeRect(location, scale, Facing.Right);
             *
             *      switch (clsn.ClsnType)
             *      {
             *              case ClsnType.Type1Attack:
             *                      drawstate.AddData(new Vector2(rect.X, rect.Y), new Rectangle(0, 0, rect.Width, rect.Height), Color.Red);
             *                      break;
             *
             *              case ClsnType.Type2Normal:
             *                      drawstate.AddData(new Vector2(rect.X, rect.Y), new Rectangle(0, 0, rect.Width, rect.Height), Color.Blue);
             *                      break;
             *      }
             * }
             *
             * drawstate.Use();
             *
             *
             * Int32 line_length = 3;
             * drawstate.Reset();
             * drawstate.Mode = DrawMode.Lines;
             * drawstate.AddData(location - new Vector2(line_length, 0), null, Color.Black);
             * drawstate.AddData(location + new Vector2(line_length, 0), null, Color.Black);
             * drawstate.AddData(location - new Vector2(0, line_length), null, Color.Black);
             * drawstate.AddData(location + new Vector2(0, line_length), null, Color.Black);
             * drawstate.Use();
             */
        }
コード例 #3
0
ファイル: MugenTest.cs プロジェクト: xubingyue/xnamugen
        protected override void Draw(GameTime gameTime)
        {
            m_subsystems.GetSubSystem <Video.VideoSystem>().ClearScreen(Color.CornflowerBlue);

            Animations.AnimationElement currentelement = m_animations.CurrentElement;
            Vector2 location = (Vector2)Mugen.ScreenSize / 2;

            DrawElement(location, currentelement);
        }
コード例 #4
0
        /// <summary>
        /// Changes the active Animation.
        /// </summary>
        /// <param name="animation">The new Animation.</param>
        /// <param name="element">The new AnimationElement of the given Animation.</param>
        private void SetAnimation(Animation animation, AnimationElement element)
        {
            if (animation == null)
            {
                throw new ArgumentNullException(nameof(animation));
            }
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            m_currentanimation = animation;
            m_currentelement   = element;

            m_finishedanimation = false;
            m_animationinloop   = false;
            m_animationtime     = CurrentAnimation.GetElementStartTime(CurrentElement.Id);
            m_elementswitchtime = CurrentElement.Gameticks;
        }
コード例 #5
0
ファイル: Animation.cs プロジェクト: xubingyue/xnamugen
        /// <summary>
        /// Return a element from this Animation that would be drawn when this Animation has been drawn for the given time, in gameticks.
        /// </summary>
        /// <param name="time">The time, in gameticks.</param>
        /// <returns>The element that would be drawn at the given time.</returns>
        public AnimationElement GetElementFromTime(Int32 time)
        {
            if (time < 0)
            {
                throw new ArgumentOutOfRangeException("time");
            }

            for (AnimationElement element = Elements[0]; element != null; element = GetNextElement(element.Id))
            {
                if (element.Gameticks == -1)
                {
                    return(element);
                }

                time -= element.Gameticks;
                if (time < 0)
                {
                    return(element);
                }
            }

            throw new InvalidOperationException();
        }
コード例 #6
0
ファイル: AnimationLoader.cs プロジェクト: xubingyue/xnamugen
        /// <summary>
        /// Creates a new Animation.
        /// </summary>
        /// <param name="section">The information used to intialize the Animation.</param>
        /// <returns>A new instance of the Animation class if it could be created; null otherwise.</returns>
        Animation CreateAnimation(TextSection section)
        {
            if (section == null)
            {
                throw new ArgumentNullException("section");
            }

            Match titlematch = m_animationtitleregex.Match(section.Title);

            if (titlematch.Success == false)
            {
                return(null);
            }

            StringComparer sc = StringComparer.OrdinalIgnoreCase;

            Int32 animationnumber            = Int32.Parse(titlematch.Groups[1].Value);
            Int32 loopstart                  = 0;
            Int32 starttick                  = 0;
            List <AnimationElement> elements = new List <AnimationElement>();

            List <Clsn> loading_type1 = new List <Clsn>();
            List <Clsn> loading_type2 = new List <Clsn>();
            List <Clsn> default_type1 = new List <Clsn>();
            List <Clsn> default_type2 = new List <Clsn>();

            Boolean  loaddefault = false;
            ClsnType loadtype    = ClsnType.None;
            Int32    loadcount   = 0;

            foreach (String line in section.Lines)
            {
                if (loadcount > 0)
                {
                    Clsn?clsn = CreateClsn(line, loadtype);
                    if (clsn != null)
                    {
                        if (loaddefault == true)
                        {
                            if (loadtype == ClsnType.Type1Attack)
                            {
                                default_type1.Add(clsn.Value);
                            }
                            if (loadtype == ClsnType.Type2Normal)
                            {
                                default_type2.Add(clsn.Value);
                            }
                        }
                        else
                        {
                            if (loadtype == ClsnType.Type1Attack)
                            {
                                loading_type1.Add(clsn.Value);
                            }
                            if (loadtype == ClsnType.Type2Normal)
                            {
                                loading_type2.Add(clsn.Value);
                            }
                        }
                    }
                    else
                    {
                        Log.Write(LogLevel.Warning, LogSystem.AnimationSystem, "Could not create Clsn from line: {0}", line);
                    }

                    --loadcount;
                    continue;
                }

                Match clsnmatch = m_clsnregex.Match(line);
                if (clsnmatch.Success == true)
                {
                    ClsnType clsntype = ClsnType.None;
                    if (sc.Equals(clsnmatch.Groups[1].Value, "1") == true)
                    {
                        clsntype = ClsnType.Type1Attack;
                    }
                    if (sc.Equals(clsnmatch.Groups[1].Value, "2") == true)
                    {
                        clsntype = ClsnType.Type2Normal;
                    }

                    Boolean isdefault = sc.Equals(clsnmatch.Groups[2].Value, "default");
                    if (isdefault == true)
                    {
                        if (clsntype == ClsnType.Type1Attack)
                        {
                            default_type1.Clear();
                        }
                        if (clsntype == ClsnType.Type2Normal)
                        {
                            default_type2.Clear();
                        }
                    }

                    loadcount   = Int32.Parse(clsnmatch.Groups[3].Value);
                    loaddefault = isdefault;
                    loadtype    = clsntype;
                    continue;
                }

                if (sc.Equals(line, "Loopstart") == true)
                {
                    loopstart = elements.Count;
                    continue;
                }

                AnimationElement element = CreateElement(line, elements.Count, starttick, default_type1, default_type2, loading_type1, loading_type2);
                if (element != null)
                {
                    if (element.Gameticks == -1)
                    {
                        starttick = -1;
                    }
                    else
                    {
                        starttick += element.Gameticks;
                    }

                    elements.Add(element);

                    loading_type1.Clear();
                    loading_type2.Clear();
                }
                else
                {
                    Log.Write(LogLevel.Warning, LogSystem.AnimationSystem, "Error parsing element for Animation #{0} - {1}", animationnumber, line);
                }
            }

            if (elements.Count == 0)
            {
                Log.Write(LogLevel.Warning, LogSystem.AnimationSystem, "No elements defined for Animation #{0}", animationnumber);
                return(null);
            }
            else
            {
                if (loopstart == elements.Count)
                {
                    loopstart = 0;
                }

                return(new Animation(animationnumber, loopstart, elements));
            }
        }
コード例 #7
0
ファイル: AnimationLoader.cs プロジェクト: xubingyue/xnamugen
        /// <summary>
        /// Creates a new AnimationElement initialized from a line of text.
        /// </summary>
        /// <param name="line"></param>
        /// <param name="elementid"></param>
        /// <param name="default_clsn"></param>
        /// <param name="loading_clsn"></param>
        /// <returns></returns>
        AnimationElement CreateElement(String line, Int32 elementid, Int32 starttick, List <Clsn> default_type1, List <Clsn> default_type2, List <Clsn> loading_type1, List <Clsn> loading_type2)
        {
            if (line == null)
            {
                throw new ArgumentNullException("line");
            }
            if (elementid < 0)
            {
                throw new ArgumentOutOfRangeException("elementid");
            }
            if (starttick < 0)
            {
                throw new ArgumentOutOfRangeException("starttick");
            }
            if (default_type1 == null)
            {
                throw new ArgumentNullException("default_type1");
            }
            if (default_type2 == null)
            {
                throw new ArgumentNullException("default_type2");
            }
            if (loading_type1 == null)
            {
                throw new ArgumentNullException("loading_type1");
            }
            if (loading_type2 == null)
            {
                throw new ArgumentNullException("loading_type2");
            }

            String[] elements = m_elementregex.Split(line);
            if (elements == null)
            {
                return(null);
            }

            Int32 groupnumber;

            if (Int32.TryParse(elements[0], out groupnumber) == false)
            {
                return(null);
            }

            Int32 imagenumber;

            if (Int32.TryParse(elements[1], out imagenumber) == false)
            {
                return(null);
            }

            Int32 offset_x;

            if (Int32.TryParse(elements[2], out offset_x) == false)
            {
                return(null);
            }

            Int32 offset_y;

            if (Int32.TryParse(elements[3], out offset_y) == false)
            {
                return(null);
            }

            Int32 gameticks;

            if (Int32.TryParse(elements[4], out gameticks) == false)
            {
                return(null);
            }

            SpriteEffects flip = SpriteEffects.None;

            if (elements.Length >= 6)
            {
                if (elements[5].IndexOf('H') != -1 || elements[5].IndexOf('h') != -1)
                {
                    flip |= SpriteEffects.FlipHorizontally;
                }
                if (elements[5].IndexOf('V') != -1 || elements[5].IndexOf('v') != -1)
                {
                    flip |= SpriteEffects.FlipVertically;
                }
            }

            Blending blending = new Blending();

            if (elements.Length >= 7)
            {
                blending = m_animationsystem.GetSubSystem <StringConverter>().Convert <Blending>(elements[6]);
            }

            List <Clsn> clsn = new List <Clsn>();

            clsn.AddRange(loading_type1.Count != 0 ? loading_type1 : default_type1);
            clsn.AddRange(loading_type2.Count != 0 ? loading_type2 : default_type2);

            AnimationElement element = new AnimationElement(elementid, clsn, gameticks, starttick, new SpriteId(groupnumber, imagenumber), new Point(offset_x, offset_y), flip, blending);

            return(element);
        }
コード例 #8
0
		/// <summary>
		/// Changes the active Animation.
		/// </summary>
		/// <param name="animation">The new Animation.</param>
		/// <param name="element">The new AnimationElement of the given Animation.</param>
		void SetAnimation(Animation animation, AnimationElement element)
		{
			if (animation == null) throw new ArgumentNullException("animation");
			if (element == null) throw new ArgumentNullException("element");

			m_currentanimation = animation;
			m_currentelement = element;

			m_finishedanimation = false;
			m_animationinloop = false;
			m_animationtime = CurrentAnimation.GetElementStartTime(CurrentElement.Id);
			m_elementswitchtime = CurrentElement.Gameticks;
		}
コード例 #9
0
ファイル: AnimationLoader.cs プロジェクト: lodossDev/xnamugen
		/// <summary>
		/// Creates a new AnimationElement initialized from a line of text.
		/// </summary>
		/// <param name="line"></param>
		/// <param name="elementid"></param>
		/// <param name="default_clsn"></param>
		/// <param name="loading_clsn"></param>
		/// <returns></returns>
		AnimationElement CreateElement(String line, Int32 elementid, Int32 starttick, List<Clsn> default_type1, List<Clsn> default_type2, List<Clsn> loading_type1, List<Clsn> loading_type2)
		{
			if (line == null) throw new ArgumentNullException("line");
			if (elementid < 0) throw new ArgumentOutOfRangeException("elementid");
			if (starttick < 0) throw new ArgumentOutOfRangeException("starttick");
			if (default_type1 == null) throw new ArgumentNullException("default_type1");
			if (default_type2 == null) throw new ArgumentNullException("default_type2");
			if (loading_type1 == null) throw new ArgumentNullException("loading_type1");
			if (loading_type2 == null) throw new ArgumentNullException("loading_type2");

			String[] elements = m_elementregex.Split(line);
			if (elements == null) return null;

			Int32 groupnumber;
			if (Int32.TryParse(elements[0], out groupnumber) == false) return null;

			Int32 imagenumber;
			if (Int32.TryParse(elements[1], out imagenumber) == false) return null;

			Int32 offset_x;
			if (Int32.TryParse(elements[2], out offset_x) == false) return null;

			Int32 offset_y;
			if (Int32.TryParse(elements[3], out offset_y) == false) return null;

			Int32 gameticks;
			if (Int32.TryParse(elements[4], out gameticks) == false) return null;

			SpriteEffects flip = SpriteEffects.None;
			if (elements.Length >= 6)
			{
				if (elements[5].IndexOf('H') != -1 || elements[5].IndexOf('h') != -1) flip |= SpriteEffects.FlipHorizontally;
				if (elements[5].IndexOf('V') != -1 || elements[5].IndexOf('v') != -1) flip |= SpriteEffects.FlipVertically;
			}

			Blending blending = new Blending();
			if (elements.Length >= 7)
			{
				blending = m_animationsystem.GetSubSystem<StringConverter>().Convert<Blending>(elements[6]);
			}

			List<Clsn> clsn = new List<Clsn>();
			clsn.AddRange(loading_type1.Count != 0 ? loading_type1 : default_type1);
			clsn.AddRange(loading_type2.Count != 0 ? loading_type2 : default_type2);

			AnimationElement element = new AnimationElement(elementid, clsn, gameticks, starttick, new SpriteId(groupnumber, imagenumber), new Point(offset_x, offset_y), flip, blending);
			return element;
		}