Mercurial > rinkhals
annotate gamelib/gameboard.py @ 60:e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Mon, 31 Aug 2009 19:10:31 +0000 |
parents | 08665fa60345 |
children | 99fbb652ce8d |
rev | line source |
---|---|
35 | 1 import pygame |
39
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
2 from pygame.locals import MOUSEBUTTONDOWN, KEYDOWN, K_UP, K_DOWN, K_LEFT, K_RIGHT |
35 | 3 from pgu import gui |
9 | 4 |
5 import data | |
24
7584453f4944
Add support for PNG tiles.
Simon Cross <hodgestar@gmail.com>
parents:
17
diff
changeset
|
6 import tiles |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
7 import constants |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
8 import buildings |
9 | 9 |
35 | 10 |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
11 class OpaqueLabel(gui.Label): |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
12 def paint(self, s): |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
13 s.fill(self.style.background) |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
14 gui.Label.paint(self, s) |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
15 |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
16 def update_value(self, value): |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
17 self.value = value |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
18 self.style.width, self.style.height = self.font.size(self.value) |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
19 self.repaint() |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
20 |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
21 |
35 | 22 class ToolBar(gui.Table): |
23 def __init__(self, gameboard, **params): | |
24 gui.Table.__init__(self, **params) | |
25 self.gameboard = gameboard | |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
26 self.cash_counter = OpaqueLabel("Groats: ", color=constants.FG_COLOR) |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
27 self.tr() |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
28 self.add(self.cash_counter) |
52
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
29 self.add_tool_button("Sell chicken", constants.TOOL_SELL_CHICKEN) |
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
30 self.add_tool_button("Sell egg", constants.TOOL_SELL_EGG) |
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
31 self.add_tool_button("Buy fence", constants.TOOL_BUY_FENCE) |
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
32 self.add_tool_button("Buy henhouse", constants.TOOL_BUY_HENHOUSE) |
60
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
33 self.add_tool_button("Buy guard tower", constants.TOOL_BUY_GUARDTOWER) |
35 | 34 |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
35 def update_cash_counter(self, amount): |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
36 self.cash_counter.update_value("Groats: %s" % amount) |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
37 self.repaint() |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
38 |
35 | 39 def add_tool_button(self, text, tool): |
40 button = gui.Button(text) | |
41 button.connect(gui.CLICK, lambda: self.gameboard.set_selected_tool(tool)) | |
42 self.tr() | |
36
5569430fd82e
Display cleanup and rationalisation.
Jeremy Thurgood <firxen@gmail.com>
parents:
35
diff
changeset
|
43 self.add(button) |
35 | 44 |
45 | |
46 class VidWidget(gui.Widget): | |
47 def __init__(self, gameboard, vid, **params): | |
48 gui.Widget.__init__(self, **params) | |
49 self.gameboard = gameboard | |
39
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
50 vid.bounds = pygame.Rect((0, 0), vid.tile_to_view(vid.size)) |
35 | 51 self.vid = vid |
52 self.width = params.get('width', 0) | |
53 self.height = params.get('height', 0) | |
54 | |
55 def paint(self, surface): | |
56 self.vid.paint(surface) | |
57 | |
58 def update(self, surface): | |
36
5569430fd82e
Display cleanup and rationalisation.
Jeremy Thurgood <firxen@gmail.com>
parents:
35
diff
changeset
|
59 return self.vid.update(surface) |
35 | 60 |
61 def resize(self, width=0, height=0): | |
62 if width is not None: | |
63 self.width = width | |
64 if height is not None: | |
65 self.height = height | |
66 return self.width, self.height | |
67 | |
39
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
68 def move_view(self, x, y): |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
69 self.vid.view.move_ip((x, y)) |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
70 |
35 | 71 def event(self, e): |
72 if e.type == MOUSEBUTTONDOWN: | |
73 self.gameboard.use_tool(e) | |
74 | |
75 | |
9 | 76 class GameBoard(object): |
77 TILE_DIMENSIONS = (20, 20) | |
35 | 78 TOOLBAR_WIDTH = 140 |
9 | 79 |
80 def __init__(self): | |
24
7584453f4944
Add support for PNG tiles.
Simon Cross <hodgestar@gmail.com>
parents:
17
diff
changeset
|
81 self.tv = tiles.FarmVid() |
9 | 82 self.tv.tga_load_tiles(data.filepath('tiles.tga'), self.TILE_DIMENSIONS) |
24
7584453f4944
Add support for PNG tiles.
Simon Cross <hodgestar@gmail.com>
parents:
17
diff
changeset
|
83 self.tv.png_folder_load_tiles(data.filepath('tiles')) |
9 | 84 self.tv.tga_load_level(data.filepath('level1.tga')) |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
85 self.create_disp() |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
86 |
35 | 87 self.selected_tool = None |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
88 self.chickens = [] |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
89 self.foxes = [] |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
90 self.henhouses = [] |
60
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
91 self.guardtowers = [] |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
92 self.cash = 0 |
52
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
93 self.add_cash(constants.STARTING_CASH) |
17
cbbc5da7708a
Interaction with the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
14
diff
changeset
|
94 |
35 | 95 def create_disp(self): |
96 width, height = pygame.display.get_surface().get_size() | |
36
5569430fd82e
Display cleanup and rationalisation.
Jeremy Thurgood <firxen@gmail.com>
parents:
35
diff
changeset
|
97 tbl = gui.Table() |
5569430fd82e
Display cleanup and rationalisation.
Jeremy Thurgood <firxen@gmail.com>
parents:
35
diff
changeset
|
98 tbl.tr() |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
99 self.toolbar = ToolBar(self) |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
100 tbl.td(self.toolbar, width=self.TOOLBAR_WIDTH) |
37
497b53b69280
Always update the vidwidget.
Jeremy Thurgood <firxen@gmail.com>
parents:
36
diff
changeset
|
101 self.tvw = VidWidget(self, self.tv, width=width-self.TOOLBAR_WIDTH, height=height) |
497b53b69280
Always update the vidwidget.
Jeremy Thurgood <firxen@gmail.com>
parents:
36
diff
changeset
|
102 tbl.td(self.tvw) |
35 | 103 self.disp = gui.App() |
36
5569430fd82e
Display cleanup and rationalisation.
Jeremy Thurgood <firxen@gmail.com>
parents:
35
diff
changeset
|
104 self.disp.init(tbl) |
14 | 105 |
12
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
106 def paint(self, screen): |
35 | 107 self.disp.paint(screen) |
14 | 108 |
9 | 109 def update(self, screen): |
37
497b53b69280
Always update the vidwidget.
Jeremy Thurgood <firxen@gmail.com>
parents:
36
diff
changeset
|
110 self.tvw.reupdate() |
35 | 111 return self.disp.update(screen) |
9 | 112 |
113 def loop(self): | |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
114 self.tv.loop() |
9 | 115 |
35 | 116 def set_selected_tool(self, tool): |
117 self.selected_tool = tool | |
17
cbbc5da7708a
Interaction with the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
14
diff
changeset
|
118 |
cbbc5da7708a
Interaction with the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
14
diff
changeset
|
119 def use_tool(self, e): |
52
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
120 if self.selected_tool == constants.TOOL_SELL_CHICKEN: |
54
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
121 self.sell_chicken(e.pos) |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
122 elif self.selected_tool == constants.TOOL_SELL_EGG: |
52
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
123 pass |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
124 elif self.selected_tool == constants.TOOL_BUY_FENCE: |
54
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
125 self.buy_fence(self.tv.screen_to_tile(e.pos)) |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
126 elif self.selected_tool == constants.TOOL_BUY_HENHOUSE: |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
127 self.buy_henhouse(self.tv.screen_to_tile(e.pos)) |
60
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
128 elif self.selected_tool == constants.TOOL_BUY_GUARDTOWER: |
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
129 self.buy_guardtower(self.tv.screen_to_tile(e.pos)) |
17
cbbc5da7708a
Interaction with the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
14
diff
changeset
|
130 |
54
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
131 def get_chicken(self, pos): |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
132 for chick in self.chickens: |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
133 if chick.rect.collidepoint(pos): |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
134 return chick |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
135 return None |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
136 |
54
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
137 def sell_chicken(self, pos): |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
138 chick = self.get_chicken(pos) |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
139 if chick is None: |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
140 return |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
141 if len(self.chickens) == 1: |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
142 print "You can't sell your last chicken!" |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
143 return |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
144 self.add_cash(constants.SELL_PRICE_CHICKEN) |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
145 self.remove_chicken(chick) |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
146 |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
147 def buy_fence(self, tile_pos): |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
148 if self.tv.get(tile_pos) != tiles.REVERSE_TILE_MAP['grassland']: |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
149 return |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
150 if self.cash < constants.BUY_PRICE_FENCE: |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
151 print "You can't afford a fence." |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
152 return |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
153 self.add_cash(-constants.BUY_PRICE_FENCE) |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
154 self.tv.set(tile_pos, tiles.REVERSE_TILE_MAP['fence']) |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
155 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
156 def buy_henhouse(self, tile_pos): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
157 if self.cash < constants.BUY_PRICE_HENHOUSE: |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
158 return |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
159 henhouse = buildings.HenHouse(tile_pos) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
160 if henhouse.place(self.tv): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
161 self.add_cash(-constants.BUY_PRICE_HENHOUSE) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
162 self.add_henhouse(henhouse) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
163 |
60
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
164 def buy_guardtower(self, tile_pos): |
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
165 if self.cash < constants.BUY_PRICE_GUARDTOWER: |
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
166 return |
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
167 guardtower = buildings.GuardTower(tile_pos) |
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
168 if guardtower.place(self.tv): |
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
169 self.add_cash(-constants.BUY_PRICE_GUARDTOWER) |
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
170 self.add_guardtower(guardtower) |
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
171 |
14 | 172 def event(self, e): |
39
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
173 if e.type == KEYDOWN: |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
174 if e.key == K_UP: |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
175 self.tvw.move_view(0, -self.TILE_DIMENSIONS[1]) |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
176 if e.key == K_DOWN: |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
177 self.tvw.move_view(0, self.TILE_DIMENSIONS[1]) |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
178 if e.key == K_LEFT: |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
179 self.tvw.move_view(-self.TILE_DIMENSIONS[0], 0) |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
180 if e.key == K_RIGHT: |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
181 self.tvw.move_view(self.TILE_DIMENSIONS[0], 0) |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
182 else: |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
183 self.disp.event(e) |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
184 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
185 def clear_foxes(self): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
186 for fox in self.foxes: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
187 self.tv.sprites.remove(fox) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
188 self.foxes = [] # Remove all the foxes |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
189 |
29 | 190 def move_foxes(self): |
191 for fox in self.foxes: | |
192 fox.move(self) | |
193 | |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
194 def add_chicken(self, chicken): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
195 self.chickens.append(chicken) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
196 self.tv.sprites.append(chicken) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
197 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
198 def add_fox(self, fox): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
199 self.foxes.append(fox) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
200 self.tv.sprites.append(fox) |
29 | 201 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
202 def add_henhouse(self, henhouse): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
203 self.henhouses.append(henhouse) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
204 self.tv.sprites.append(henhouse) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
205 |
60
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
206 def add_guardtower(self, guardtower): |
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
207 self.guardtowers.append(guardtower) |
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
208 self.tv.sprites.append(guardtower) |
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
209 |
29 | 210 def remove_fox(self, fox): |
211 if fox in self.foxes: | |
212 self.foxes.remove(fox) | |
213 self.tv.sprites.remove(fox) | |
214 | |
215 def remove_chicken(self, chick): | |
216 if chick in self.chickens: | |
217 self.chickens.remove(chick) | |
218 self.tv.sprites.remove(chick) | |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
219 |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
220 def add_cash(self, amount): |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
221 self.cash += amount |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
222 self.toolbar.update_cash_counter(self.cash) |