Time for action – firing shots
Add the
FireShot()
method to theShotManager
class:Public Sub FireShot( location As Vector2, velocity As Vector2, playerFired as Boolean) Dim modifiedVelocity As Vector2 = velocity modifiedVelocity.Normalize() modifiedVelocity *= _shotSpeed Dim thisShot as Sprite = new Sprite( location, _texture, _initialFrame, modifiedVelocity) For x As Integer = 1 to _frameCount - 1 thisShot.AddFrame(New Rectangle( _initialFrame.X+(_initialFrame.Width * x), _initialFrame.Y, _initialFrame.Width, _initialFrame.Height)) Next thisShot.CollisionRadius = _collisionRadius Shots.Add(thisShot) End Sub
What just happened?
When a shot is fired, we normalize the velocity passed into the function, so that we can standardize the speed of the projectile. Then a new sprite (called thisShot
) is built using the parameters stored, when the ShotManager
class...