add autofire (with a cooldown); don't shoot a plethora of shots at once

This commit is contained in:
Colin McMillen 2020-11-20 16:18:12 -05:00
parent ed3dd73493
commit 5d9a7205a1

View File

@ -11,6 +11,7 @@ namespace SemiColinGames {
public Vector2 Position = new Vector2(48, 1080 / 8); public Vector2 Position = new Vector2(48, 1080 / 8);
public Vector2 HalfSize = new Vector2(16, 10); public Vector2 HalfSize = new Vector2(16, 10);
public float Speed = 150f; public float Speed = 150f;
public float ShotCooldown = 0f;
} }
public class Shot { 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.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.Max(Player.Position.Y, Player.HalfSize.Y);
Player.Position.Y = Math.Min(Player.Position.Y, Bounds.Size.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) { foreach (Shot shot in Shots) {
shot.Update(modelTime); 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 shotOffset = new Vector2(12, 2);
Vector2 shotPosition = Vector2.Add(Player.Position, shotOffset); 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, 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)); Shots.RemoveAll(shot => !Bounds.Intersects(shot.Bounds));