/// <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) { //ronnie added for animation //Console.WriteLine("{0} {1} {2} {3}", myGameTime, xFrame,yFrame,animateTimer); if (animate == true) { myGameTime++; sourceRect = new Rectangle(xFrame * spriteWidth, yFrame * spriteHeight, spriteWidth, spriteHeight); if (!((xFrame == 3) && (yFrame == 1))) { animateTimer += myGameTime; if (animateTimer > animateInterval) { xFrame++; if (xFrame > 4 && yFrame == 0) { xFrame = 0; yFrame = 1; } else if (xFrame > 3 && yFrame == 1) { xFrame = 3; yFrame = 1; } // -= (int)walkInterval; myGameTime = 0; animateTimer = 0; } } } // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); bool skipdialog = false; keyState = Keyboard.GetState(); // Allows the game to exit if (keyState.IsKeyDown(Keys.F4)) { ExitGame(); } if (keyState.IsKeyDown(Keys.Enter) && !prevKeyState.IsKeyDown(Keys.Enter)) { skipdialog = true; } switch (progstate) { case ProgramState.Menu: currentMenu.Update(); MenuCommand command = currentMenu.ReturnAndResetCommand(forcedCommand); //lastFloorPlayed = Constants.floors.IndexOf(command); switch (command) { case MenuCommand.LinkToMainMenu: LinkToMain(); currentWorld = null; audioManager.Stop(); break; case MenuCommand.LinkToRooms: LinkToRooms(); currentWorld = null; audioManager.Stop(); break; case MenuCommand.ExitProgram: ExitGame(); break; case MenuCommand.Load: if (LoadWorld()) { countdown = COUNTDOWN; progstate = ProgramState.Playing; } break; case MenuCommand.LoadGenesis: if (LoadRelWorld("introduction1")) { lastFloorPlayed = 0; countdown = COUNTDOWN; forcedCommand = MenuCommand.NONE; progstate = ProgramState.Playing; } break; case MenuCommand.LoadExodus: if (LoadRelWorld("recreation1")) { lastFloorPlayed = 1; countdown = COUNTDOWN; forcedCommand = MenuCommand.NONE; progstate = ProgramState.Playing; } break; case MenuCommand.LoadLeviticus: if (LoadRelWorld("engineering1")) { lastFloorPlayed = 2; countdown = COUNTDOWN; forcedCommand = MenuCommand.NONE; progstate = ProgramState.Playing; } break; case MenuCommand.LoadNumbers: if (LoadRelWorld("core1")) { lastFloorPlayed = 3; countdown = COUNTDOWN; forcedCommand = MenuCommand.NONE; progstate = ProgramState.Playing; } break; case MenuCommand.LoadDeuteronomy: if (LoadRelWorld("credits1")) { lastFloorPlayed = 3; countdown = COUNTDOWN; forcedCommand = MenuCommand.NONE; progstate = ProgramState.Playing; } break; case MenuCommand.LoadIntroduction: if (LoadRelWorld("introduction" + (currentMenu.currentScreen.selected + 1) )) { lastFloorPlayed = 0; countdown = COUNTDOWN; forcedCommand = MenuCommand.NONE; progstate = ProgramState.Playing; } break; case MenuCommand.LoadRecreation: if (LoadRelWorld("recreation" + (currentMenu.currentScreen.selected + 1) )) { lastFloorPlayed = 1; countdown = COUNTDOWN; forcedCommand = MenuCommand.NONE; progstate = ProgramState.Playing; } break; case MenuCommand.LoadEngineering: if (LoadRelWorld("engineering" + (currentMenu.currentScreen.selected + 1) )) { lastFloorPlayed = 2; countdown = COUNTDOWN; forcedCommand = MenuCommand.NONE; progstate = ProgramState.Playing; } break; case MenuCommand.LoadCore: if (LoadRelWorld("core" + (currentMenu.currentScreen.selected + 1) )) { lastFloorPlayed = 3; countdown = COUNTDOWN; forcedCommand = MenuCommand.NONE; progstate = ProgramState.Playing; } break; case MenuCommand.LaunchEditor: { progstate = ProgramState.EditorOpen; editor = new CrisisAtSwissStation.LevelEditor.Editor(); editor.Show(); } break; case MenuCommand.Resume: progstate = ProgramState.Playing; break; case MenuCommand.New: // menuAnimate = true; if (NewWorld()) { countdown = COUNTDOWN; progstate = ProgramState.Playing; } break; case MenuCommand.LoadCompleted: // menuAnimate = true; LoadCompleted(); break; case MenuCommand.Continue: countdown = COUNTDOWN; forcedCommand = Constants.floors[savedgame.GetCurrentFloor(floorsScreen.Options.Count)]; break; } break; case ProgramState.Playing: //menuAnimate = false; //Updates the room. KeyboardState ks = Keyboard.GetState(); if (ks.IsKeyDown(Keys.Escape)) { EnterMenu(); } else if (ks.IsKeyDown(Keys.R)) { LoadWorld(cwname); } else if (ks.IsKeyDown(Keys.N) && ks.IsKeyDown(Keys.U)) { //LoadNextWorld(); currentWorld.Succeeded = true; } else if (ks.IsKeyDown(Keys.RightControl) && ks.IsKeyDown(Keys.P) && ks.IsKeyDown(Keys.O)) { LoadCompleted(); } //world.Update(); currentWorld.Simulate((float)gameTime.ElapsedGameTime.TotalSeconds); //SetDebugInfo("Level = " + world.player.Level); break; case ProgramState.EditorOpen: if (editor.IsDisposed) progstate = ProgramState.Menu; break; } //toggle mute if they press 'm' if (keyState.IsKeyDown(Keys.M) && prevKeyState.IsKeyUp(Keys.M)) audioManager.Mute(); if (currentWorld != null && (currentWorld.Succeeded || currentWorld.Failed)) { countdown--; audioManager.DecreaseMusicVolume(.005f); //if (currentWorld.Failed) //{ // countdown--; //} //Play the level complete SFX if (countdown == 180 && currentWorld.Succeeded) { audioManager.Stop(); audioManager.Play(CrisisAtSwissStation.AudioManager.SFXSelection.LevelComplete); } if (countdown <= 0 && currentWorld.Succeeded && !currentWorld.Failed) { //reset = currentWorld.Failed; if (!audioManager.isMuted()) { audioManager.IncreaseMusicVolume(0.5f); } LoadNextWorld(); } else if (countdown <= 0) // failed { LoadWorld(cwname); progstate = ProgramState.Playing; countdown = COUNTDOWN; if (!audioManager.isMuted()) { audioManager.IncreaseMusicVolume(0.5f); } } } // Just won or lost - initiate countdown if (currentWorld!=null && (currentWorld.Failed || currentWorld.Succeeded) && countdown <= 0) countdown = COUNTDOWN; base.Update(gameTime); prevKeyState = keyState; }