# HG changeset patch # User Jeremy Thurgood # Date 1282517362 -7200 # Node ID ad6f56bfa8b777d05302b8b15897b6c3dfa4fbba # Parent 9fdbfbc02a60c375d5c1151a8a03fd0375190bb3 Cryo door, titanium leg and some interaction prototypes. diff -r 9fdbfbc02a60 -r ad6f56bfa8b7 Resources/images/items/titanium_leg.png Binary file Resources/images/items/titanium_leg.png has changed diff -r 9fdbfbc02a60 -r ad6f56bfa8b7 gamelib/gamescreen.py --- a/gamelib/gamescreen.py Sun Aug 22 22:09:59 2010 +0200 +++ b/gamelib/gamescreen.py Mon Aug 23 00:49:22 2010 +0200 @@ -1,4 +1,4 @@ -# menu.py +# gamescreen.py # Copyright Boomslang team, 2010 (see COPYING File) # Main menu for the game @@ -71,6 +71,9 @@ StartButton, QuitButton, AddItemButton, + Button('Use hand', action = lambda: self.state.scenes['cryo'].things['cryo.door'].interact(None)), + Button('Use triangle', action = lambda: self.state.scenes['cryo'].things['cryo.door'].interact(self.state.items['triangle'])), + Button('Use titanium_leg', action = lambda: self.state.scenes['cryo'].things['cryo.door'].interact(self.state.items['titanium_leg'])), ], align='l', spacing=20) self.add_centered(menu) self.menubutton = Button('M', action=self.main_menu) @@ -88,7 +91,7 @@ # Test items self.state.add_inventory_item('triangle') - self.state.add_inventory_item('square') + self.state.add_inventory_item('titanium_leg') def main_menu(self): print 'Returning to menu' diff -r 9fdbfbc02a60 -r ad6f56bfa8b7 gamelib/scenes/cryo.py --- a/gamelib/scenes/cryo.py Sun Aug 22 22:09:59 2010 +0200 +++ b/gamelib/scenes/cryo.py Mon Aug 23 00:49:22 2010 +0200 @@ -1,5 +1,7 @@ """Cryo room where the prisoner starts out.""" +import random + from gamelib.state import Scene, Item, Thing @@ -8,23 +10,53 @@ FOLDER = "cryo" BACKGROUND = "cryo_room.png" + INITIAL_DATA = { + 'accessible': True, + } + def __init__(self, state): super(Cryo, self).__init__(state) self.add_item(Triangle("triangle")) - self.add_item(Square("square")) + self.add_item(TitaniumLeg("titanium_leg")) self.add_thing(CryoUnitAlpha("cryo.unit.1", (20, 20, 400, 500))) + self.add_thing(CryoRoomDoor("cryo.door", (30, 30, 400, 300))) class Triangle(Item): + "Test item. Needs to go away at some point." + INVENTORY_IMAGE = "triangle.png" -class Square(Item): - INVENTORY_IMAGE = "square.png" +class TitaniumLeg(Item): + "Titanium leg, found on a piratical corpse." + + INVENTORY_IMAGE = "titanium_leg.png" class CryoUnitAlpha(Thing): pass +class CryoRoomDoor(Thing): + "Door to the cryo room." + + FOLDER = "cryo" + IMAGE = "cryo_door_closed" + + def interact_with_titanium_leg(self, item): + self.message("You wedge the titanium leg into the chain and twist. With a satisfying *snap*, the chain breaks and the door opens.") + self.scene.remove_thing(self) + + def interact_without(self): + self.message("It moves slightly and then stops. A chain on the other side is preventing it from opening completely.") + + def interact_default(self, item): + self.message(random.choice([ + "Sadly, this isn't that sort of game.", + "Your valiant efforts are foiled by the Evil Game Designer.", + "The door resists. Try something else, perhaps?", + ])) + + SCENES = [Cryo] diff -r 9fdbfbc02a60 -r ad6f56bfa8b7 gamelib/state.py --- a/gamelib/state.py Sun Aug 22 22:09:59 2010 +0200 +++ b/gamelib/state.py Mon Aug 23 00:49:22 2010 +0200 @@ -54,6 +54,9 @@ def draw(self, surface): self.current_scene.draw(surface) + def message(self, msg): + print msg + class Scene(object): """Base class for scenes.""" @@ -67,6 +70,9 @@ # name of scene (optional, defaults to folder) NAME = None + # initial scene data (optional, defaults to none) + INITIAL_DATA = None + def __init__(self, state): # scene name self.name = self.NAME if self.NAME is not None else self.FOLDER @@ -75,12 +81,19 @@ # map of thing names -> Thing objects self.things = {} self._background = get_image(self.FOLDER, self.BACKGROUND) + self.data = {} + if self.INITIAL_DATA: + self.data.update(self.INITIAL_DATA) def add_item(self, item): self.state.add_item(item) def add_thing(self, thing): self.things[thing.name] = thing + thing.set_scene(self) + + def remove_thing(self, thing): + del self.things[thing.name] def draw_background(self, surface): surface.blit(self._background, (0, 0), None, BLEND_ADD) @@ -97,6 +110,12 @@ class Thing(object): """Base class for things in a scene that you can interact with.""" + # sub-folder to look for resources in + FOLDER = None + + # name of image resource + IMAGE = None + def __init__(self, name, rect): self.name = name # area within scene that triggers calls to interact @@ -112,8 +131,24 @@ self.scene = scene self.state = scene.state + def message(self, msg): + self.state.message(msg) + def interact(self, item): - pass + if item is None: + self.interact_without() + else: + handler = getattr(self, 'interact_with_' + item.name, None) + if handler is not None: + handler(item) + else: + self.interact_default(item) + + def interact_without(self): + self.interact_default(None) + + def interact_default(self, item): + self.message("It doesn't work.") def draw(self, surface): pass