Time for action – creating explosions
Add the
RandomDirection()
helper method to the ExplosionManager class:public Vector2 randomDirection(float scale) { Vector2 direction; do { direction = new Vector2( rand.Next(0, 101) - 50, rand.Next(0, 101) - 50); } while (direction.Length() == 0); direction.Normalize(); direction *= scale; return direction; }
Add the
AddExplosion()
method to the ExplosionManager class:public void AddExplosion(Vector2 location, Vector2 momentum) { Vector2 pieceLocation = location - new Vector2(pieceRectangles[0].Width/2, pieceRectangles[0].Height/2); int pieces = rand.Next(minPieceCount, maxPieceCount + 1); for (int x = 0; x < pieces; x++) { ExplosionParticles.Add(new Particle( pieceLocation, texture, pieceRectangles[rand.Next(0,pieceRectangles.Count)], randomDirection(pieceSpeedScale) + momentum, Vector2.Zero...