From 5d9a7205a1f0ef36614e3030afb531380dc9f8b9 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Fri, 20 Nov 2020 16:18:12 -0500 Subject: [PATCH] add autofire (with a cooldown); don't shoot a plethora of shots at once --- Shared/ShmupWorld.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Shared/ShmupWorld.cs b/Shared/ShmupWorld.cs index e717fde..61d719c 100644 --- a/Shared/ShmupWorld.cs +++ b/Shared/ShmupWorld.cs @@ -11,6 +11,7 @@ namespace SemiColinGames { public Vector2 Position = new Vector2(48, 1080 / 8); public Vector2 HalfSize = new Vector2(16, 10); public float Speed = 150f; + public float ShotCooldown = 0f; } public class Shot { @@ -70,25 +71,18 @@ namespace SemiColinGames { Player.Position.X = Math.Min(Player.Position.X, Bounds.Size.X - Player.HalfSize.X); Player.Position.Y = Math.Max(Player.Position.Y, Player.HalfSize.Y); Player.Position.Y = Math.Min(Player.Position.Y, Bounds.Size.Y - Player.HalfSize.Y); + Player.ShotCooldown -= modelTime; foreach (Shot shot in Shots) { shot.Update(modelTime); } - if (input[0].Attack && !input[1].Attack) { + // TODO: move this all into Player.Update(). + if (input[0].Attack && Player.ShotCooldown <= 0) { + Player.ShotCooldown = 0.2f; Vector2 shotOffset = new Vector2(12, 2); Vector2 shotPosition = Vector2.Add(Player.Position, shotOffset); - Shots.Add(new Shot(shotPosition, new Vector2(300, -50))); - Shots.Add(new Shot(shotPosition, new Vector2(300, -40))); - Shots.Add(new Shot(shotPosition, new Vector2(300, -30))); - Shots.Add(new Shot(shotPosition, new Vector2(300, -20))); - Shots.Add(new Shot(shotPosition, new Vector2(300, -10))); Shots.Add(new Shot(shotPosition, new Vector2(300, 0))); - Shots.Add(new Shot(shotPosition, new Vector2(300, 10))); - Shots.Add(new Shot(shotPosition, new Vector2(300, 20))); - Shots.Add(new Shot(shotPosition, new Vector2(300, 30))); - Shots.Add(new Shot(shotPosition, new Vector2(300, 40))); - Shots.Add(new Shot(shotPosition, new Vector2(300, 50))); } Shots.RemoveAll(shot => !Bounds.Intersects(shot.Bounds));