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

(Issue #119) Remove return value from reinit screen #129

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/asteroids/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ def on_key_down(key):
game.player.turn += 1
if key == keys.RIGHT:
game.player.turn -= 1
if key == keys.SPACE and not game.player.frozen:
if key == keys.SPACE and not game.player.frozen and not is_paused():
sounds.fire.play()
game.bullets.append(game.player.fire())
if key == keys.RETURN:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return is an odd choice for a pause key. Perhaps P instead of return?

pause()
elif game.stage is GameStage.game_over:
if key == keys.BACKSPACE:
game.initials = game.initials[:-1]
Expand Down
2 changes: 1 addition & 1 deletion pgzero/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

from .constants import mouse, keys, keymods

from .game import exit
from .game import exit, pause, is_paused
33 changes: 22 additions & 11 deletions pgzero/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@

screen = None
DISPLAY_FLAGS = 0
paused = False

def pause():
global paused
paused = not paused

def is_paused():
return paused

def exit():
"""Wait for up to a second for all sounds to play out
Expand Down Expand Up @@ -56,7 +63,6 @@ def reinit_screen(self):

"""
global screen
changed = False
mod = self.mod

icon = getattr(self.mod, 'ICON', DEFAULTICON)
Expand All @@ -70,6 +76,7 @@ def reinit_screen(self):
w = getattr(mod, 'WIDTH', 800)
h = getattr(mod, 'HEIGHT', 600)
if w != self.width or h != self.height:
self.need_redraw = True
self.screen = pygame.display.set_mode((w, h), DISPLAY_FLAGS)
if hasattr(self.mod, 'screen'):
self.mod.screen.surface = self.screen
Expand All @@ -84,8 +91,6 @@ def reinit_screen(self):
pygame.display.set_caption(title)
self.title = title

return changed

@staticmethod
def show_default_icon():
"""Show a default icon loaded from Pygame Zero resources."""
Expand Down Expand Up @@ -192,9 +197,13 @@ def get_update_func(self):
except AttributeError:
return None
else:
if update.__code__.co_argcount == 0:
return lambda dt: update()
return update
def update_wrapper(dt):
if update.__code__.co_argcount == 0:
update()
else:
update(dt)
self.need_redraw = True
return update_wrapper

def get_draw_func(self):
"""Get a draw function.
Expand Down Expand Up @@ -261,13 +270,15 @@ def mainloop(self):
self.keyboard._release(event.key)
self.dispatch_event(event)

pgzclock.tick(dt)
if not paused:
pgzclock.tick(dt)

if update:
update(dt)

if update:
update(dt)

screen_change = self.reinit_screen()
if screen_change or update or pgzclock.fired or self.need_redraw:
self.reinit_screen()
if pgzclock.fired or self.need_redraw:
draw()
pygame.display.flip()
self.need_redraw = False