Mercurial > dw
changeset 39:62f224d11915
Moved scrolling to display.py
| author | Radomir Dopieralski <moindev@sheep.art.pl> |
|---|---|
| date | Tue, 25 Dec 2007 22:11:45 +0100 |
| parents | 0bc7de373079 |
| children | b752350d6e03 |
| files | lib/display.py lib/game.py |
| diffstat | 2 files changed, 18 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/display.py Tue Dec 25 21:50:35 2007 +0100 +++ b/lib/display.py Tue Dec 25 22:11:45 2007 +0100 @@ -20,7 +20,7 @@ def __init__(self): pygame.init() - self.screen = pygame.display.set_mode((480, 320)) + self.screen = pygame.display.set_mode((320, 320)) self.sprites = SortedUpdates() self.shadows = pygame.sprite.RenderUpdates() self.effects = pygame.sprite.RenderUpdates() @@ -68,6 +68,22 @@ self.shadows.add(shadow.Shadow(sprite)) + def scroll_after(self, rect): + """Scrolls to keep the sepcified rectangle visible.""" + hscroll = 0 + vscroll = 0 + if rect.left<48: + hscroll = 3 + if rect.right>self.screen.get_width()-48: + hscroll = -3 + if rect.top<48: + vscroll = 2 + if rect.bottom>self.screen.get_height()-48: + vscroll = -2 + if hscroll or vscroll: + self.scroll(hscroll, vscroll) + self.refresh() + def scroll(self, dx, dy): """Scroll the map by specified amount"""
--- a/lib/game.py Tue Dec 25 21:50:35 2007 +0100 +++ b/lib/game.py Tue Dec 25 22:11:45 2007 +0100 @@ -51,19 +51,7 @@ key_pressed = None while 1: # Update the screen - hscroll = 0 - vscroll = 0 - if av.rect.left<48: - hscroll = 3 - if av.rect.right>self.display.screen.get_width()-48: - hscroll = -3 - if av.rect.top<48: - vscroll = 2 - if av.rect.bottom>self.display.screen.get_height()-48: - vscroll = -2 - if hscroll or vscroll: - self.display.scroll(hscroll, vscroll) - self.display.refresh() + self.display.scroll_after(av.rect) self.display.update() self.clock.tick(15) # Process input
