public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; /// This is ours /// //Change Window Title Window.Title = "Cemetery Escape"; //Resolution Setting graphics.PreferredBackBufferWidth = 1000; graphics.PreferredBackBufferHeight = 650; graphics.ApplyChanges(); this.IsMouseVisible = true; startScreen = new StartMenuScreen(); //declaration pauseScreen = new PauseScreen(); storyScreen = new SplashScreen(); helpScreen = new HelpScreen(); Global.highscore = new HighScore(); }
/// <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) { if (this.IsActive) { // TODO: Add your update logic here playerRootedInterval += (float)gameTime.ElapsedGameTime.TotalSeconds; fogTime += (float)gameTime.ElapsedGameTime.TotalSeconds; interval += (float)gameTime.ElapsedGameTime.TotalSeconds; fogOfWarPowerUpDuration += (float)gameTime.ElapsedGameTime.TotalSeconds; //update keystates oldkeys = keystate; keystate = Keyboard.GetState(); //save the hassle, just exit once this is detected if (startScreen.Exit.clicked || pauseScreen.quitGame.clicked) { this.Exit(); } #region play background music forever playSounds(); //zombie sound if (zombieSoundInstance.State != SoundState.Playing) { zombieSoundInstance.Volume = 0f; } #endregion #region On screen text for debuggin. activate this by pressing ctrl-X if (interval > 2f) { onScreenText = ""; } if ((keystate.IsKeyDown(Keys.LeftControl) && keystate.IsKeyDown(Keys.X)) && !(oldkeys.IsKeyDown(Keys.LeftControl) && oldkeys.IsKeyDown(Keys.X))) { if (enableXYPosition) { enableXYPosition = false; } else { enableXYPosition = true; } } #endregion // check if the player is at the last map. if (currentMap == numberOfMaps) { lastMap = true; } #region switchcase switch (CurrentState) { #region GameState.StartingSplashScreen -> Starting SplashScreen case GameState.StartingSplashScreen: if (storyScreen.Update(gameTime)) { CurrentState = GameState.StartMenu; } interval = 0f; break; #endregion #region GameState.StartMenu -> Start Menu Updates case GameState.StartMenu: startScreen.Update(); //if control button is click if (startScreen.Controls.clicked) { startScreen.Controls.clicked = false; CurrentState = GameState.ControlsScreen; } //if play button is clicked or spacebar button if (((startScreen.Play.clicked) || (keystate.IsKeyDown(Keys.Space) && interval > 0.4f))) { startScreen.Play.clicked = true; this.IsMouseVisible = false; LoadLevel(); interval = 0f; CurrentState = GameState.Playing; } //credit screen if (startScreen.Credits.clicked) { startScreen.Credits.clicked = false; this.IsMouseVisible = false; interval = 0f; loadCreditScreen(); currentMap = 999; CurrentState = GameState.CreditScreen; } break; #endregion #region GameState.ControlsScreen -> Control Screen Methods case GameState.ControlsScreen: //check if user exit controls screen if (helpScreen.buto) { helpScreen = new HelpScreen(); helpScreen.LoadContent(Content); CurrentState = GameState.StartMenu; } else { helpScreen.Update(); } break; #endregion #region GameState.CreditScreen -> run the credit screen case GameState.CreditScreen: //same as playing #endregion #region GameState.Playing -> This contain all the updates once it starts playing case GameState.Playing: //if game has started, press esc to pause if (keystate.IsKeyDown(Keys.Escape) && !(oldkeys.IsKeyDown(Keys.Escape))) { CurrentState = GameState.Pause; } //check for player health reaches zero, he die if (Global.player.isHeDead() && CurrentState != GameState.CreditScreen) { interval = 0; CurrentState = GameState.PlayerDied; } /// if score reaches 0 if (Global.highscore.getCurrentScore() < 0 && CurrentState != GameState.CreditScreen) { CurrentState = GameState.OutOfTime; } if (Global.player.rooted = true && playerRootedInterval > 3f) { Global.player.rooted = false; } this.IsMouseVisible = false; map.Update(gameTime, Content); Camera(gameTime); Collision(); Global.player.Update(gameTime); ZombieCollision(); PlayerCollisionWithZombie(); chaserCollidePlayer(); #region Power Ups if (fogOfWarPowerUpDuration > 5f && !fog_cheat) { fogOn = true; } #endregion #region GodMode, FogOfWar and SkipLevel Cheats //turn off Fog Of war if ((keystate.IsKeyDown(Keys.F) && keystate.IsKeyDown(Keys.LeftControl)) && !(oldkeys.IsKeyDown(Keys.F) && oldkeys.IsKeyDown(Keys.LeftControl))) { if (fogOn) { fogOn = false; fog_cheat = true; } else { fogOn = true; fog_cheat = false; } } //godmode, unlimited health if ((keystate.IsKeyDown(Keys.G) && keystate.IsKeyDown(Keys.LeftControl)) && !(oldkeys.IsKeyDown(Keys.G) && oldkeys.IsKeyDown(Keys.LeftControl))) { if (godMode) { godMode = false; } else { godMode = true; } } //if godMode, player health will never move if (godMode) { Global.player.playerHealth = 0; } //bypass the current level by pressing ctrl-C if ((keystate.IsKeyDown(Keys.LeftControl) && keystate.IsKeyDown(Keys.C)) && !(oldkeys.IsKeyDown(Keys.LeftControl) && oldkeys.IsKeyDown(Keys.C))) { if (currentMap < numberOfMaps) { ++currentMap; enableXYPosition = false; LoadLevel(); } else { //onScreenText = "NO MORE MAPS TO LOAD!"; interval = 0; } } //fog update scale if (fogTime > fogInterval) { if (fogIncreaseSize) { if (fogScale > 3.5f) { fogIncreaseSize = false; } fogScale += 0.01f; } if (!fogIncreaseSize) { if (fogScale < 1.5f) { fogIncreaseSize = true; } fogScale -= 0.01f; } fogTime = 0f; } #endregion break; #endregion #region GameState.Pause -> pause update case GameState.Pause: this.IsMouseVisible = true; pauseScreen.Update(); //resume validation if (pauseScreen.resume.clicked || (((keystate.IsKeyDown(Keys.Escape) || keystate.IsKeyDown(Keys.Enter)) && interval > 0.3f) && (!(oldkeys.IsKeyDown(Keys.Escape) || oldkeys.IsKeyDown(Keys.Enter))))) { pauseScreen = new PauseScreen(); pauseScreen.LoadContent(Content); CurrentState = GameState.Playing; } //exit level if (pauseScreen.exitLevel.clicked) { pauseScreen = new PauseScreen(); pauseScreen.LoadContent(Content); storyScreen.buto = false; if (currentMap == 999) { map.player.Stop(); } this.LoadContent(); } break; #endregion #region GameState.PlayerWin -> Player win, reach the goal case GameState.PlayerWin: //this will add up the totalcurrentscore to show on the screen when finish if (runOnce) { Global.highscore.CalculateScore(); currentTotalScore += Global.highscore.currentScore; runOnce = false; } // press escape, enter, space to exit screen if (((keystate.IsKeyDown(Keys.Escape) || keystate.IsKeyDown(Keys.Space) || keystate.IsKeyDown(Keys.Enter)) && interval > 0.3f) && (!(oldkeys.IsKeyDown(Keys.Escape) || oldkeys.IsKeyDown(Keys.Space) || oldkeys.IsKeyDown(Keys.Enter)))) { if (lastMap) { currentMap = 999; loadCreditScreen(); CurrentState = GameState.CreditScreen; } else { CurrentState = GameState.LevelSplashScreen; } } break; #endregion #region GameState.LevelSplashScreen -> show story screen case GameState.LevelSplashScreen: // press escape, enter, space to exit screen if ((((keystate.IsKeyDown(Keys.Escape) || keystate.IsKeyDown(Keys.Space) || keystate.IsKeyDown(Keys.Enter)) && interval > 0.3f) && (!(oldkeys.IsKeyDown(Keys.Escape) || oldkeys.IsKeyDown(Keys.Space) || oldkeys.IsKeyDown(Keys.Enter)))) || !splashScreenForLevelExist) { runOnce = true; interval = 0f; if (!lastMap) //if not lastmap { ++currentMap; enableXYPosition = false; LoadLevel(); CurrentState = GameState.Playing; } else { //comparing old totalScore to current regradless of level if (currentTotalScore > oldTotalScore) { Global.highscore.addTotalScore(currentTotalScore); } currentMap = 1; pauseScreen = new PauseScreen(); pauseScreen.LoadContent(Content); storyScreen.buto = false; lastMap = false; this.LoadLevel(); } } break; #endregion #region GameState.PlayerDied -> player Died from zombie, chaser or falling into blackhole case GameState.PlayerDied: ///Combined with OutOfTime case #endregion #region GameState.OutOfTime -> out of time!! case GameState.OutOfTime: //Zombie eat you, you die! //Exit to main menu // press escape, enter, space to exit screen if (((keystate.IsKeyDown(Keys.Escape) || keystate.IsKeyDown(Keys.Enter)) && interval > 0.3f) && (!(oldkeys.IsKeyDown(Keys.Escape) || oldkeys.IsKeyDown(Keys.Enter)))) { pauseScreen = new PauseScreen(); pauseScreen.LoadContent(Content); storyScreen.buto = false; this.LoadContent(); } //restart level, press R if (keystate.IsKeyDown(Keys.R) && !oldkeys.IsKeyDown(Keys.R)) { startScreen.Play.clicked = true; this.IsMouseVisible = false; LoadLevel(); interval = 0f; CurrentState = GameState.Playing; } break; #endregion } #endregion } base.Update(gameTime); }