Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvements #285

Open
wants to merge 13 commits into
base: canon
Choose a base branch
from
Prev Previous commit
Next Next commit
Fix remaining styling issues
nbraud committed May 28, 2019
commit 3cd96aee1c5f41b453c70c128e551202ed791d89
4 changes: 2 additions & 2 deletions examples/targets_with_twisted.py
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ def __init__(self, *p, **kw):
self.add(Target(pos=Vector(x, 1.875)), tags=['target'])


######### This is "non-game-specific code" ###########
# This is "non-game-specific code"
class _FinishLoop(Exception):
pass

@@ -118,7 +118,7 @@ def loop_once(engine):
yield loop.start(0.001)
except _FinishLoop:
pass
######### End of "non-game-specific code" ###########
# End of "non-game-specific code"


@defer.inlineCallbacks
11 changes: 6 additions & 5 deletions ppb/camera.py
Original file line number Diff line number Diff line change
@@ -91,11 +91,12 @@ def point_in_viewport(self, point: Vector) -> bool:
return vpx <= px <= (vpw + vpx) and vpy <= py <= (vph + vpy)

def in_frame(self, sprite: BaseSprite) -> bool:
return (self.frame_left <= sprite.right and
self.frame_right >= sprite.left and
self.frame_top <= sprite.bottom and
self.frame_bottom >= sprite.top
)
return (
self.frame_left <= sprite.right and
self.frame_right >= sprite.left and
self.frame_top <= sprite.bottom and
self.frame_bottom >= sprite.top
)

def translate_to_frame(self, point: Vector) -> Vector:
"""
4 changes: 2 additions & 2 deletions ppb/keycodes.py
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ class H(KeyCode):
""


class I(KeyCode):
class I(KeyCode): # noqa: E742
""


@@ -72,7 +72,7 @@ class N(KeyCode):
""


class O(KeyCode):
class O(KeyCode): # noqa: E742
""


6 changes: 4 additions & 2 deletions ppb/systems/__init__.py
Original file line number Diff line number Diff line change
@@ -27,7 +27,8 @@ def __exit__(self, exc_type, exc_val, exc_tb):

class Renderer(System):

def __init__(self, resolution=default_resolution, window_title: str = "PursuedPyBear", target_frame_rate: int = 30, **kwargs):
def __init__(self, resolution=default_resolution,
window_title: str = "PursuedPyBear", target_frame_rate: int = 30, **kwargs):
self.resolution = resolution
self.resources = {}
self.window = None
@@ -163,6 +164,7 @@ def on_idle(self, idle_event: events.Idle, signal):
self.accumulated_time += this_tick - self.last_tick
self.last_tick = this_tick
while self.accumulated_time >= self.time_step:
# This might need to change for the Idle event system to signal _only_ once per idle event.
# This might need to change for the Idle event system
# to signal _only_ once per idle event.
self.accumulated_time += -self.time_step
signal(events.Update(self.time_step))
9 changes: 6 additions & 3 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
@@ -209,7 +209,8 @@ def on_scene_stopped(self, event, signal):
assert event.scene is self
test_function()

with GameEngine(TestScene, systems=[Updater, Failer], fail=lambda x: False, message="Will only time out.") as ge:
with GameEngine(TestScene, systems=[Updater, Failer],
fail=lambda x: False, message="Will only time out.") as ge:
ge.run()

test_function.assert_called()
@@ -250,7 +251,8 @@ def on_test_event(self, event, signal):
def event_extension(self, event):
event.test_value = "Red"

with GameEngine(TestScene, systems=[Updater, Failer], message="Will only time out.", fail=lambda x: False) as ge:
with GameEngine(TestScene, systems=[Updater, Failer],
message="Will only time out.", fail=lambda x: False) as ge:
ge.run()


@@ -299,5 +301,6 @@ def on_idle(self, event: events.Idle, signal):
was_called = True
signal(events.Quit())

with GameEngine(BaseScene, systems=[TestSystem, Failer], fail=lambda x: False, message="Can only time out.") as ge:
with GameEngine(BaseScene, systems=[TestSystem, Failer],
fail=lambda x: False, message="Can only time out.") as ge:
ge.run()