comparison 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
comparison
equal deleted inserted replaced
59:efbaedd0fdfe 60:e2631c8e2cd6
28 self.add(self.cash_counter) 28 self.add(self.cash_counter)
29 self.add_tool_button("Sell chicken", constants.TOOL_SELL_CHICKEN) 29 self.add_tool_button("Sell chicken", constants.TOOL_SELL_CHICKEN)
30 self.add_tool_button("Sell egg", constants.TOOL_SELL_EGG) 30 self.add_tool_button("Sell egg", constants.TOOL_SELL_EGG)
31 self.add_tool_button("Buy fence", constants.TOOL_BUY_FENCE) 31 self.add_tool_button("Buy fence", constants.TOOL_BUY_FENCE)
32 self.add_tool_button("Buy henhouse", constants.TOOL_BUY_HENHOUSE) 32 self.add_tool_button("Buy henhouse", constants.TOOL_BUY_HENHOUSE)
33 self.add_tool_button("Buy guard tower", constants.TOOL_BUY_GUARDTOWER)
33 34
34 def update_cash_counter(self, amount): 35 def update_cash_counter(self, amount):
35 self.cash_counter.update_value("Groats: %s" % amount) 36 self.cash_counter.update_value("Groats: %s" % amount)
36 self.repaint() 37 self.repaint()
37 38
85 86
86 self.selected_tool = None 87 self.selected_tool = None
87 self.chickens = [] 88 self.chickens = []
88 self.foxes = [] 89 self.foxes = []
89 self.henhouses = [] 90 self.henhouses = []
91 self.guardtowers = []
90 self.cash = 0 92 self.cash = 0
91 self.add_cash(constants.STARTING_CASH) 93 self.add_cash(constants.STARTING_CASH)
92 94
93 def create_disp(self): 95 def create_disp(self):
94 width, height = pygame.display.get_surface().get_size() 96 width, height = pygame.display.get_surface().get_size()
121 pass 123 pass
122 elif self.selected_tool == constants.TOOL_BUY_FENCE: 124 elif self.selected_tool == constants.TOOL_BUY_FENCE:
123 self.buy_fence(self.tv.screen_to_tile(e.pos)) 125 self.buy_fence(self.tv.screen_to_tile(e.pos))
124 elif self.selected_tool == constants.TOOL_BUY_HENHOUSE: 126 elif self.selected_tool == constants.TOOL_BUY_HENHOUSE:
125 self.buy_henhouse(self.tv.screen_to_tile(e.pos)) 127 self.buy_henhouse(self.tv.screen_to_tile(e.pos))
128 elif self.selected_tool == constants.TOOL_BUY_GUARDTOWER:
129 self.buy_guardtower(self.tv.screen_to_tile(e.pos))
126 130
127 def get_chicken(self, pos): 131 def get_chicken(self, pos):
128 for chick in self.chickens: 132 for chick in self.chickens:
129 if chick.rect.collidepoint(pos): 133 if chick.rect.collidepoint(pos):
130 return chick 134 return chick
154 return 158 return
155 henhouse = buildings.HenHouse(tile_pos) 159 henhouse = buildings.HenHouse(tile_pos)
156 if henhouse.place(self.tv): 160 if henhouse.place(self.tv):
157 self.add_cash(-constants.BUY_PRICE_HENHOUSE) 161 self.add_cash(-constants.BUY_PRICE_HENHOUSE)
158 self.add_henhouse(henhouse) 162 self.add_henhouse(henhouse)
163
164 def buy_guardtower(self, tile_pos):
165 if self.cash < constants.BUY_PRICE_GUARDTOWER:
166 return
167 guardtower = buildings.GuardTower(tile_pos)
168 if guardtower.place(self.tv):
169 self.add_cash(-constants.BUY_PRICE_GUARDTOWER)
170 self.add_guardtower(guardtower)
159 171
160 def event(self, e): 172 def event(self, e):
161 if e.type == KEYDOWN: 173 if e.type == KEYDOWN:
162 if e.key == K_UP: 174 if e.key == K_UP:
163 self.tvw.move_view(0, -self.TILE_DIMENSIONS[1]) 175 self.tvw.move_view(0, -self.TILE_DIMENSIONS[1])
189 201
190 def add_henhouse(self, henhouse): 202 def add_henhouse(self, henhouse):
191 self.henhouses.append(henhouse) 203 self.henhouses.append(henhouse)
192 self.tv.sprites.append(henhouse) 204 self.tv.sprites.append(henhouse)
193 205
206 def add_guardtower(self, guardtower):
207 self.guardtowers.append(guardtower)
208 self.tv.sprites.append(guardtower)
209
194 def remove_fox(self, fox): 210 def remove_fox(self, fox):
195 if fox in self.foxes: 211 if fox in self.foxes:
196 self.foxes.remove(fox) 212 self.foxes.remove(fox)
197 self.tv.sprites.remove(fox) 213 self.tv.sprites.remove(fox)
198 214