Example #1
0
 /// <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();
 }
Example #2
0
        // 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);

            }
        }
Example #3
0
        // Checks input during gameplay
        //Gameworld as argument is JUST FOR TESTING-PURPOSES
        public void checkInput(GameTime gameTime, InputHandler inputHandler, Gameworld gameWorld)
        {
            // Controller input
            Vector2 movementVector = inputHandler.getLeftStickMovement();
            Vector2 rightStick = inputHandler.getRightStickMovement();
            //playerObject.update(movementVector, rightStick, gameTime);

            if (inputHandler.ButtonDown(Buttons.RightTrigger) || inputHandler.KeyDown(Keys.LeftShift))
            {
                updateGravityWell(gameWorld, inputHandler.getRightTrigger());
            }
            else
            {
                gameWorld.setDrawGravityWell(false, 0);
            }

            if (inputHandler.ButtonDown(Buttons.LeftTrigger) || inputHandler.KeyDown(Keys.Space))
            {
                gameWorld.getPlayer().ShootingRockets = true;
            }
            if (inputHandler.ButtonReleased(Buttons.LeftTrigger) || inputHandler.KeyReleased(Keys.Space))
            {
                gameWorld.getPlayer().ShootingRockets = false;
            }

            #if DEBUG
            if (inputHandler.ButtonPressed(Buttons.LeftShoulder) && inputHandler.ButtonPressed(Buttons.RightShoulder))
                gameWorld.setDebug();
            #endif

            // Temp Keyboardinput
            /////////////////////////////////////////////////////////////////////////////////////////////////////////
            // !USING A KEYBOARD WILL BREAK THE SPEED OF THE PLAYER. THIS IS NOT TO BE INCLUDED IN THE FINAL GAME! //
            // !IT ALSO SCREWS WITH PROJECTILE VELOCITY/DIRECTION!                                                 //
            /////////////////////////////////////////////////////////////////////////////////////////////////////////
            inputHandler.updateInput();

            // Zooming
            if (inputHandler.KeyDown(Keys.X))
            {
                gameWorld.getCamera().Zoom += 0.01f;
            }
            if (inputHandler.KeyDown(Keys.Z))
            {
                gameWorld.getCamera().Zoom -= 0.01f;
            }
            if (inputHandler.KeyDown(Keys.C))
            {
                gameWorld.getCamera().Zoom = 1.0f;
            }

            // Movement
            if (inputHandler.KeyDown(Keys.D))
                movementVector.X = 1;

            if (inputHandler.KeyDown(Keys.A))
                movementVector.X = -1;

            if (inputHandler.KeyDown(Keys.S))
                movementVector.Y = -1;

            if (inputHandler.KeyDown(Keys.W))
                movementVector.Y = 1;

            // Shooting
            if (inputHandler.KeyDown(Keys.Right))
                rightStick.X = 1;

            if (inputHandler.KeyDown(Keys.Left))
                rightStick.X = -1;

            if (inputHandler.KeyDown(Keys.Down))
                rightStick.Y = -1;

            if (inputHandler.KeyDown(Keys.Up))
                rightStick.Y = 1;
            // Other keys
            #if DEBUG
            if (inputHandler.KeyReleased(Keys.F1))
                gameWorld.setDebug();
            #endif

            physicsEngine.collisionDetection(ref gameWorld, movementVector, rightStick, gameTime);
        }
Example #4
0
        public void updateMenu(Gameworld gameWorld, InputHandler inputHandler, GameTime gameTime, Highscores highscores)
        {
            inputHandler.updateInput();

            Vector2 movementVector = inputHandler.getLeftStickMovement();

            bool aButton = false;                       // flagged if A button, or Enter, is pressed
            bool bButton = false;                       // flagged if B button, or backspace, is pressed

            int movementY = 0;                           // Tells the menu where to move next (-1 is up, 1 is down)
            int movementX = 0;

            if (inputHandler.ButtonPressed(Buttons.DPadDown) || movementVector.Y < 0 || inputHandler.KeyReleased(Keys.Down))
                movementY = 1;
            if (inputHandler.ButtonPressed(Buttons.DPadUp) || movementVector.Y > 0 || inputHandler.KeyReleased(Keys.Up))
                movementY = -1;

            if (inputHandler.ButtonPressed(Buttons.DPadLeft) || movementVector.X < 0 || inputHandler.KeyReleased(Keys.Left))
                movementX = -1;
            if (inputHandler.ButtonPressed(Buttons.DPadRight) || movementVector.X > 0 || inputHandler.KeyReleased(Keys.Right))
                movementX = 1;

            if (inputHandler.ButtonPressed(Buttons.A) || inputHandler.KeyDown(Keys.Enter))
                aButton = true;
            if (inputHandler.ButtonPressed(Buttons.B) || inputHandler.KeyDown(Keys.Back))
                bButton = true;

            if (menuHandler.ElapsedSinceLastInput > menuHandler.AllowedTimeBetweenInputs)
            {
                if (movementY != 0 || movementX != 0 || aButton || bButton)
                {
                    menuHandler.update(movementY, movementX, aButton, bButton);
                    menuHandler.ElapsedSinceLastInput = 0;
                }
            }

            menuHandler.ElapsedSinceLastInput += gameTime.ElapsedGameTime.Milliseconds;

            if (menuHandler.sendScore)
            {
                sendScore(gameWorld);

                menuHandler.ExitGame = true;
            }
        }
Example #5
0
        public void updateGravityWell(Gameworld gameWorld, float rightTrigger)
        {
            gameWorld.GravityWell.Position = gameWorld.PlayerObject.Position;
            gameWorld.setDrawGravityWell(true, rightTrigger);

            physicsEngine.checkGravityWellCollision(gameWorld.GravityWell, gameWorld.getRock());
        }
Example #6
0
        //************** FUNCTIONS ******************
        public void updateGameWorld(ref Gameworld gameWorld, GameTime gameTime, InputHandler inputHandler)
        {
            getModelFromGameworld(gameWorld);

            //Change gamestate

            if (!(MediaPlayer.State == MediaState.Playing))
            {
                MediaPlayer.Play(content.soundtrack);
            }

            elapsed = elapsed + gameTime.ElapsedGameTime.Milliseconds;

            Console.Out.WriteLine(gameTime.ElapsedGameTime.Milliseconds);

            if (elapsed > randomTimeBetweenSpawns)
            {
                randomTimeBetweenSpawns = randGen.Next(1, 3) * 1000;
                elapsed = 0;

                gameWorld.spawnEnemiesAtRandom(content);

                //Console.Out.WriteLine("RAAAAp");
            }

            checkInput(gameTime, inputHandler, gameWorld);
            //gameWorld.updateEnemies(gameTime);
            handleProjectileCollisions(gameWorld);
            //updateGravityWell(gameWorld);

            //physicsEngine.collisionDetection(gameWorld);

            gameWorld.setPlayer(playerObject);

            gameWorld.update(gameTime, content);
            playSounds();

            //return gameWorld;
        }
Example #7
0
 public void sendScore(Gameworld gameWorld)
 {
     thread = new Thread(() => hs.sendScore("1", menuHandler.endMenu.name, "null", gameWorld.Score));
     thread.Start();
 }
Example #8
0
 //Copies the entire Gamestate
 public void getModelFromGameworld(Gameworld gameWorld)
 {
     playerObject = gameWorld.getPlayer();
 }
Example #9
0
        /// <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
            gamestate = GameStates.Menu;
            highScores = new Highscores();
            contentHolder = new ContentHolder(this.Content);
            soundManager = new SoundManager(contentHolder);
            gameController = new Controllers.Controller(contentHolder, soundManager, highScores, gameName, width, height);
            inputHandler = new InputHandler();
            gameWorld = new Models.Gameworld(contentHolder, GraphicsDevice.Viewport, 4096);    //TODO SINGLETON

            base.Initialize();
        }
Example #10
0
        /// <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);
        }
Example #11
0
        //************** FUNCTIONS ******************
        public Gameworld updateGameWorld(Gameworld gameWorld, GameTime gameTime, InputHandler inputHandler)
        {
            getModelFromGameworld(gameWorld);

            //Change gamestate

            checkInput(gameTime, inputHandler, gameWorld);

            gameWorld.setPlayer(playerObject);

            return gameWorld;
        }