protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); //Menu Draw switch (CurrentGameState) { case GameState.MainMenu: buttonplay.Draw(spriteBatch); // När screen är i MainMenu så ritas button upp. break; case GameState.Playing: break; } if (pause == false) // Om spelet inte är i pause. { hero.Draw(spriteBatch); foreach (Enemy enemies in enemy) // Ritar ut spriten för varje enemy som skapas. { enemies.Draw(spriteBatch); } foreach (Bullet bullets in bullet) // Riar ut spriten för varje bullet som skapas. { bullets.Draw(spriteBatch); } score.Draw(spriteBatch); } spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); var viewMatrix = camera.GetViewMatrix(); camera.Position = camPos; camera.Rotation = rotation; camera.Zoom = zoom; if (CurrentGameState == GameState.MainMenu) { spriteBatch.Begin(); spriteBatch.Draw(background, mainframe, Color.White); //spriteBatch.DrawString(font, "press enter to start ", new Vector2(0, 0), Color.Black, 0, new Vector2(0, 0),2 , 0, 0); spriteBatch.DrawString(font, "press enter to start", new Vector2((GraphicsDevice.Viewport.Width / 2) - 150, 375), Color.Black); spriteBatch.End(); } else if (CurrentGameState == GameState.PlayingLvl1) { #region GameLvl1; spriteBatch.Begin(); spriteBatch.Draw(background, mainframe, Color.White); spriteBatch.DrawString(font, "Score: " + _hero.Score, new Vector2(750, 0), Color.Black); spriteBatch.DrawString(font, "Hero Life: x" + _hero.HeroLife, new Vector2(0, 0), Color.Black); spriteBatch.End(); spriteBatch.Begin(transformMatrix: viewMatrix); exit_Lvl1.Draw(spriteBatch); _hero.Draw(spriteBatch); fire.Draw(spriteBatch); foreach (coin coin in coins) { coin.Draw(spriteBatch); } foreach (Enemy enemy in _Enemys) { if (enemy.isAlive) { enemy.Draw(spriteBatch); } } foreach (BulletRight Bullet in bulletsright) { Bullet.Draw(spriteBatch); } foreach (BulletLeft Bullet in bulletsleft) { Bullet.Draw(spriteBatch); } map.Draw(spriteBatch); foreach (MovingTiles tile in movingTiles) { tile.Draw(spriteBatch); } spriteBatch.End(); #endregion } else if (CurrentGameState == GameState.PlayingSecretLvl) { spriteBatch.Begin(); spriteBatch.Draw(background, mainframe, Color.White); spriteBatch.DrawString(font, "Score: " + _hero.Score, new Vector2(750, 0), Color.Black); spriteBatch.DrawString(font, "Hero Life: x" + _hero.HeroLife, new Vector2(0, 0), Color.Black); spriteBatch.End(); spriteBatch.Begin(); exit_SecretLvl.Draw(spriteBatch); _hero.Draw(spriteBatch); SecretLvl.Draw(spriteBatch); foreach (coin coin in coins_SecretLvl) { coin.Draw(spriteBatch); } spriteBatch.End(); } else if (CurrentGameState == GameState.PlayingLvl2) { spriteBatch.Begin(); spriteBatch.Draw(background, mainframe, Color.White); spriteBatch.DrawString(font, "Score: " + _hero.Score, new Vector2(750, 0), Color.Black); spriteBatch.DrawString(font, "Hero Life: x" + _hero.HeroLife, new Vector2(0, 0), Color.Black); spriteBatch.End(); spriteBatch.Begin(transformMatrix: viewMatrix); _hero.Draw(spriteBatch); foreach (MovingTiles tile in movingTiles_Lvl2) { tile.Draw(spriteBatch); } foreach (Enemy enemy in _EnemysLvl2) { if (enemy.isAlive) { enemy.Draw(spriteBatch); } } foreach (BulletRight Bullet in bulletsright) { Bullet.Draw(spriteBatch); } foreach (BulletLeft Bullet in bulletsleft) { Bullet.Draw(spriteBatch); } foreach (BulletEnemy Bullet in bulletEnemy) { Bullet.Draw(spriteBatch); } foreach (coin coin in coins_Lvl2) { coin.Draw(spriteBatch); } if (damageEndBoss < 20) { endBoss.Draw(spriteBatch); } else { exit_Lvl2.Draw(spriteBatch); } foreach (Kanon kanon in Kannonen) { kanon.Draw(spriteBatch); } map_Lvl2.Draw(spriteBatch); spriteBatch.End(); } else if (CurrentGameState == GameState.Dead) { spriteBatch.Begin(); spriteBatch.Draw(background, mainframe, Color.White); spriteBatch.DrawString(font, "Game Over!", new Vector2(650, 200), Color.Black); spriteBatch.DrawString(font, "Your score: " + _hero.Score, new Vector2(650, 400), Color.Black); spriteBatch.End(); } else if (CurrentGameState == GameState.End) { spriteBatch.Begin(); spriteBatch.Draw(background, mainframe, Color.White); spriteBatch.DrawString(font, "Yes! You did it!", new Vector2(650, 200), Color.Black); spriteBatch.DrawString(font, "Your score: " + _hero.Score, new Vector2(650, 400), Color.Black); spriteBatch.End(); } base.Draw(gameTime); }