diff --git a/Shared/ShmupWorld.cs b/Shared/ShmupWorld.cs index e0b129e..eba64f2 100644 --- a/Shared/ShmupWorld.cs +++ b/Shared/ShmupWorld.cs @@ -14,10 +14,9 @@ namespace SemiColinGames { private float speed = 150f; private float shotCooldown = 0f; - private ProfilingList shots = new ProfilingList(10, "playerShots"); - public ProfilingList Update( - float modelTime, History input, Rectangle worldBounds) { + public void Update(float modelTime, History input, Rectangle worldBounds, + ProfilingList newShots) { // Movement update. Vector2 motion = Vector2.Multiply(input[0].Motion, modelTime * speed); Position = Vector2.Add(Position, motion); @@ -28,14 +27,12 @@ namespace SemiColinGames { // Check whether we need to add new shots. shotCooldown -= modelTime; - shots.Clear(); if (input[0].Attack && shotCooldown <= 0) { shotCooldown = 0.2f; Vector2 shotOffset = new Vector2(12, 2); Vector2 shotPosition = Vector2.Add(Position, shotOffset); - shots.Add(new Shot(shotPosition, new Vector2(300, 0))); + newShots.Add(new Shot(shotPosition, new Vector2(300, 0))); } - return shots; } public void Draw(SpriteBatch spriteBatch) { @@ -108,6 +105,7 @@ namespace SemiColinGames { public readonly ShmupPlayer Player; public readonly ProfilingList Enemies; public readonly ProfilingList Shots; + private ProfilingList newShots; public ShmupWorld() { Bounds = new Rectangle(0, 0, 1920 / 4, 1080 / 4); @@ -115,6 +113,7 @@ namespace SemiColinGames { Enemies = new ProfilingList(100, "enemies"); Enemies.Add(new Enemy()); Shots = new ProfilingList(100, "shots"); + newShots = new ProfilingList(100, "newShots"); } ~ShmupWorld() { @@ -127,7 +126,8 @@ namespace SemiColinGames { public void Update(float modelTime, History input) { // Update player, enemies, & shots. - ProfilingList newPlayerShots = Player.Update(modelTime, input, Bounds); + newShots.Clear(); + Player.Update(modelTime, input, Bounds, newShots); foreach (Enemy enemy in Enemies) { enemy.Update(modelTime); } @@ -136,7 +136,7 @@ namespace SemiColinGames { } // Add new shots. - Shots.AddRange(newPlayerShots); + Shots.AddRange(newShots); // Reap off-screen objects. Rectangle paddedBounds = Bounds;