Public feed #725997

Anonymous

public text v1 · immutable
Raw Edit
·published 2007-10-04 20:27 UTC
rendered paste body
///////XODUS'S CODE//////////

//////////////////////////////
//My update for paddle , wall col check, and input

        public override void Update(int screen, Ball ball)
        {
            CheckWallCollision(screen);
            CheckBallCollision(ball);

            if (inputType == Input.gamePad)
                GetPadInput(PlayerIndex.One);

            else if (inputType == Input.keyBoard)
                GetKeyBoardInput();
        }

        private void CheckWallCollision(int screen)
        {
            if (base.position.X + base.texture.Width > screen)
            {
                base.position.X = screen - base.texture.Width;
            }
            else if (base.position.X < 1)
            {
                base.position.X = 0;
            }
        }

        private void GetPadInput(PlayerIndex index)
        {
            if (GamePad.GetState(index).ThumbSticks.Left.X > .01)
            {
                base.position.X += PaddleSpeed;
            }

            else if (GamePad.GetState(index).ThumbSticks.Left.X < 0)
            {
                base.position.X -= PaddleSpeed;
            }
        }

        private void GetKeyBoardInput()
        {
            keyState = Keyboard.GetState();

            if (keyState.IsKeyDown(Keys.A))
            {
                base.position.X -= PaddleSpeed;
            }
            else if (keyState.IsKeyDown(Keys.D))
            {
                base.position.X += PaddleSpeed;
            }
        }


//////NOW FOR THE HORROR! //////////


///////THIS IS NOT MY CODE/////////\\

//This is just his update...
internal class Input
{
    // Fields
    private Keys moveDownKey;
    private Keys moveUpKey;
    private ThumbStick thumbStick;
    private WhichInput whichInput = WhichInput.DONT_KNOW;

    // Methods
    public Input(Keys moveUpKey, Keys moveDownKey, ThumbStick thumbStick)
    {
        this.moveUpKey = moveUpKey;
        this.moveDownKey = moveDownKey;
        this.thumbStick = thumbStick;
    }

    public static GameControl GameKeyPressed()
    {
        KeyboardState keyboardState = Keyboard.GetState();
        GamePadState gamepadState = GamePad.GetState(PlayerIndex.One);
        MouseState mouseState = Mouse.GetState();
        if (keyboardState.IsKeyDown(Keys.Escape) || (gamepadState.Buttons.Back == ButtonState.Pressed))
        {
            return GameControl.ESCAPE;
        }
        if ((!keyboardState.IsKeyDown(Keys.Enter) && (gamepadState.Buttons.Start != ButtonState.Pressed)) && (mouseState.LeftButton != ButtonState.Pressed))
        {
            return GameControl.NONE;
        }
        return GameControl.START;
    }

    public Move KeyPressed()
    {
        KeyboardState keyboardState = Keyboard.GetState();
        GamePadState gamepadState = GamePad.GetState(PlayerIndex.One);
        switch (this.thumbStick)
        {
            case ThumbStick.LEFT:
                switch (this.whichInput)
                {
                    case WhichInput.KEYBOARD:
                        if (keyboardState.IsKeyDown(this.moveUpKey))
                        {
                            return Move.UP;
                        }
                        if (!keyboardState.IsKeyDown(this.moveDownKey))
                        {
                            break;
                        }
                        return Move.DOWN;

                    case WhichInput.CONTROLLER:
                        if (gamepadState.ThumbSticks.Left.Y > 0f)
                        {
                            return Move.UP;
                        }
                        if (gamepadState.ThumbSticks.Left.Y >= 0f)
                        {
                            break;
                        }
                        return Move.DOWN;

                    case WhichInput.DONT_KNOW:
                        if (keyboardState.IsKeyDown(this.moveUpKey))
                        {
                            this.whichInput = WhichInput.KEYBOARD;
                            return Move.UP;
                        }
                        if (gamepadState.ThumbSticks.Left.Y > 0f)
                        {
                            this.whichInput = WhichInput.CONTROLLER;
                            return Move.UP;
                        }
                        if (keyboardState.IsKeyDown(this.moveDownKey))
                        {
                            this.whichInput = WhichInput.KEYBOARD;
                            return Move.DOWN;
                        }
                        if (gamepadState.ThumbSticks.Left.Y >= 0f)
                        {
                            break;
                        }
                        this.whichInput = WhichInput.CONTROLLER;
                        return Move.DOWN;
                }
                break;

            case ThumbStick.RIGHT:
                switch (this.whichInput)
                {
                    case WhichInput.KEYBOARD:
                        if (keyboardState.IsKeyDown(this.moveUpKey))
                        {
                            return Move.UP;
                        }
                        if (!keyboardState.IsKeyDown(this.moveDownKey))
                        {
                            break;
                        }
                        return Move.DOWN;

                    case WhichInput.CONTROLLER:
                        if (gamepadState.ThumbSticks.Right.Y > 0f)
                        {
                            return Move.UP;
                        }
                        if (gamepadState.ThumbSticks.Right.Y < 0f)
                        {
                            return Move.DOWN;
                        }
                        break;

                    case WhichInput.DONT_KNOW:
                        if (keyboardState.IsKeyDown(this.moveUpKey))
                        {
                            this.whichInput = WhichInput.KEYBOARD;
                            return Move.UP;
                        }
                        if (gamepadState.ThumbSticks.Right.Y > 0f)
                        {
                            this.whichInput = WhichInput.CONTROLLER;
                            return Move.UP;
                        }
                        if (keyboardState.IsKeyDown(this.moveDownKey))
                        {
                            this.whichInput = WhichInput.KEYBOARD;
                            return Move.DOWN;
                        }
                        if (gamepadState.ThumbSticks.Right.Y >= 0f)
                        {
                            break;
                        }
                        this.whichInput = WhichInput.CONTROLLER;
                        return Move.DOWN;
                }
                break;
        }
        return Move.NONE;
    }

    public void Reset()
    {
        this.whichInput = WhichInput.DONT_KNOW;
    }

    // Properties
    public WhichInput Which
    {
        get
        {
            return this.whichInput;
        }
    }

    // Nested Types
    public enum GameControl
    {
        NONE,
        START,
        ESCAPE
    }

    public enum Move
    {
        NONE,
        UP,
        DOWN
    }

    public enum ThumbStick
    {
        LEFT,
        RIGHT
    }

    public enum WhichInput
    {
        KEYBOARD,
        CONTROLLER,
        DONT_KNOW
    }
}


///I don't even want to post his collisions, it's a few hundred lines long.