astro-pi / python-sense-hat

Source code for Sense HAT Python library
https://sense-hat.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
505 stars 253 forks source link

Moar examples for joystick input #49

Closed eah13 closed 8 years ago

eah13 commented 8 years ago

I whipped up a few examples in the process of learning SenseStick and exploring other means of handling the joystick's input. Thought maybe they'd be useful to others.

The first commit has SenseStick examples, including a re-implementation of evdev_joystick.py that doesn't import evdev (using SenseStick's char codes instead since that seems simpler), some alternate graphical tests, and a simple game framework, bug.py. The second commit uses stidlib's curses and thrid party module readchar to implement bug.py as examples of using them to handle input. Readchar may require apting a shared lib, as noted in the docstring. I haven't tested any of these on platforms outside the Pi since I'm not sure that's relevant to this module.

bug.py and its cousins are suitable for making simple 2D games to be played with the joystick and have a simple global state dictionary that could be extended to include enemies, keep score, etc. The code is intentionally verbose to help suggest ways of extending it.

Dunno if these are the kinds of things you want in the examples but thought I'd submit upstream since I have them. Feel free to cherry pick or I can remove files from this PR if only some are useful.

As with other examples, Python2ers will need to from __future__ import print_function