// Draw is fired with each paint event of the main form public void Draw(Graphics graphics, int frame, bool gameOver) { graphics.FillRectangle(Brushes.Black, formArea); stars.Draw(graphics); foreach (Invader invader in invaders) { invader.Draw(graphics, frame); } playerShip.Draw(graphics); foreach (Shot shot in playerShots) { shot.Draw(graphics); } foreach (Shot shot in invaderShots) { shot.Draw(graphics); } graphics.DrawString(("Score: " + score.ToString()), statsFont, Brushes.Yellow, scoreLocation); graphics.DrawString(("Lives: " + livesLeft.ToString()), statsFont, Brushes.Yellow, livesLocation); graphics.DrawString(("Wave: " + wave.ToString()), statsFont, Brushes.Yellow, waveLocation); if (gameOver) { graphics.DrawString("GAME OVER", messageFont, Brushes.Red, (formArea.Width / 4), formArea.Height / 3); } }
/// <summary> /// Draw is fired with each paint event of the main form /// </summary> /// <param name="graphics"></param> /// <param name="frame"></param> /// <param name="gameOver"></param> public void Draw(Graphics graphics, int frame, bool gameOver) { graphics.FillRectangle(Brushes.Black, formArea); stars.Draw(graphics); //TODO: Remove this section after reading /* * Only draw the boss when reach the bossWa */ // Only draw the small invaders when it is not bossWave if (wave != bossWave) { foreach (Invader invader in invaders) { invader.Draw(graphics, frame); } } else { boss.Draw(graphics, frame); } playerShip.Draw(graphics); foreach (Shot shot in playerShots) { shot.Draw(graphics, "player"); } foreach (Shot shot in invaderShots) { shot.Draw(graphics, "invader"); } foreach (Shot shot in bossShots) { shot.Draw(graphics, "invader"); } // UI drawing code graphics.DrawImage(ui, uiRect); Bitmap ship = Properties.Resources.player; for (int l = livesLeft; l <= livesLeft && l >= 1; l--) { graphics.DrawImage(ship, formArea.Right - 330.0F + (30.0F * l), formArea.Top + 15.0F, ship.Width * 0.5F, ship.Height * 0.5F); } if (wave == bossWave) { graphics.DrawString(("HP: " + bossLives.ToString()), statsFont, Brushes.Yellow, boss.Location.X + 120, boss.Location.Y - 8); } //instructions graphics.DrawString("Press Esc to" + '\n' + "pause game.", statsFont, Brushes.White, 3, 20); graphics.DrawString(("Score: " + score.ToString()), statsFont, Brushes.Yellow, scoreLocation); graphics.DrawString(("Lives: " + livesLeft.ToString()), statsFont, Brushes.Yellow, livesLocation); graphics.DrawString(("Wave: " + wave.ToString()), statsFont, Brushes.Yellow, waveLocation); }