Beispiel #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();
 }
Beispiel #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);

            }
        }
Beispiel #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);
        }
Beispiel #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;
            }
        }
Beispiel #5
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;
        }
Beispiel #6
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();
        }
Beispiel #7
0
        //************** FUNCTIONS ******************
        public Gameworld updateGameWorld(Gameworld gameWorld, GameTime gameTime, InputHandler inputHandler)
        {
            getModelFromGameworld(gameWorld);

            //Change gamestate

            checkInput(gameTime, inputHandler, gameWorld);

            gameWorld.setPlayer(playerObject);

            return gameWorld;
        }