private void loadSplashScreen(SplashScreen ss) { Splash = ss; if (ss.Music != null) { MediaPlayer.Play(ss.Music); } else { MediaPlayer.Stop(); } GameState = GameState.Splash; ss.Update(0); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit(); //Debug input #if DEBUG if (Keyboard.GetState().IsKeyDown(Keys.OemTilde)) { GameState = GameState.Splash; SplashType = SplashScreenType.GameOver; loadSplashScreen(new Credits()); } #endif if (Keyboard.GetState().IsKeyDown(Keys.Y) && oldKS.IsKeyUp(Keys.Y)) { //CurrentLevel++; if (CurrentLevel < Levels.Count) { LevelManager.LevelDone = true; } } float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; // Update according to current game state switch (GameState) { case GameState.Initializing: if (!LevelManager.Loading) GameState = GameState.Gameplay; break; case GameState.Splash: if (SplashType == SplashScreenType.GameStart ) { if (Splash.Done && Keyboard.GetState().IsKeyDown(Keys.Enter)) { //the game is starting, load the first cutscene and update to the first line of dialog SplashType = SplashScreenType.Beginning; loadSplashScreen(new Beginning()); } } else if (SplashType == SplashScreenType.GameOver) //Should be Gameover or credits { if (Splash.Done && Keyboard.GetState().IsKeyDown(Keys.Enter)) { //Game over reload first screen. SplashType = SplashScreenType.GameStart; loadSplashScreen(new GameStart()); } } else if (Splash.Done || Keyboard.GetState().IsKeyDown(Keys.S) && oldKS.IsKeyUp(Keys.S)) { //Load next level CurrentLevel = Splash.NextLevel; Reset(); } //Otherwise update. Splash.Update(elapsedTime); break; case GameState.Gameplay: LevelManager.Update(elapsedTime); if (!LevelManager.Ending) { GameObjectManager.Update(elapsedTime); ProcessCollisions(); } if (LevelManager.LevelDone) { switch (CurrentLevel) { case 1: SplashType = SplashScreenType.EndLevelOne; Splash = new EndLevelOne(); break; case 2: SplashType = SplashScreenType.EndLevelTwo; Splash = new EndLevelTwo(); break; case 3: SplashType = SplashScreenType.EndLevelThree; Splash = new EndLevelThree(); break; case 4: SplashType = SplashScreenType.EndLevelFour; Splash = new EndLevelFour(); break; case 5: SplashType = SplashScreenType.EndLevelFive; Splash = new EndLevelFive(); break; case 6: SplashType = SplashScreenType.EndLevelSix; Splash = new EndLevelSix(); break; case 7: SplashType = SplashScreenType.EndLevelSeven; Splash = new EndLevelSix(); break; case 8: SplashType = SplashScreenType.GameOver; Splash = new Credits(); break; } GameState = GameState.Splash; Splash.Update(elapsedTime); } else if (LevelManager.ResetLevel) { //Should be handle by player death method. Reset(); LevelManager.ResetLevel = false; Player.Score = 0; Player.Lives = 5; Player.Health = Player.MaxHealth; Player.Dead = false; } break; case GameState.Scoring: //Not used GuiManager.Update(elapsedTime); if (GuiManager.tallyState == GuiManager.TallyingState.PressSpaceToContinue && Keyboard.GetState().IsKeyDown(Keys.Space)) { GameState = GameState.Splash; Music = Splash.Music; if (Music != null) MediaPlayer.Play(Music); } break; } oldKS = Keyboard.GetState(); base.Update(gameTime); }
public void PlayerDeath() { Splash = new GameOver(); GameState = GameState.Splash; LevelManager.ResetLevel = false; Player.Score = 0; Player.Lives = 5; Player.Health = Player.MaxHealth; Player.Dead = false; }
/// <summary> /// Loads the LevelManager's content and initializes any /// functionality that needs a created graphics device /// </summary> public void LoadContent() { // Create our scroll bounds (the part of the world that is visible) // Note scrollBounds = new Rectangle(0, 0, 384, 360); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(game.GraphicsDevice); // Create a basic effect, used with the spritebatch basicEffect = new BasicEffect(game.GraphicsDevice) { TextureEnabled = true, VertexColorEnabled = true, }; // Create our first splash screen CurrentSplash = new GameStart(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create our viewports gameViewport = GraphicsDevice.Viewport; worldViewport = new Viewport(0, 0, 768, 720); // Twice as wide as 16 tiles guiViewport = new Viewport(768, 0, 512, 720); // Remaining space // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); GameObjectManager = new GameObjectManager(Content); // TODO: use this.Content to load your game content here Player = GameObjectManager.CreatePlayerShip(PlayerShipType.Shrike, new Vector2(300, 300)); LevelManager.LoadContent(); GuiManager.LoadContent(); Splash = new GameStart(); SplashType = SplashScreenType.GameStart; GameState = GameState.Splash; }