Mercurial > boomslang
diff gamelib/scenes/game_widgets.py @ 525:821b322e903b
Separate "scene widgets" from "game-specific widgets".
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Wed, 08 Sep 2010 14:02:11 +0200 |
parents | gamelib/scenes/scene_widgets.py@8f3c82c685a4 |
children | f79d1d3df8e8 2f1952748cdb |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gamelib/scenes/game_widgets.py Wed Sep 08 14:02:11 2010 +0200 @@ -0,0 +1,72 @@ +"""Generic, game specific widgets""" + + +from gamelib.state import Thing, Result + + +class Door(Thing): + """A door somewhere""" + + DEST = "map" + SCENE = None + + def __init__(self): + self.NAME = self.SCENE + '.door' + Thing.__init__(self) + + def is_interactive(self, tool=None): + return True + + def interact_without(self): + """Go to map.""" + self.state.set_current_scene("map") + + def get_description(self): + return 'An open doorway leads to the rest of the ship.' + + def interact_default(self, item): + return self.interact_without() + + +def make_jim_dialog(mesg, state): + "Utility helper function" + if state.scenes['bridge'].get_data('ai status') == 'online': + return Result(mesg, style='JIM') + else: + return None + + +class BaseCamera(Thing): + "Base class for the camera puzzles" + + INITIAL = 'online' + INITIAL_DATA = { + 'state': 'online', + } + + def get_description(self): + status = self.state.scenes['bridge'].get_data('ai status') + if status == 'online': + return "A security camera watches over the room" + elif status == 'looping': + return "The security camera is currently offline but should be working soon" + else: + return "The security camera is powered down" + + def is_interactive(self, tool=None): + return self.state.scenes['bridge'].get_data('ai status') == 'online' + + def interact_with_escher_poster(self, item): + # Order matters here, because of helper function + if self.state.scenes['bridge'].get_data('ai status') == 'online': + ai_response = make_jim_dialog("3D scene reconstruction failed. Critical error. Entering emergency shutdown.", self.state) + self.state.scenes['bridge'].set_data('ai status', 'looping') + return ai_response + + def animate(self): + ai_status = self.state.scenes['bridge'].get_data('ai status') + if ai_status != self.get_data('status'): + self.set_data('status', ai_status) + self.set_interact(ai_status) + super(BaseCamera, self).animate() +