Time for action – firing shots
Add the
FireShot()
method to the ShotManager class:public void FireShot( Vector2 location, Vector2 velocity, bool playerFired) { Sprite thisShot = new Sprite( location, Texture, InitialFrame, velocity); thisShot.Velocity *= shotSpeed; for (int x = 1; x < FrameCount; x++) { thisShot.AddFrame(new Rectangle( InitialFrame.X+(InitialFrame.Width * x), InitialFrame.Y, InitialFrame.Width, InitialFrame.Height)); } thisShot.CollisionRadius = CollisionRadius; Shots.Add(thisShot); }
What just happened?
When a shot is fired, a new Sprite (called thisShot
) is built using the parameters stored when the ShotManager class was constructed. The location and velocity are set according to the values passed to the FireShot()
method. The velocity passed in will be normalized by the code that fires the shot, and is multiplied here by the shotSpeed...