Changeset 39:ec79aabe2bf1


Ignore:
Timestamp:
Aug 31, 2009, 2:19:13 PM (11 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@40
Message:

Scroll game window with arrow keys.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gamelib/gameboard.py

    r37 r39  
    11import pygame
    2 from pygame.locals import MOUSEBUTTONDOWN
     2from pygame.locals import MOUSEBUTTONDOWN, KEYDOWN, K_UP, K_DOWN, K_LEFT, K_RIGHT
    33from pgu import gui
    44
     
    3333        gui.Widget.__init__(self, **params)
    3434        self.gameboard = gameboard
     35        vid.bounds = pygame.Rect((0, 0), vid.tile_to_view(vid.size))
    3536        self.vid = vid
    3637        self.width = params.get('width', 0)
     
    4950            self.height = height
    5051        return self.width, self.height
     52
     53    def move_view(self, x, y):
     54        self.vid.view.move_ip((x, y))
    5155
    5256    def event(self, e):
     
    99103
    100104    def event(self, e):
    101         self.disp.event(e)
     105        if e.type == KEYDOWN:
     106            if e.key == K_UP:
     107                self.tvw.move_view(0, -self.TILE_DIMENSIONS[1])
     108            if e.key == K_DOWN:
     109                self.tvw.move_view(0, self.TILE_DIMENSIONS[1])
     110            if e.key == K_LEFT:
     111                self.tvw.move_view(-self.TILE_DIMENSIONS[0], 0)
     112            if e.key == K_RIGHT:
     113                self.tvw.move_view(self.TILE_DIMENSIONS[0], 0)
     114        else:
     115            self.disp.event(e)
    102116
    103117    def clear_foxes(self):
Note: See TracChangeset for help on using the changeset viewer.