Skip to content
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 · 12 comments
Open

Add support for SNES-style gamepads #70

lordmauve opened this issue Feb 28, 2018 · 12 comments
Labels
enhancement New feature or request

Comments

@lordmauve
Copy link
Owner

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 lordmauve added the enhancement New feature or request label Mar 2, 2018
@lordmauve
Copy link
Owner Author

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
Copy link

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
Copy link

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

@nanoflite
Copy link

nanoflite commented Jul 28, 2018 via email

@nanoflite
Copy link

nanoflite commented Jul 29, 2018 via email

@nanoflite
Copy link

I just created a PR for this:
#111

Cheers,
Johan

@lordmauve
Copy link
Owner Author

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
Copy link

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.

@pintman
Copy link

pintman commented Mar 29, 2019

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. :)

@mariaS210
Copy link

@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 #70 (comment) but maybe i can remake it to better fit this vision.

@electronstudio
Copy link

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.

@robosidd
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants