Пример #1
0
        // handle key presses
        public override void HandleInput(InputState input)
        {
            if (input.IsNewKeyPress(Keys.Up, GameUtil.MenuSelectDelay))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }
            if (input.IsNewKeyPress(Keys.Down, GameUtil.MenuSelectDelay))
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }
            if (input.IsNewKeyPress(Keys.Enter))
            {
                switch (selectedEntry)
                {
                    case (int)MainMenuEntry.Start:
                        ScreenManager.AddScreen(new PlayGameScreen());
                        ScreenManager.RemoveScreen(this);
                        break;
                    case (int)MainMenuEntry.Exit:
                        ScreenManager.Game.Exit();
                        break;
                }
            }
        }
Пример #2
0
 public override void HandleInput(InputState input)
 {
     if (input.IsNewKeyPress(Keys.Space, GameUtil.MenuSelectDelay))
     {
         ScreenManager.AddScreen(new TitleScreen());
         ScreenManager.RemoveScreen(this);
     }
 }
Пример #3
0
        public void HandlePlayerJump(InputState input)
        {
            /* We put this check above new jump check because if new jump check
             * is first, then we'll register new jump, see it's not same as old
             * input state, and immediate stop jumping.  Doing it this way ensures
             * we get at least one input state with jump being true meaning we
             * can maintain the jump.
             */
            if (input.IsCurrentKeyPress(Keys.Space)) // player still jumping
            {
                if (player.Jumping && !player.ForceDown) // we're still going up!
                {
                    // hit max height?
                    if ((player.GetComponent("Mobile") as Mobile).Position.Y <= GameUtil.playerY - GameUtil.maxJumpHeight)
                    {
                        player.ForceDown = true;
                        (player.GetComponent("Mobile") as Mobile).Velocity += new Vector2(0, GameUtil.JumpFriction);
                    }
                }
            }
            else // we let go, so force going down
            {
                if (player.Jumping && !player.ForceDown)
                {
                    player.ForceDown = true;
                    (player.GetComponent("Mobile") as Mobile).Velocity += new Vector2(0, GameUtil.JumpFriction);
                }
            }

            if (input.IsNewKeyPress(Keys.Space)) // player new jump!
            {
                if (!player.Jumping && !player.ForceDown) // if not forcing down nor jumping, lets jump
                {
                    player.Jumping = true;
                    (player.GetComponent("Mobile") as Mobile).Velocity = new Vector2(0, GameUtil.JumpPower);
                }
            }

            // we need to stop falling when we hit ground.
            if (player.ForceDown)
            {
                if ((player.GetComponent("Mobile") as Mobile).Velocity.Y < GameUtil.FallPower)
                {
                    (player.GetComponent("Mobile") as Mobile).Velocity += new Vector2(0, GameUtil.JumpFriction);
                }

                if ((player.GetComponent("Mobile") as Mobile).Position.Y >= GameUtil.playerY)
                {
                    Vector2 standPosition = (player.GetComponent("Mobile") as Mobile).Position;
                    standPosition.Y = GameUtil.playerY;
                    (player.GetComponent("Mobile") as Mobile).Position = standPosition;
                    player.ForceDown = false;
                    player.Jumping = false;
                }
            }
        }