public int Update(GameWindow window, GameTime gameTime) { closestLength = 100000; closestEnemy = null; foreach (Enemy enemy in Enemies.ToArray()) { if ((enemy.Center - player.Center).Length() < closestLength && enemy.Y < player.Y && !enemy.IsDying) { closestLength = (enemy.Position - player.Position).Length(); closestEnemy = enemy; } foreach (Projectile bullet in player.Bullets) if (enemy.IsColliding(bullet) && bullet.Y > 0 && enemy.IsAlive && bullet.IsAlive) { enemy.Health--; bullet.Health--; } if (enemy.IsAlive && enemy.IsColliding(player)) { player.Health--; enemy.Health--; } enemy.Update(window); } return !player.IsAlive ? (int) Level.LevelState.GameOver : (player.Pause ? (int) Level.LevelState.Pause : (int) Level.LevelState.Active); }
public static Formation VShape(Vector2 position, float angle, int spacing, int numLayers, Enemy enemy) { Formation v = new Formation(); v.Add(Enemy.Standard(position, enemy.Speed)); float dY = (float)Math.Sin(angle) * spacing; float dX = (float)Math.Cos(angle) * spacing; for (int i = 1; i < numLayers; i++) { enemy = Enemy.Standard(new Vector2(position.X + i * dX, position.Y - i * dY), enemy.Speed); v.Add(enemy); enemy = Enemy.Standard(new Vector2(position.X - i * dX, v.Last.Y), enemy.Speed); v.Add(enemy); } return v; }
private void Add(Enemy e) { Enemies.Add(e); }
public static Enemy Standard(Vector2 position, Vector2 speed, VectorUpdate positionUpdate) { Enemy e = new Enemy(new Animation(StandardTexture, 1F, true, StandardTexture.Width), position, speed, Destruction, positionUpdate, (sender) => sender.IsAlive ? sender.Speed : Vector2.Zero); return e; }