Giter Site home page Giter Site logo

cpgame's Introduction

cpgame

Simple "game" framework for CircuitPython embedded hardware.

build status version license code style

Install

Download the compiled library and copy it to your device's directory:

$ cp -X cpgame.mpy /Volumes/CIRCUITPY/

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:

from cpgame import start, tick

@tick
def loop(now):
    ...

start()

Blink a Neopixel every second:

@every(1)
def periodic(now):
    pixel[0] = RED if int(now) % 2 else OFF

Turn a Neopixel on and off with a button press:

@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:

@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:

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

cpgame is copyright John Reese, 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.

cpgame's People

Contributors

amyreese avatar thatch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.