/// <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() { spriteBatch = new SpriteBatch(GraphicsDevice); buffer = new InputBuffer(); gameState = new GameState(); gameState.LoadContent(Content); // hack try { input = new WiiController(this, gameState, buffer); } catch (WiimoteLib.WiimoteNotFoundException) { input = new MouseController(this, gameState, buffer); } Services.AddService(typeof(GameState), gameState); menuController = new MenuController(this, gameState, spriteBatch); menuController.Initialize(); levelController = new LevelSelectController(gameState, spriteBatch); levelController.Initialize(); playlevel = new PlayLevel(this, gameState, spriteBatch, buffer); playlevel.Initialize(); worldController = new WorldMapController(this, gameState, spriteBatch, buffer); worldController.Initialize(); gameState.world = worldController; pauseController = new PauseScreenController(this, spriteBatch); pauseController.Initialize(); Components.Add(new GamerServicesComponent(this)); Components.Add(new Components.SaveManager(this)); Components.Add(new BatonView(this, spriteBatch)); base.Initialize(); }
public void Update(Movement m, float score, bool newMovement, GameTime t, PlayLevel level) { if (newMovement) // current movement is over, set state accordingly { //Debug.WriteLine("NEW MOVEMENT!"); // send score back to Movement if (CurrentMovement != null) { if (score < FAIL_THRESHOLD) { CurrentMovement.setState(Movement.States.Fail); } else if (score >= FAIL_THRESHOLD) { CurrentMovement.setState(Movement.States.Succeed); } else // no op { CurrentMovement.setState(Movement.States.None); } } CurrentMovement = m; // update movement } }
/// <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) { input.Update(gameTime); // transitioning to new state if (lastState != gameState.CurrentScreen) { switch (lastState) { case DataTypes.Screens.PlayLevel: if (gameState.CurrentScreen == DataTypes.Screens.Pause) { playlevel.Pause(); } break; case DataTypes.Screens.SelectLevel: if (gameState.CurrentScreen == DataTypes.Screens.PlayLevel) { buffer.Clear(); playlevel = new PlayLevel(this, gameState, spriteBatch, buffer); playlevel.Initialize(); } break; case DataTypes.Screens.WorldMap: if (gameState.CurrentScreen == DataTypes.Screens.PlayLevel) { buffer.Clear(); playlevel = new PlayLevel(this, gameState, spriteBatch, buffer); playlevel.Initialize(); } break; case DataTypes.Screens.Title: if (gameState.CurrentScreen == DataTypes.Screens.WorldMap) { buffer.Clear(); worldController.Update(gameTime, false); } break; } switch (gameState.CurrentScreen) { case DataTypes.Screens.Pause: playlevel.Pause(); break; case DataTypes.Screens.PlayLevel: playlevel.Start(); break; } } lastState = gameState.CurrentScreen; switch (gameState.CurrentScreen) { case DataTypes.Screens.Title: menuController.Update(gameTime); break; case DataTypes.Screens.SelectLevel: levelController.Update(gameTime); break; case DataTypes.Screens.PlayLevel: playlevel.Update(gameTime); break; case DataTypes.Screens.WorldMap: worldController.Update(gameTime, true); break; case DataTypes.Screens.Pause: pauseController.Update(gameTime); break; } base.Update(gameTime); }