Ejemplo n.º 1
0
 public void DisablePlayerInput(PlayerObject player)
 {
     KeyboardState disableState = Keyboard.GetState();
     if(disableState.IsKeyDown(Keys.Left) || disableState.IsKeyDown(Keys.Right) || disableState.IsKeyDown(Keys.Space))
     {
         player.physComp.velocity.X = 0;
     }
 }
Ejemplo n.º 2
0
        public void handlePlayerInput(PlayerObject playerObject)
        {
            currentKeyboardState = Keyboard.GetState();
            currentGamePadState = GamePad.GetState(PlayerIndex.One);

            if (currentKeyboardState.IsKeyDown(Keys.Space) || currentGamePadState.IsButtonDown(Buttons.A))
            {
                if (!playerObject.IsJumping)
                {
                    playerObject.physComp.velocity.Y = -PlayerObject.JumpSpeed;
                    playerObject.IsJumping = true;
                    Game1.sounds["jump"].Play();
                    //TODO: Change the Vertical velocity to a higher or lower based on play.
                }
            }

            if (currentKeyboardState.IsKeyDown(Keys.Left) || currentGamePadState.DPad.Left == ButtonState.Pressed)
            {
                playerObject.physComp.velocity.X = -PlayerObject.MaxHorizontalVelocity;
            }

            if (currentKeyboardState.IsKeyDown(Keys.Right) || currentGamePadState.DPad.Right == ButtonState.Pressed)
            {
                playerObject.physComp.velocity.X = PlayerObject.MaxHorizontalVelocity;
            }

            if ((previousKeyboardState.IsKeyDown(Keys.Left)  && currentKeyboardState.IsKeyUp(Keys.Left)) || (previousGamePadState.DPad.Left == ButtonState.Pressed && currentGamePadState.DPad.Left == ButtonState.Released))
            {
                playerObject.physComp.velocity.X = 0;
            }

            if (previousKeyboardState.IsKeyDown(Keys.Right) && (currentKeyboardState.IsKeyUp(Keys.Right)) || ((previousGamePadState.DPad.Right == ButtonState.Pressed && currentGamePadState.DPad.Right == ButtonState.Released)))
            {
                playerObject.physComp.velocity.X = 0;
            }

            previousKeyboardState = currentKeyboardState;
            previousGamePadState = currentGamePadState;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Loads assets into the dictionary
            LoadAssets();

            Texture2D playerSprite = textures["Player"];
            player = new PlayerObject(Screen.Center.ToVector2(), playerSprite, true, PhysicsType.Player);
            player.Size = new Point(playerSprite.Width / 2, playerSprite.Height / 2);

            //GameObject floor = new GameObject(0, Screen.Bottom - 100, playerSprite, true, PhysicsType.StaticObject);
            //floor.Size = new Point(Screen.Width, 200);

            //gameObjects.Add(floor);
            CreateLevel();

            player.Teleport(player.SpawnPoint);
            PhysicsSystem.Instance.player = player;
        }