Time for action – the Particle class-part 1
To add
particles to our game using the Particle
class, perform the following steps:
1. Add a new class file called
Particle.cs
to the Tank Battles project.2. Add the following declarations at the beginning of the
Particle
class file:using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics;
3. Add a region of static fields to the
Partic
le
class as follows:#region Static Fields public static GraphicsDevice GraphicsDevice; private static Vector3 Gravity = new Vector3(0, -5, 0); private static VertexBuffer vertexBuffer; private static IndexBuffer indexBuffer; #endregion
4. Add a region of non-static fields to the
Partic
le
class as follows:#region Instance Fields private Vector3 position; private Vector3 velocity; public float duration; private float initialDuration; private float scale; #endregion
5. Add the following property to the
Particle
class:#region Properties public bool IsActive { get { return (duration > 0); }} #endregion
6...