public void NewGame() { // do all your game init stuffs here (like making new player or tilemaps) gameState = new GameState(this); logState = new LogState(this); Entities.instance().clearList(); currentState = gameState; MediaPlayer.Play(music); MediaPlayer.Volume = 0.5f; KeyHandler.Update(); ; }
/// <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) { KeyHandler.Update(); // Allows the game to exit if ((Input.BACK(1) || Input.BACK(2) || Input.BACK(3) || Input.BACK(4))) this.Exit(); if (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit(); // TODO: Add your update logic here if (menus.menusBusy) { menus.Update(gameTime.ElapsedGameTime.Milliseconds); } else { if ((Input.START(1) || Input.START(2) || Input.START(3) || Input.START(4)) || Keyboard.GetState().IsKeyDown(Keys.Tab)) menus.turnOn(MenuSystem.PAUSE); // all the rest... if (currentState == gameState && Keyboard.GetState().IsKeyDown(Keys.Space)) { currentState = logState; } if (currentState == logState && Keyboard.GetState().IsKeyDown(Keys.Enter)) { currentState = gameState; logState.parseInput(); logState.clearInput(); } currentState.Update(gameTime); if (GameState.player.isDead()) { menus.turnOn(MenuSystem.GAMEOVER); } } base.Update(gameTime); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here menus = new MenuSystem(this); menus.turnOn(MenuSystem.MAIN); gameState = new GameState(this); logState = new LogState(this); currentState = gameState; KeyHandler.Update(); base.Initialize(); }