/// <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 gameController = new Controllers.Controller(); contentHolder = new ContentHolder(this.Content); inputHandler = new InputHandler(); gameWorld = new Models.Gameworld(contentHolder, GraphicsDevice.Viewport); //TODO SINGLETON base.Initialize(); }
//************** FUNCTIONS ****************** public Gameworld updateGameWorld(Gameworld gameWorld, GameTime gameTime, InputHandler inputHandler) { getModelFromGameworld(gameWorld); //Change gamestate checkInput(gameTime, inputHandler, gameWorld); gameWorld.setPlayer(playerObject); return(gameWorld); }
public void SetScenario(ScenarioComponent scenario) { if (gameworld != null) { gameworld.UnregisterObserver(this); } context = scenario; if (scenario != null) { gameworld = scenario.GetGameWorld(); if (gameworld != null) { gameworld.RegisterObserver(this); } } }
// Checks input //Gameworld as argument is JUST FOR TESTING-PURPOSES public void checkInput(GameTime gameTime, InputHandler inputHandler, Gameworld gameWorld) { Vector2 tempVector = inputHandler.getMovementInputFromPlayer(); playerObject.update(tempVector); //playerObject.update(inputHandler.getMovementInputFromPlayer()); //Temp input inputHandler.updateInput(); if (inputHandler.KeyDown(Keys.X)) { gameWorld.getCamera().Zoom += (float)0.01; } if (inputHandler.KeyDown(Keys.Z)) { gameWorld.getCamera().Zoom -= (float)0.01; } if (inputHandler.KeyDown(Keys.D)) { playerObject.updatePosition(1, 0); } if (inputHandler.KeyDown(Keys.A)) { playerObject.updatePosition(-1, 0); } if (inputHandler.KeyDown(Keys.S)) { playerObject.updatePosition(0, 1); } if (inputHandler.KeyDown(Keys.W)) { playerObject.updatePosition(0, -1); } }
/// <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) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } // Stores the keyboardstate in a variable KeyboardState keyboard = Keyboard.GetState(); // Exits the game when ESC is pressed if (keyboard.IsKeyDown(Keys.Escape)) { Exit(); } // Sends gamestate to controller and receives updated state. gameWorld = gameController.updateGameWorld(gameWorld, gameTime, inputHandler); // TODO: Add your update logic here base.Update(gameTime); }
public void Visit(Gameworld gameworld) { render(); }
//Copies the entire Gamestate public void getModelFromGameworld(Gameworld gameWorld) { playerObject = gameWorld.getPlayer(); }