New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SNES-style gamepads #70

Open
lordmauve opened this Issue Feb 28, 2018 · 8 comments

Comments

Projects
None yet
4 participants
@lordmauve
Owner

lordmauve commented Feb 28, 2018

USB SNES-style gamepads are extremely cheap and I understand they are compatible without extra drivers across operating systems. The SNES gamepad can be seen as a lowest-common-denominator across modern gamepads, as nearly all more modern gamepads have at least as many buttons and axes.

Supporting gamepads would make a useful addition to let people create more fun games.

However, Pygame Zero should not require a gamepad, nor should users be able to create games with Pygame Zero that can only be played with a gamepad.

@lordmauve

This comment has been minimized.

Owner

lordmauve commented Mar 3, 2018

I would suggest this could be implemented with two mapping layers:

User gamepad mapping layer

Provide a command, built into pgzrun, to configure connected joysticks. It should save how the buttons and axes map to a standard SNES controller into a per-user config file, keyed by whatever joystick identifier property we can access.

Joystick events mapping

Inside Pygame Zero, map Joystick events to key up/key down events for the corresponding keys. We could provide a default mapping (stick 0 axis 0 should map to cursors, buttons to space, enter and so on) but let game authors customise the mapping by updating a new GAMEPADS builtin:

GAMEPADS[0] = {
        'directions': 'WASD',
        'A': key.Q,
        'B': key.E,
}

However this is achieved it should aim to minimise boilerplate for game developers.

If people find a game that was developed without specifying a key binding, they should just be able to add this to the top of the file (configured appropriately for game controls) to add pad controls. We could print help on how to do this to the terminal, if a user starts a Pygame Zero with a joystick attached that has key handlers and no GAMEPADS settings.

@nanoflite

This comment has been minimized.

nanoflite commented Jul 13, 2018

To keep it simple, what about having support for 2 gamepads only and by convention have one gamepad mapped to WASD and space and the other one to the arrow keys and enter? For the B button, we can find another key...

Just like the keyboard, have a gamepad1 and gamepad2 object you can query:
gamepad1[buttons.UP], ....

The glue in gpzero would be responsible to detect the gamepads and map the button presses to the gamepad objects. Also, when no gamepads are detected there's the fallback to the keys. Probably it wouldn't even hurt to have the keyboard support also there when a gamepad is connected. As an example, you can press W or press the up-button and both would fire the buttons.UP event....

We also need to have the event methods, e.g. on_button_press(button) etc...

@mariaS210

This comment has been minimized.

mariaS210 commented Jul 28, 2018

we're having a go at this, at the europython2018 sprint

@nanoflite

This comment has been minimized.

nanoflite commented Jul 28, 2018

@nanoflite

This comment has been minimized.

nanoflite commented Jul 29, 2018

@nanoflite

This comment has been minimized.

nanoflite commented Aug 15, 2018

I just created a PR for this:
#111

Cheers,
Johan

@lordmauve

This comment has been minimized.

Owner

lordmauve commented Sep 19, 2018

We now have a number of pull requests for this:

I'm going to try to get something merged drawing from all of these as necessary, but it will probably be slightly different to all of them.

@AnthonyBriggs

This comment has been minimized.

AnthonyBriggs commented Sep 19, 2018

Awesome news!

FWIW, I'm not so keen on only using gamepads. Xbox controller clones are also pretty cheap and work well. I'm teaching two boys (8 and 10) how to code via Mu and PgZero at the moment, and real controllers are a big drawcard. They also seemed to pick up how the axis values and button handlers work pretty quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment