Time for action – creating explosions
Add the
RandomDirection()
helper method to theExplosionManager
class:Public Function randomDirection(scale As Single) As Vector2 Dim direction As Vector2 Do direction = new Vector2( rand.Next(0, 101) - 50, rand.Next(0, 101) - 50) Loop While direction.Length() = 0 direction.Normalize() direction *= scale Return direction End Function
Add the
AddExplosion()
method to theExplosionManager
class:Public Sub AddExplosion( location As Vector2, momentum As Vector2) Dim pieceLocation As Vector2 = location - new Vector2(pieceRectangles(0).Width/2.0F, pieceRectangles(0).Height/2.0F) Dim pieces As Integer = rand.Next(minPieceCount, maxPieceCount + 1) For x As Integer = 1 to pieces ExplosionParticles.Add(new Particle( pieceLocation, _texture, pieceRectangles(rand.Next(0,pieceRectangles.Count)), randomDirection(pieceSpeedScale) + momentum, ...