/// <summary> /// Controls updating of the game based on the current screen state and mouse/keyboard input /// </summary> /// <param name="time">The GameTime to update with respect to</param> public void update(GameTime time) { lastKeyState = currentKeyState; currentKeyState = Keyboard.GetState(); collisionManager.updatePressButtons(player); /*if (currentKeyState.IsKeyDown(Keys.Escape)) { * game.Exit(); * }*/ if (playerManager.getHealth() <= 0) { deaths++; player.playEffect(); if (deaths == 3) { resetGame(false); } else { deathManager.resetGame(deaths); dropText = deaths == 1 ? "2 lives remaining" : "1 life remaining"; } } if (!finished && (MediaPlayer.State != MediaState.Playing || deaths == 3)) { Song song; if (level.getSong() == prevLevel.getSong()) { if (prevLevel.shouldLoop() || level.shouldLoop()) { prevLevel.setLooped(true); level.setLooped(true); song = level.getSong2(); } else { song = level.getSong(); } } else { song = level.shouldLoop() ? level.getSong2() : level.getSong(); } if (deaths == 3) { deaths = 0; } MediaPlayer.Stop(); MediaPlayer.Play(song); level.setLooped(true); } /*if (lastKeyState.IsKeyDown(Keys.F1) && currentKeyState.IsKeyUp(Keys.F1)) { * foreach (Level l in game.getLevels()) { * l.toggleDebug(); * } * }*/ foreach (PressButton pb in level.getPressButtons()) { pb.update(); } foreach (Pit p in level.getPits()) { if (p is LavaPit) { LavaPit lava = (LavaPit)p; lava.updateFrame(); } else if (p is PlayerLimitationField) { PlayerLimitationField lim = (PlayerLimitationField)p; lim.updateFrame(); } } if (stagnant) { if (ticks >= WAIT) { player.updateStill(); ticks = 0; stagnant = false; } else { ticks++; } } if (gameState == GameState.Normal) { updateNormal(time); } else if (gameState == GameState.TelekinesisSelect) { updateSelect(time); } else if (gameState == GameState.TelekinesisMovement) { updateTelekinesisMove(time); } else if (gameState == GameState.PauseMenu) { if (menuShown) { gameState = GameState.Normal; menuShown = false; } else { menuShown = true; PauseMenu pause = (PauseMenu)level.getScreen("Pause"); pause.setActive(true); } } else if (gameState == GameState.Puzzle) { if (puzzleShown) { puzzleShown = false; showPuzzle = false; gameState = GameState.Normal; level.setActive(true); } else { puzzleShown = true; Numberpad num = (Numberpad)level.getScreen("Numberpad"); num.setActive(true); } } else if (gameState == GameState.Outro) { if (game.getLastScreen() == "Outro video") { resetGame(true); finished = false; gameState = GameState.Normal; } else { level.setActive(false); MediaPlayer.Stop(); ManualVideo outro = (ManualVideo)level.getScreen("Outro video"); outro.reset(); outro.setActive(true); } } }