BaseParticle.cs :  » Game » SDL » SdlDotNet » Particles » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » SDL 
SDL » SdlDotNet » Particles » BaseParticle.cs
#region LICENSE
/*
 * Copyright (C) 2005 Rob Loach (http://www.robloach.net)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#endregion LICENSE

using System;
using System.Drawing;
using System.Diagnostics.CodeAnalysis;

using SdlDotNet.Core;
using SdlDotNet.Graphics;
using SdlDotNet.Graphics.Sprites;

namespace SdlDotNet.Particles{
    /// <summary>
    /// An abstract class describing a base particle.
    /// </summary>
    /// <remarks>Some implementations of the particle class include ParticlePixel and ParticleSprite.</remarks>
    /// <example>This is an example of implementing a new kind of particle.  It creates a ParticleBox that uses blue boxes to represent particles:
    /// <code>
    /// public class ParticleBox : BaseParticle
    /// {
    ///    public override void Render(Surface destination)
    ///    {
    ///      destination.Draw(new Rectangle((int)this.X, (int)this.Y, 100,100), Color.Blue);
    ///    }
    /// }
    /// </code>
    /// </example>
    public abstract class BaseParticle
    {
        private int m_Life = -1;
        /// <summary>
        /// The current life of the particle. -1 means infinate life.
        /// </summary>
        /// <remarks>This is decreased when the Update method is called.</remarks>
        public int Life
        {
            get
            {
                return m_Life;
                //Surface a = new Surface();
            }
            set
            {
                m_Life = value;
            }
        }

        private int m_LifeFull = 100;
        /// <summary>
        /// Gets and sets the value representing the full life of the particle.
        /// </summary>
        /// <remarks>This is usually used when distinguishing when the particle should start dying out with alpha transparency.</remarks>
        public int LifeFull
        {
            get
            {
                return m_LifeFull;
            }
            set
            {
                m_LifeFull = value;
            }
        }

        private bool m_Static;
        /// <summary>
        /// Gets and sets whether the particle's velocity will change its location.
        /// </summary>
        /// <remarks>If set to true, the particle will not move.  If set to false, the particle will move with manipulators.</remarks>
        public bool Static
        {
            get
            {
                return m_Static;
            }
            set
            {
                m_Static = value;
            }
        }

        private float m_X;
        /// <summary>
        /// The X coordinate of the particle.
        /// </summary>
        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", Justification = "Correct Spelling")]
        public float X
        {
            get
            {
                return m_X;
            }
            set
            {
                m_X = value;
            }
        }
        private float m_Y;
        /// <summary>
        /// The Y coordinate of the particle.
        /// </summary>
        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", Justification = "Correct Spelling")]
        public float Y
        {
            get
            {
                return m_Y;
            }
            set
            {
                m_Y = value;
            }
        }

        private Vector m_Velocity = new Vector(0, 0, 0);
        /// <summary>
        /// The speed and direction the particle is going.
        /// </summary>
        public Vector Velocity
        {
            get
            {
                return m_Velocity;
            }
            set
            {
                m_Velocity = value;
            }
        }

        /// <summary>
        /// Draws the particle onto the destination.
        /// </summary>
        /// <param name="destination">The destination surface of the particle.</param>
        public abstract void Render(Surface destination);

        /// <summary>
        /// Updates the location and life of the particle.
        /// </summary>
        /// <returns>True if the particle is still alive, false if the particle is to be destroyed.</returns>
        public virtual bool Update()
        {
            if (m_Life == 0)
            {
                return false;
            }
            if (!m_Static)
            {
                m_X += m_Velocity.X;
                m_Y += m_Velocity.Y;
            }
            if (m_Life != -1) // -1 is alife forever.
            {
                if (--m_Life == 0)
                {
                    return false;
                }
            }
            return true;
        }

        /// <summary>
        /// Gets and sets the width of the particle.
        /// </summary>
        public abstract float Width
        {
            get;
            set;
        }

        /// <summary>
        /// Gets and sets the height of the particle.
        /// </summary>
        public abstract float Height
        {
            get;
            set;
        }

        /// <summary>
        /// Gets the y-coordinate of the bottom edge of the particle.
        /// </summary>
        public virtual float Bottom
        {
            get
            {
                return m_Y + Height;
            }
        }

        /// <summary>
        /// Gets the x-coordinate of the right edge of the particle.
        /// </summary>
        public virtual float Right
        {
            get
            {
                return m_X + Width;
            }
        }

        /// <summary>
        /// Gets the x-coordinate of the left edge of the particle.
        /// </summary>
        public virtual float Left
        {
            get
            {
                return m_X;
            }
        }

        /// <summary>
        /// Gets the y-coordinate of the top edge of the particle.
        /// </summary>
        public virtual float Top
        {
            get
            {
                return m_Y;
            }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.