Time for action – implementing particles
To implement the particles for our game, perform the following steps:
1. In the
LoadContent()
method of theTankBattlesGame
class, initialize theParticleManager
as follows:ParticleManager.Initialize( GraphicsDevice, Content.Load<Effect>(@"Effects\Particles"), Content.Load<Texture2D>(@"Textures\Explosion"));
2. Add the
CheckForShotImpacts()
helper method to theTankBattlesGame
class as follows:private void CheckForShotImpacts() { if (!ShotManager.ShotActive && !ShotManager.HitProcessed) { Vector3 impactPoint = new Vector3( ShotManager.Position.X, 0, ShotManager.Position.Z); impactPoint.Y = terrain.GetHeight( impactPoint.X, impactPoint.Z); ParticleManager.MakeExplosion(impactPoint, 200); ShotManager.HitProcessed = true; } }
3. In the
Update()
method of theTankBattlesGame
class, add the following lines of code right after theShotManager
is updated:CheckForShotImpacts...