pgzero
pgzero copied to clipboard
Add support for SNES-style gamepads
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.
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.
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...
we're having a go at this, at the europython2018 sprint
Nice! I'm also working on it. Let me know how it went.
Johan
On Sat, 28 Jul 2018, 12:32 mariaS210, [email protected] wrote:
we're having a go at this, at the europython2018 sprint
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/lordmauve/pgzero/issues/70#issuecomment-408598207, or mute the thread https://github.com/notifications/unsubscribe-auth/AADj5Zd9szZxXNx8BjzjyZ-eGhLQypVcks5uLD2qgaJpZM4SWRNz .
FWIW... here's the link to what I already did: https://github.com/nanoflite/pgzero/tree/feature/gamepad_support
Cheers, Johan
On Sat, Jul 28, 2018 at 2:35 PM, Johan Van den Brande < [email protected]> wrote:
Nice! I'm also working on it. Let me know how it went.
Johan
On Sat, 28 Jul 2018, 12:32 mariaS210, [email protected] wrote:
we're having a go at this, at the europython2018 sprint
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/lordmauve/pgzero/issues/70#issuecomment-408598207, or mute the thread https://github.com/notifications/unsubscribe-auth/AADj5Zd9szZxXNx8BjzjyZ-eGhLQypVcks5uLD2qgaJpZM4SWRNz .
-- "Your time is limited, so don’t waste it living someone else’s life.", Steve Jobs
http://about.me/johan.vandenbrande
I just created a PR for this: https://github.com/lordmauve/pgzero/pull/111
Cheers, Johan
We now have a number of pull requests for this:
- #113 by @mariaS210
- #111 by @nanoflite
- #115 by @AnthonyBriggs
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.
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.
What is the status of this issue? There are some PRs and long time no work on this. It would be great to have a controller support soon. :)
@lordmauve if it helps, i can try to adapt my PR, or make an entirely new one, that draws from the other approaches, if you'd let me know what you found interesting in each of them i admit, my PR did not implement quite as described in https://github.com/lordmauve/pgzero/issues/70#issuecomment-370143820 but maybe i can remake it to better fit this vision.
SDL2 mostly solves this problem by providing the new Controller API (separate from Joystick API) and a database of mappings so all kinds of controllers are mapped to a standard button layout. https://github.com/gabomdq/SDL_GameControllerDB So you would just need to map these to Pygame Zero keys and then you would have support for SNES, Xbox, whatever with no configuration required. Unfortunately I guess Pygame Zero is using SDL1? So would require a switch to SDL2 or else someone to write support in Python to read the gamecontrollerdb.txt format and map it to the SDL1 joysticks.
Hi I am 11 Years old and looking for my SNES gamepad support with simplified pygame-zero. I love to use in MU editor. Kindly release support for this device. Till then i am going to learn pygame direct support with joystick. Complex coding. Thanks.