Skip to content

Instantly share code, notes, and snippets.

@pathunstrom
Last active May 23, 2016 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pathunstrom/5ac4274aada155373b10b47f9fca0650 to your computer and use it in GitHub Desktop.
Save pathunstrom/5ac4274aada155373b10b47f9fca0650 to your computer and use it in GitHub Desktop.
The same test with some abstraction
import logging
import ppb.engine
from ppb.event import Quit, Tick
from ppb.components.models import GameObject
from ppb.components.controls import Publisher
import ppb.hw as hardware
hardware.choose("pygame")
logging.basicConfig(level=logging.INFO)
hardware.init((200, 200), "Test")
publisher = Publisher(hardware)
def get_events(*_):
hardware.update_input()
publisher.subscribe(Tick, get_events)
def quit_timer(time):
def callback(_, event, count=[time]):
count[0] += -1 * event.sec
if count[0] <= 0:
ppb.engine.message(Quit())
return callback
clock = GameObject(behaviors=[(Tick, quit_timer(5))])
ppb.engine.run(publisher)
import logging
from ppb.engine import message
from ppb.event import Quit, Tick
from ppb.tests.visual import Runner
logging.basicConfig(level=logging.INFO)
def quit_timer(time):
def callback(tick_event, count=[time]):
count[0] += -1 * tick_event.sec
if count[0] <= 0:
message(Quit())
return callback
test_runner = Runner("sdl2")
test_runner.set_events([(Tick, quit_timer(5))])
test_runner.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment