protected override void Draw(GameTime gameTime) { spriteBatch.Begin(); Rectangle bounds = GraphicsDevice.Viewport.Bounds; Vector2 earthPosition = new Vector2(WIDTH - (0.85f) * earth.Width, HEIGHT - (1.05f) * earth.Height); //Draw background spriteBatch.Draw(stars, bounds, Color.White); spriteBatch.Draw(earth, earthPosition, earth.Bounds, Color.White); //Draw missiles foreach (ProjectileSprite ps in projectiles) { ps.Draw(gameTime, spriteBatch); } //Draw ship if (!lost) { ship.Draw(gameTime, spriteBatch); } foreach (BouncingSprite bs in asteroids) { bs.Draw(gameTime, spriteBatch); } if (lost) { spriteBatch.DrawString(spriteFont, "You Lose", new Vector2(50, 50), FONT_COLOR); } explosionEffect.Draw(spriteBatch); if (DEBUG) { DrawBorder(ship.CollisionRect, 2, Color.Yellow); foreach (BouncingSprite bs in asteroids) { DrawBorder(bs.CollisionRect, 2, Color.Red); } foreach (ProjectileSprite ps in projectiles) { DrawBorder(ps.CollisionRect, 1, Color.Green); } } spriteBatch.End(); base.Draw(gameTime); }
protected override void Draw(GameTime gameTime) { spriteBatch.Begin(); Rectangle bounds = GraphicsDevice.Viewport.Bounds; Vector2 earthPosition = new Vector2(WIDTH - (0.85f) * earth.Width, HEIGHT - (1.05f) * earth.Height); //Draw background spriteBatch.Draw(stars, bounds, Color.White); spriteBatch.Draw(earth, earthPosition, earth.Bounds, Color.White); //Draw missiles, ship, and asteroids foreach (ProjectileSprite ps in projectiles) { ps.Draw(gameTime, spriteBatch); } foreach (BouncingSprite bs in asteroids) { bs.Draw(gameTime, spriteBatch); } if (!lost) { ship.Draw(gameTime, spriteBatch); } //Display a message if the user has won or lost. if (lost) { spriteBatch.DrawString(spriteFont, "You Lose.", new Vector2(50, 50), FONT_COLOR); } if (asteroids.Count == 0) { spriteBatch.DrawString(spriteFont, "You Win!", new Vector2(50, 50), FONT_COLOR); } explosionEffect.Draw(spriteBatch); spriteBatch.End(); base.Draw(gameTime); }