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