private void DrawGameOverText(SpriteBatch spriteBatch, SpriteFont font) { if (this.lose >= 0) { if (this.lose < 180) { //present game over text String s1 = "You lost the game"; float length1 = font.MeasureString(s1).X; (this.Game as Game1).SpriteBatch.DrawString(font, s1, new Vector2((Game1.SCREEN_WIDTH - length1 * 2) / 2, (Game1.SCREEN_HEIGHT / 2) - 100), Color.Yellow, 0f, new Vector2(0, 0), 2f, SpriteEffects.None, 0f); } if (player.Score > LeaderboardScreen.LowestScore() && this.lose < 100) { DrawHighScoreGet(spriteBatch, font); } else { if (this.lose < 90) { String s1 = "Try again next time."; float length1 = font.MeasureString(s1).X; (this.Game as Game1).SpriteBatch.DrawString(font, s1, new Vector2((Game1.SCREEN_WIDTH - length1) / 2, (Game1.SCREEN_HEIGHT / 2) - 25), Color.White); } if (this.lose == 0) { String s1 = "See you!"; float length1 = font.MeasureString(s1).X; (this.Game as Game1).SpriteBatch.DrawString(font, s1, new Vector2((Game1.SCREEN_WIDTH - length1) / 2, (Game1.SCREEN_HEIGHT / 2) + 10), Color.White); } } } }
public override void Initialize() { base.Initialize(); MenuScreen = new MenuScreen(Game); SplashScreen = new SplashScreen(Game); GameScreen = new GameScreen(Game); CreditsScreen = new CreditsScreen(Game); StoryScreen = new StoryScreen(Game); LeaderboardScreen = new LeaderboardScreen(Game); ParallaxBackground = new ParallaxBackground(Game); MenuScreen.Initialize(); CreditsScreen.Initialize(); SplashScreen.Initialize(); StoryScreen.Initialize(); LeaderboardScreen.Initialize(); ParallaxBackground.Initialize(); Screens = new List <Screen>(); Screens.Add(ParallaxBackground); Screens.Add(MenuScreen); Screens.Add(LeaderboardScreen); Screens.Add(CreditsScreen); Screens.Add(StoryScreen); Screens.Add(GameScreen); Screens.Add(SplashScreen); MenuScreen.Show(false); GameScreen.Show(false); CreditsScreen.Show(false); StoryScreen.Show(false); LeaderboardScreen.Show(false); }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { this.Initialize(); //TODO change this to option menu? if ((this.Game as Game1).Keyboard.Back.IsPressed() && this.Alive) { AudioManager.stopMusic(); AudioManager.playMusic(menuSong); Show(false); Game.ScreenManager.ParallaxBackground.gameSpeed = 10; Game.ScreenManager.MenuScreen.Show(true); this.initialized = false; } if (this.intro > 0) { this.intro--; this.arsenal.Velocity = new Vector2(-MathHelper.Clamp(40 - (intro / 5f), 0, 10), 0); } if (speedDisplayGrow > 0) { speedDisplayGrow--; } if (timeout > 0) { timeout--; if (timeout == 105) { foreach (GameComponent component in this.Components) { if (component is ZombieShip || component is Bullet || component is Asteroid || component is Explosion) { this.RemoveComponent(component); } } } } if (this.lose > 0) { this.lose--; } else if (this.lose < 0) { this.speedUpTimer--; if (speedUpTimer == 30) { this.speedDisplayGrow = 60; } if (speedUpTimer < 0) { this.gameSpeed++; this.ResetSpeedTimer(); } if (this.bossCountdown > 0) { this.bossCountdown--; } else if (this.NoZombies()) { this.SpawnBoss(); } } Game.ScreenManager.ParallaxBackground.gameSpeed = gameSpeed; if (timeout <= 0 && this.intro <= 0) { if (this.random.NextDouble() < (0.001 * this.GameSpeed) && this.lose < 0) { int halfScreenWidth = Game1.SCREEN_WIDTH / 2; int type = this.random.Next(10); if (type < 2) { float sign = (0.12f * this.random.Next(2)) - 0.06f; Vector2 position = new Vector2(halfScreenWidth + this.random.Next(halfScreenWidth), sign > 0 ? -50 : Game1.SCREEN_HEIGHT + 50); Vector2 velocity = new Vector2(-0.06f * this.GameSpeed * (this.NextFloat() + 0.5f), sign * this.GameSpeed * (this.NextFloat() + 0.5f)); this.AddComponent(new Asteroid(this.Game, this, position, velocity)); } else if (this.bossCountdown > 0) { if (type < 6) { this.AddComponent(new ZombieShip(this.Game, this, new Vector2(halfScreenWidth + this.random.Next(halfScreenWidth), -60), ZombieType.FLOATER)); } else if (type < 9) { this.AddComponent(new ZombieShip(this.Game, this, new Vector2(Game1.SCREEN_WIDTH + 10, this.random.Next(Game1.SCREEN_HEIGHT)), ZombieType.SHOOTER)); } else { this.AddComponent(new ZombieShip(this.Game, this, new Vector2(halfScreenWidth + this.random.Next(halfScreenWidth), Game1.SCREEN_HEIGHT + 10), ZombieType.SLAMMER)); } } } } foreach (GameComponent component in this.components) { component.Update(gameTime); } this.components.AddRange(this.newComponents); this.newComponents = new List <GameComponent>(); foreach (GameComponent oldComponent in this.oldComponents) { this.components.Remove(oldComponent); } this.oldComponents = new List <GameComponent>(); if (!this.Alive && player.Score > LeaderboardScreen.LowestScore() && this.lose < 100) { UpdateNameInput(); } }