Ejemplo n.º 1
0
        // Created by Noble 11-07, edited by Alexander 12-06
        private void UpdateControls(GameTime gameTime)
        {
            // Update keyboard
            keyboard = Keyboard.GetState();

            // Reset walking
            walking = false;

            // if player hits the ground //or the top of a platform
            if (collidableObject.Position.Y >= InGame.groundRectangle.Top - collidableObject.origin.Y)
            {
                onGround    = true;
                direction.Y = 0;
            }
            else
            {
                onGround = false;
            }


            // If W or Up arrow key is pressed down And jump is not complete TODO: Fix jumping
            if ((keyboard.IsKeyDown(Keys.W) || keyboard.IsKeyDown(Keys.Up)) && !jumpComplete)
            {
                // Continue jump
                // Jump has already started
                if (jumpTime > 0)
                {
                    Jump(gameTime);
                }

                // Start jump
                // If jumpTime is reset and is on ground
                if (jumpTime == 0 && onGround)
                {
                    Jump(gameTime);
                }
            }
            else
            {
                // key was released, therefore set jump to complete
                jumpComplete = true;
                // if both keys are up and player is on ground
                if (keyboard.IsKeyUp(Keys.W) && keyboard.IsKeyUp(Keys.Up) && onGround)
                {
                    // Reset jump
                    jumpTime     = 0;
                    jumpComplete = false;
                }
                // Fall
                Fall(gameTime);
            }

            // If A or Left arrow key is pressed down AND right keys are not down as to prevent pressing both directions at once
            if (keyboard.IsKeyDown(Keys.A) || keyboard.IsKeyDown(Keys.Left) && !(keyboard.IsKeyDown(Keys.D) || keyboard.IsKeyDown(Keys.Right)))
            {
                // Move left
                MoveLeft();
            }

            // If D or Right arrow key is pressed down AND left keys are not down as to prevent pressing both directions at once
            if (keyboard.IsKeyDown(Keys.D) || keyboard.IsKeyDown(Keys.Right) && !(keyboard.IsKeyDown(Keys.A) || keyboard.IsKeyDown(Keys.Left)))
            {
                // Move Right
                MoveRight();
            }

            // If Space or Z key are pressed down
            if ((UtilityClass.SingleActivationKey(Keys.Space) && !UtilityClass.SingleActivationKey(Keys.Z)) || (UtilityClass.SingleActivationKey(Keys.Z) && !UtilityClass.SingleActivationKey(Keys.Space)))
            {
                // If not already attacking
                if (!attacking)
                {
                    // Start a new attack
                    StartAttack();
                }
            }
        }
Ejemplo n.º 2
0
        // Edited by Noble 12-10
        /// <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 || UtilityClass.SingleActivationKey(Keys.End))
            {
                this.Exit();
            }

            UtilityClass.Update();

            switch (GameState)
            {
            case GameStates.MainMenu:
                MainMenu.Update();
                break;

            case GameStates.InGame:
                InGame.Update(gameTime);
                break;

            case GameStates.Tutorial:
                Tutorial.Update(gameTime);
                break;

            case GameStates.Credits:
                Credits.Update(gameTime);
                break;

            case GameStates.Exit:
                this.Exit();
                break;

            case GameStates.HighScore:
                break;

            case GameStates.GameOver:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (UtilityClass.SingleActivationKey(Keys.Escape))
            {
                LoadContent();
            }

            base.Update(gameTime);
        }