public override void Update(GameTime gametime) { if (Mouse.GetState().LeftButton == ButtonState.Pressed && buttonRect.Contains(Mouse.GetState().Position)) { SpaceInvaders.StartGame(); } }
public override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { SpaceInvaders.LoseGame(); } player.Update(gameTime); if (Keyboard.GetState().IsKeyDown(Keys.Space)) { Missile Missile = new Missile(content, true); Missile.position = player.position; missiles.Add(Missile); } foreach (Enemy enemy in enemies) { enemy.Update(gameTime); } foreach (Missile missile in missiles) { missile.Update(gameTime); List <Enemy> deadEnemies = new List <Enemy>(); if (missile.IsPlayerMissile) { foreach (Enemy enemy in enemies) { if (missile.GetBoundingBox().Intersects(enemy.GetBoundingBox())) { deadEnemies.Add(enemy); } } } else { if (missile.GetBoundingBox().Intersects(player.GetBoundingBox())) { SpaceInvaders.LoseGame(); } } foreach (Enemy deadEnemy in deadEnemies) { enemies.Remove(deadEnemy); } } }
static void Main() { using (var game = new SpaceInvaders()) game.Run(); }