comparison gamelib/scenes/mess.py @ 759:386475464202 pyntnclick

Inspect game state for Thing.set_interact() instead of setting it manually everywhere.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 26 Jan 2013 13:00:31 +0200
parents f703bdce8c9e
children a8510f4e2ea1 43b49f1de828
comparison
equal deleted inserted replaced
758:f4853f817a7a 759:386475464202
124 124
125 INITIAL_DATA = { 125 INITIAL_DATA = {
126 'cans_available': 3, 126 'cans_available': 3,
127 } 127 }
128 128
129 def select_interact(self):
130 return '%icans' % (self.get_data('cans_available'),)
131
129 def interact_without(self): 132 def interact_without(self):
130 starting_cans = self.get_data('cans_available') 133 starting_cans = self.get_data('cans_available')
131 if starting_cans > 0: 134 if starting_cans > 0:
132 can = FullCan("full_can") 135 can = FullCan("full_can")
133 self.game.add_item(can) 136 self.game.add_item(can)
134 self.game.add_inventory_item(can.name) 137 self.game.add_inventory_item(can.name)
135 self.set_data('cans_available', starting_cans - 1) 138 self.set_data('cans_available', starting_cans - 1)
136 self.set_interact('%icans' % (starting_cans - 1)) 139 self.set_interact()
137 if starting_cans == 1: 140 if starting_cans == 1:
138 self.scene.remove_thing(self) 141 self.scene.remove_thing(self)
139 return Result({ 142 return Result({
140 3: "Best before a long time in the past." 143 3: "Best before a long time in the past."
141 " Better not eat these.", 144 " Better not eat these.",
176 return ("The pipes have been repaired but are the repairs" 179 return ("The pipes have been repaired but are the repairs"
177 " aren't airtight, yet") 180 " aren't airtight, yet")
178 else: 181 else:
179 return "Your fix looks like it's holding up well." 182 return "Your fix looks like it's holding up well."
180 183
184 def select_interact(self):
185 return self.get_data('status')
186
181 def interact_with_machete(self, item): 187 def interact_with_machete(self, item):
182 if self.get_data("status") == "blocked": 188 if self.get_data("status") == "blocked":
183 self.set_data("status", "broken") 189 self.set_data("status", "broken")
184 self.set_interact("broken") 190 self.set_interact()
185 return Result("With a flurry of disgusting mutant vegetable " 191 return Result("With a flurry of disgusting mutant vegetable "
186 "chunks, you clear the overgrown broccoli away from " 192 "chunks, you clear the overgrown broccoli away from "
187 "the access panel and reveal some broken tubes. " 193 "the access panel and reveal some broken tubes. "
188 "They look important.", 194 "They look important.",
189 soundfile='chopping.ogg') 195 soundfile='chopping.ogg')
199 if self.get_data("status") == "blocked": 205 if self.get_data("status") == "blocked":
200 return Result("It would get lost in the fronds.") 206 return Result("It would get lost in the fronds.")
201 else: 207 else:
202 self.game.remove_inventory_item(item.name) 208 self.game.remove_inventory_item(item.name)
203 self.set_data('status', 'replaced') 209 self.set_data('status', 'replaced')
204 self.set_interact("replaced") 210 self.set_interact()
205 self.scene.set_data('life support status', 'replaced') 211 self.scene.set_data('life support status', 'replaced')
206 return Result("The pipes slot neatly into place, but don't make" 212 return Result("The pipes slot neatly into place, but don't make"
207 " an airtight seal. One of the pipes has cracked" 213 " an airtight seal. One of the pipes has cracked"
208 " slightly as well.") 214 " slightly as well.")
209 215
213 elif self.get_data("status") == 'fixed': 219 elif self.get_data("status") == 'fixed':
214 return Result("There's quite enough tape on the ducting already.") 220 return Result("There's quite enough tape on the ducting already.")
215 else: 221 else:
216 self.set_data("fixed", True) 222 self.set_data("fixed", True)
217 self.set_data("status", "fixed") 223 self.set_data("status", "fixed")
218 self.set_interact("fixed") 224 self.set_interact()
219 self.scene.set_data('life support status', 'fixed') 225 self.scene.set_data('life support status', 'fixed')
220 return Result("It takes quite a lot of tape, but eventually" 226 return Result("It takes quite a lot of tape, but eventually"
221 "everything is airtight and ready to hold pressure." 227 "everything is airtight and ready to hold pressure."
222 " Who'd've thought duct tape could actually be used" 228 " Who'd've thought duct tape could actually be used"
223 " to tape ducts?") 229 " to tape ducts?")
261 def animate(self): 267 def animate(self):
262 hiss = self.game.gd.sound.get_sound(self.HISS) 268 hiss = self.game.gd.sound.get_sound(self.HISS)
263 if self.get_data('anim_pos') > -1: 269 if self.get_data('anim_pos') > -1:
264 self.current_interact.animate() 270 self.current_interact.animate()
265 if self.get_data('anim_pos') > self.current_interact._anim_pos: 271 if self.get_data('anim_pos') > self.current_interact._anim_pos:
266 self.set_interact('no_snake') 272 self._set_interact('no_snake')
267 self.set_data('anim_pos', -1) 273 self.set_data('anim_pos', -1)
268 else: 274 else:
269 self.set_data('anim_pos', self.current_interact._anim_pos) 275 self.set_data('anim_pos', self.current_interact._anim_pos)
270 return True 276 return True
271 if randint(0, 30 * self.game.gd.constants.frame_rate) == 0: 277 if randint(0, 30 * self.game.gd.constants.frame_rate) == 0:
272 self.set_interact('snake') 278 self._set_interact('snake')
273 self.set_data('anim_pos', 0) 279 self.set_data('anim_pos', 0)
274 hiss.play() 280 hiss.play()
275 return False 281 return False
276 282
277 283
288 INITIAL = 'present' 294 INITIAL = 'present'
289 295
290 INITIAL_DATA = { 296 INITIAL_DATA = {
291 'taken': False, 297 'taken': False,
292 } 298 }
299
300 def select_interact(self):
301 if self.get_data('taken'):
302 return 'taken'
303 return self.INITIAL
293 304
294 def interact_without(self): 305 def interact_without(self):
295 if self.get_data('taken'): 306 if self.get_data('taken'):
296 return Result("The remaining bottles leak.") 307 return Result("The remaining bottles leak.")
297 self.set_data('taken', True) 308 self.set_data('taken', True)
298 self.set_interact('taken') 309 self.set_interact()
299 self.game.add_inventory_item('detergent_bottle') 310 self.game.add_inventory_item('detergent_bottle')
300 return Result("You pick up an empty dishwashing liquid bottle. You" 311 return Result("You pick up an empty dishwashing liquid bottle. You"
301 " can't find any sponges.") 312 " can't find any sponges.")
302 313
303 def get_description(self): 314 def get_description(self):