Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amyreese/cpgame
Simple game framework for CircuitPython embedded hardware
https://github.com/amyreese/cpgame
circuit-playground-express circuitpython framework game-engine
Last synced: 1 day ago
JSON representation
Simple game framework for CircuitPython embedded hardware
- Host: GitHub
- URL: https://github.com/amyreese/cpgame
- Owner: amyreese
- License: mit
- Created: 2019-03-12T06:34:38.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-10T00:33:06.000Z (almost 5 years ago)
- Last Synced: 2024-11-13T11:12:35.396Z (7 days ago)
- Topics: circuit-playground-express, circuitpython, framework, game-engine
- Language: Python
- Size: 18.6 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
cpgame
======Simple "game" framework for [CircuitPython][] embedded hardware.
[![build status](https://travis-ci.org/jreese/cpgame.svg?branch=master)](https://travis-ci.org/jreese/cpgame)
[![version](https://img.shields.io/pypi/v/cpgame.svg)](https://pypi.org/project/cpgame)
[![license](https://img.shields.io/pypi/l/cpgame.svg)](https://github.com/jreese/cpgame/blob/master/LICENSE)
[![code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)Install
-------Download the [compiled library][cpgame.mpy] and copy it to your device's directory:
```bash
$ cp -X cpgame.mpy /Volumes/CIRCUITPY/
```[cpgame.mpy]: https://github.com/jreese/cpgame/releases/download/v0.5/cpgame.mpy
Overview
--------cpgame provides a number of decorators and a simple event loop to provide a responsive
framework for building applications and games on embedded hardware using CircuitPython.Run a function on every "tick" of the event loop:
```python
from cpgame import start, tick@tick
def loop(now):
...start()
```Blink a Neopixel every second:
```python
@every(1)
def periodic(now):
pixel[0] = RED if int(now) % 2 else OFF
```Turn a Neopixel on and off with a button press:
```python
@on(board.BUTTON_A, DOWN)
def pressed(now):
pixel[0] = RED@on(board.BUTTON_A, UP)
def released(now):
pixel[0] = OFF
```Create or reset timers:
```python
@on(board.BUTTON_A)
def flood(now):
pixels.fill(random.choice(COLORS))
delay = random.randint(20, 100) / 10 # between 2 and 10 seconds
after(delay, flood)@on(board.BUTTON_B)
def halt(now):
cancel(flood)
```Play sound:
```python
enable_speaker()
middle_a = sample(440)@on(board.BUTTON_A)
def noise(now):
play_sound(middle_a, 1)
```Roadmap
-------* Support more boards than Circuit Playground Express.
* Add helper functions for animating NeoPixels, raw audio clips, and LCD displays.License
-------aiosqlite is copyright [John Reese](https://jreese.sh), and licensed under the
MIT license. I am providing code in this repository to you under an open source
license. This is my personal repository; the license you receive to my code
is from me and not from my employer. See the `LICENSE` file for details.[CircuitPython]: https://circuitpython.org