Mercurial > rinkhals
comparison gamelib/gameboard.py @ 39:ec79aabe2bf1
Scroll game window with arrow keys.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Mon, 31 Aug 2009 14:19:13 +0000 |
parents | 497b53b69280 |
children | 678421bd58ee |
comparison
equal
deleted
inserted
replaced
38:03121c89d5fd | 39:ec79aabe2bf1 |
---|---|
1 import pygame | 1 import pygame |
2 from pygame.locals import MOUSEBUTTONDOWN | 2 from pygame.locals import MOUSEBUTTONDOWN, KEYDOWN, K_UP, K_DOWN, K_LEFT, K_RIGHT |
3 from pgu import gui | 3 from pgu import gui |
4 | 4 |
5 import data | 5 import data |
6 import tiles | 6 import tiles |
7 | 7 |
30 | 30 |
31 class VidWidget(gui.Widget): | 31 class VidWidget(gui.Widget): |
32 def __init__(self, gameboard, vid, **params): | 32 def __init__(self, gameboard, vid, **params): |
33 gui.Widget.__init__(self, **params) | 33 gui.Widget.__init__(self, **params) |
34 self.gameboard = gameboard | 34 self.gameboard = gameboard |
35 vid.bounds = pygame.Rect((0, 0), vid.tile_to_view(vid.size)) | |
35 self.vid = vid | 36 self.vid = vid |
36 self.width = params.get('width', 0) | 37 self.width = params.get('width', 0) |
37 self.height = params.get('height', 0) | 38 self.height = params.get('height', 0) |
38 | 39 |
39 def paint(self, surface): | 40 def paint(self, surface): |
46 if width is not None: | 47 if width is not None: |
47 self.width = width | 48 self.width = width |
48 if height is not None: | 49 if height is not None: |
49 self.height = height | 50 self.height = height |
50 return self.width, self.height | 51 return self.width, self.height |
52 | |
53 def move_view(self, x, y): | |
54 self.vid.view.move_ip((x, y)) | |
51 | 55 |
52 def event(self, e): | 56 def event(self, e): |
53 if e.type == MOUSEBUTTONDOWN: | 57 if e.type == MOUSEBUTTONDOWN: |
54 self.gameboard.use_tool(e) | 58 self.gameboard.use_tool(e) |
55 | 59 |
96 return | 100 return |
97 pos = self.tv.screen_to_tile(e.pos) | 101 pos = self.tv.screen_to_tile(e.pos) |
98 self.tv.set(pos, self.selected_tool) | 102 self.tv.set(pos, self.selected_tool) |
99 | 103 |
100 def event(self, e): | 104 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) | |
102 | 116 |
103 def clear_foxes(self): | 117 def clear_foxes(self): |
104 for fox in self.foxes: | 118 for fox in self.foxes: |
105 self.tv.sprites.remove(fox) | 119 self.tv.sprites.remove(fox) |
106 self.foxes = [] # Remove all the foxes | 120 self.foxes = [] # Remove all the foxes |