Last active
May 23, 2016 04:43
-
-
Save pathunstrom/5ac4274aada155373b10b47f9fca0650 to your computer and use it in GitHub Desktop.
The same test with some abstraction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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