comparison gamelib/scenes/mess.py @ 854:3577c51029f1 default tip

Remove Suspended Sentence. pyntnclick is the library we extracted from it
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 21 Jun 2014 22:15:54 +0200
parents f95830b58336
children
comparison
equal deleted inserted replaced
853:f95830b58336 854:3577c51029f1
1 """Mess where crew eat. Fun stuff."""
2
3 from random import randint
4
5 from pyntnclick.i18n import _
6 from pyntnclick.state import Scene, Item, CloneableItem, Thing, Result
7 from pyntnclick.cursor import CursorSprite
8 from pyntnclick.scenewidgets import (InteractNoImage, InteractImage,
9 InteractImageRect, InteractAnimated,
10 GenericDescThing)
11
12 from gamelib.scenes.game_constants import PLAYER_ID
13 from gamelib.scenes.game_widgets import Door
14
15
16 class Mess(Scene):
17
18 FOLDER = "mess"
19 BACKGROUND = "mess_hall.png"
20
21 INITIAL_DATA = {
22 'life support status': 'broken', # broken, replaced, fixed
23 }
24
25 def setup(self):
26 self.add_thing(CansOnShelf())
27 self.add_thing(Tubes())
28 self.add_thing(ToMap())
29 self.add_thing(DetergentThing())
30 self.add_thing(Boomslang())
31 self.add_item_factory(DetergentBottle)
32 self.add_item_factory(EmptyCan)
33 self.add_item_factory(FullCan)
34 self.add_item_factory(DentedCan)
35 # Flavour items
36 # extra cans on shelf
37 self.add_thing(GenericDescThing('mess.cans', 1,
38 _("A large collection of rusted, useless cans."),
39 (
40 (154, 335, 89, 106),
41 (152, 435, 63, 66),
42 )))
43 self.add_thing(GenericDescThing('mess.broccoli', 2,
44 _("An impressively overgrown broccoli."),
45 (
46 (503, 89, 245, 282),
47 (320, 324, 229, 142),
48 )))
49
50
51 class BaseCan(CloneableItem):
52 """Base class for the cans"""
53
54 MAX_COUNT = 3
55
56 def interact_with_full_can(self, item):
57 return Result(_("You bang the cans together. It sounds like two"
58 " cans being banged together."),
59 soundfile="can_hit.ogg")
60
61 def interact_with_dented_can(self, item):
62 return self.interact_with_full_can(item)
63
64 def interact_with_empty_can(self, item):
65 return self.interact_with_full_can(item)
66
67 def interact_with_machete(self, item):
68 return Result(_("You'd mangle it beyond usefulness."))
69
70 def interact_with_canopener(self, item):
71 self.game.replace_inventory_item(self.name, 'empty_can')
72 return Result(_("You open both ends of the can, discarding the"
73 " hideous contents."))
74
75
76 class EmptyCan(BaseCan):
77 "After emptying the full can."
78
79 NAME = 'empty_can'
80 INVENTORY_IMAGE = "empty_can.png"
81 CURSOR = CursorSprite('empty_can_cursor.png')
82
83 def interact_with_titanium_leg(self, item):
84 return Result(_("Flattening the can doesn't look like a useful"
85 " thing to do."))
86
87 def interact_with_canopener(self, item):
88 return Result(_("There's nothing left to open on this can"))
89
90
91 class FullCan(BaseCan):
92 "Found on the shelf."
93
94 NAME = 'full_can'
95 INVENTORY_IMAGE = "full_can.png"
96 CURSOR = CursorSprite('full_can_cursor.png')
97
98 def interact_with_titanium_leg(self, item):
99 self.game.replace_inventory_item(self.name, 'dented_can')
100 return Result(_("You club the can with the femur. The can gets dented,"
101 " but doesn't open."), soundfile="can_hit.ogg")
102
103
104 class DentedCan(BaseCan):
105 "A can banged on with the femur"
106
107 NAME = 'dented_can'
108 INVENTORY_IMAGE = "dented_can.png"
109 CURSOR = CursorSprite('dented_can_cursor.png')
110
111 def interact_with_titanium_leg(self, item):
112 return Result(_("You club the can with the femur. The dents shift"
113 " around, but it still doesn't open."),
114 soundfile="can_hit.ogg")
115
116
117 class CansOnShelf(Thing):
118
119 NAME = "mess.cans"
120
121 INTERACTS = {
122 '3cans': InteractImage(165, 209, 'shelf_3_cans.png'),
123 '2cans': InteractImage(165, 209, 'shelf_2_cans.png'),
124 '1cans': InteractImage(165, 209, 'shelf_1_can.png'),
125 '0cans': InteractNoImage(165, 209, 50, 50),
126 }
127
128 INITIAL = '3cans'
129
130 INITIAL_DATA = {
131 'cans_available': 3,
132 }
133
134 def should_add(self):
135 return self.get_data('cans_available') > 0
136
137 def select_interact(self):
138 return '%icans' % (self.get_data('cans_available'),)
139
140 def interact_without(self):
141 starting_cans = self.get_data('cans_available')
142 if starting_cans > 0:
143 self.game.add_inventory_item('full_can')
144 self.set_data('cans_available', starting_cans - 1)
145 self.set_interact()
146 if starting_cans == 1:
147 self.scene.remove_thing(self)
148 return Result({
149 3: _("Best before a long time in the past."
150 " Better not eat these."),
151 2: _("Mmmm. Nutritious bacteria stew."),
152 1: _("Candied silkworms. Who stocked this place?!"),
153 }[starting_cans])
154 else:
155 return Result(_("The rest of the cans are rusted beyond "
156 "usefulness."))
157
158 def get_description(self):
159 return _("The contents of these cans look synthetic.")
160
161
162 class Tubes(Thing):
163
164 NAME = "mess.tubes"
165
166 INTERACTS = {
167 "blocked": InteractImage(250, 130, "blocking_broccoli.png"),
168 "broken": InteractImage(250, 183, "broken_tubes.png"),
169 "replaced": InteractImage(250, 183, "replaced_tubes.png"),
170 "fixed": InteractImage(252, 183, "fixed_tubes.png"),
171 }
172
173 INITIAL = "blocked"
174
175 INITIAL_DATA = {
176 "status": "blocked",
177 }
178
179 def get_description(self):
180 if self.get_data('status') == "blocked":
181 return _("The broccoli seems to have become"
182 " entangled with something.")
183 elif self.get_data("status") == "broken":
184 return _("These broken pipes look important.")
185 elif self.get_data("status") == "replaced":
186 return _("The pipes have been repaired but are the repairs"
187 " aren't airtight, yet")
188 else:
189 return _("Your fix looks like it's holding up well.")
190
191 def select_interact(self):
192 return self.get_data('status')
193
194 def interact_with_machete(self, item):
195 if self.get_data("status") == "blocked":
196 self.set_data("status", "broken")
197 self.set_interact()
198 return Result(_("With a flurry of disgusting mutant vegetable "
199 "chunks, you clear the overgrown broccoli away "
200 "from the access panel and reveal some broken "
201 "tubes. They look important."),
202 soundfile='chopping.ogg')
203 elif self.get_data("status") == "broken":
204 return Result(_("It looks broken enough already."))
205 elif self.get_data("status") == "replaced":
206 return Result(_("Cutting holes won't repair the leaks."))
207 else:
208 return Result(_("After all that effort fixing it, chopping it to "
209 "bits doesn't seem very smart."))
210
211 def interact_with_cryo_pipes_three(self, item):
212 if self.get_data("status") == "blocked":
213 return Result(_("It would get lost in the fronds."))
214 else:
215 self.game.remove_inventory_item(item.name)
216 self.set_data('status', 'replaced')
217 self.set_interact()
218 self.scene.set_data('life support status', 'replaced')
219 return Result(_("The pipes slot neatly into place, but don't make"
220 " an airtight seal. One of the pipes has cracked"
221 " slightly as well."))
222
223 def interact_with_duct_tape(self, item):
224 if self.get_data("status") == "broken":
225 return Result(_("It would get lost in the fronds."))
226 elif self.get_data("status") == 'fixed':
227 return Result(
228 _("There's quite enough tape on the ducting already."))
229 else:
230 self.set_data("fixed", True)
231 self.set_data("status", "fixed")
232 self.set_interact()
233 self.scene.set_data('life support status', 'fixed')
234 return Result(_("It takes quite a lot of tape, but eventually "
235 "everything is airtight and ready to hold "
236 "pressure. Who'd've thought duct tape could "
237 "actually be used to tape ducts?"))
238
239 def interact_without(self):
240 if self.get_data("status") == "blocked":
241 return Result(_("The mutant broccoli resists your best efforts."))
242 elif self.get_data("status") == "broken":
243 return Result(_("Shoving the broken pipes around doesn't help "
244 "much."))
245 elif self.get_data("status") == "replaced":
246 return Result(_("Do you really want to hold it together for the "
247 "rest of the voyage?"))
248 else:
249 return Result(_("You don't find any leaks. Good job, Prisoner %s.")
250 % PLAYER_ID)
251
252
253 class Boomslang(Thing):
254 NAME = 'mess.boomslang'
255
256 INTERACTS = {
257 'snake': InteractAnimated(455, 241, (
258 'boomslang_no_tongue.png', 'boomslang_with_tongue.png',
259 'boomslang_no_tongue.png', 'boomslang_with_tongue.png',
260 'boomslang_no_tongue.png',
261 ), 5),
262 'no_snake': InteractNoImage(0, 0, 0, 0),
263 }
264
265 INITIAL = 'no_snake'
266
267 INITIAL_DATA = {
268 'anim_pos': -1,
269 }
270
271 HISS = 'boomslang.ogg'
272
273 def is_interactive(self, tool=None):
274 return False
275
276 def animate(self):
277 hiss = self.game.gd.sound.get_sound(self.HISS)
278 if self.get_data('anim_pos') > -1:
279 self.current_interact.animate()
280 if self.get_data('anim_pos') > self.current_interact._anim_pos:
281 self._set_interact('no_snake')
282 self.set_data('anim_pos', -1)
283 else:
284 self.set_data('anim_pos', self.current_interact._anim_pos)
285 return True
286 if randint(0, 30 * self.game.gd.constants.frame_rate) == 0:
287 self._set_interact('snake')
288 self.set_data('anim_pos', 0)
289 hiss.play()
290 return False
291
292
293 class DetergentThing(Thing):
294
295 NAME = "mess.detergent"
296
297 INTERACTS = {
298 'present': InteractImageRect(581, 424, 'detergent_lid.png',
299 565, 399, 62, 95),
300 'taken': InteractNoImage(565, 399, 62, 95),
301 }
302
303 INITIAL = 'present'
304
305 INITIAL_DATA = {
306 'taken': False,
307 }
308
309 def select_interact(self):
310 if self.get_data('taken'):
311 return 'taken'
312 return self.INITIAL
313
314 def interact_without(self):
315 if self.get_data('taken'):
316 return Result(_("The remaining bottles leak."))
317 self.set_data('taken', True)
318 self.set_interact()
319 self.game.add_inventory_item('detergent_bottle')
320 return Result(_("You pick up an empty dishwashing liquid bottle. You"
321 " can't find any sponges."))
322
323 def get_description(self):
324 return _("Empty plastic containers. "
325 "They used to hold dishwasher soap.")
326
327
328 class DetergentBottle(Item):
329 NAME = 'detergent_bottle'
330 INVENTORY_IMAGE = 'bottle_empty.png'
331 CURSOR = CursorSprite('bottle_empty_cursor.png', 27, 7)
332
333
334 class ToMap(Door):
335
336 SCENE = "mess"
337
338 INTERACTS = {
339 "door": InteractNoImage(20, 390, 85, 150),
340 }
341
342 INITIAL = "door"
343
344
345 SCENES = [Mess]