changeset 132:686bb74a52f8

Map shows accessible areas.
author Jeremy Thurgood <firxen@gmail.com>
date Tue, 24 Aug 2010 19:22:01 +0200
parents 97c5ff0a05bb
children 0530547a131f
files gamelib/scenes/map.py gamelib/state.py
diffstat 2 files changed, 35 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/scenes/map.py	Tue Aug 24 18:52:52 2010 +0200
+++ b/gamelib/scenes/map.py	Tue Aug 24 19:22:01 2010 +0200
@@ -27,6 +27,10 @@
         self.add_thing(ToEngine())
         self.add_thing(ToMachine())
 
+    def enter(self):
+        for door_thing in self.things.values():
+            door_thing.check_dest()
+
 
 class DoorThing(Thing):
 
@@ -36,9 +40,16 @@
     def interact_without(self):
         """Go to destination."""
         if self.DEST in self.state.scenes:
-            self.state.set_current_scene('bridge')
+            self.state.set_current_scene(self.DEST)
             return Result("You head for the %s." % self.DEST)
 
+    def check_dest(self):
+        if self.DEST in self.state.scenes:
+            if self.state.scenes[self.DEST].get_data('accessible'):
+                self.set_interact('accessible')
+            else:
+                self.set_interact('inaccessible')
+
 
 class ToCryo(DoorThing):
     "Way to cryo room."
@@ -47,10 +58,11 @@
     DEST = "cryo"
 
     INTERACTS = {
-        "room": InteractText(100, 200, "To Cryo"),
+        "inaccessible": InteractText(100, 200, "To Cryo"),
+        "accessible": InteractText(100, 200, "To Cryo", (0, 127, 0)),
         }
 
-    INITIAL = "room"
+    INITIAL = "inaccessible"
 
 
 class ToBridge(DoorThing):
@@ -60,10 +72,11 @@
     DEST = "bridge"
 
     INTERACTS = {
-        "room": InteractText(300, 200, "To Bridge"),
+        "inaccessible": InteractText(300, 200, "To Bridge"),
+        "accessible": InteractText(300, 200, "To Bridge", (0, 127, 0)),
         }
 
-    INITIAL = "room"
+    INITIAL = "inaccessible"
 
 
 class ToMess(DoorThing):
@@ -73,23 +86,25 @@
     DEST = "mess"
 
     INTERACTS = {
-        "room": InteractText(100, 300, "To Mess"),
+        "inaccessible": InteractText(100, 300, "To Mess"),
+        "accessible": InteractText(100, 300, "To Mess", (0, 127, 0)),
         }
 
-    INITIAL = "room"
+    INITIAL = "inaccessible"
 
 
-class ToEngine(Thing):
+class ToEngine(DoorThing):
     "Way to engine room."
 
     NAME = "map.toengine"
     DEST = "engine"
 
     INTERACTS = {
-        "room": InteractText(300, 300, "To Engine"),
+        "inaccessible": InteractText(300, 300, "To Engine"),
+        "accessible": InteractText(300, 300, "To Engine", (0, 127, 0)),
         }
 
-    INITIAL = "room"
+    INITIAL = "inaccessible"
 
 
 class ToMachine(DoorThing):
@@ -99,10 +114,11 @@
     DEST = "machine"
 
     INTERACTS = {
-        "room": InteractText(100, 400, "To Machine"),
+        "inaccessible": InteractText(100, 400, "To Machine"),
+        "accessible": InteractText(100, 400, "To Machine", (0, 127, 0)),
         }
 
-    INITIAL = "room"
+    INITIAL = "inaccessible"
 
 
 SCENES = [Map]
--- a/gamelib/state.py	Tue Aug 24 18:52:52 2010 +0200
+++ b/gamelib/state.py	Tue Aug 24 19:22:01 2010 +0200
@@ -38,9 +38,9 @@
     state = State(screen)
     state.load_scenes("cryo")
     state.load_scenes("bridge")
-    #state.load_scenes("mess")
-    #state.load_scenes("engine")
-    #state.load_scenes("machine")
+    state.load_scenes("mess")
+    # state.load_scenes("engine")
+    # state.load_scenes("machine")
     state.load_scenes("map")
     state.set_current_scene("cryo")
     state.set_do_enter_leave()
@@ -349,12 +349,14 @@
 class InteractText(Interact):
     """Display box with text to interact with -- mostly for debugging."""
 
-    def __init__(self, x, y, text):
+    def __init__(self, x, y, text, bg_color=None):
+        if bg_color is None:
+            bg_color = (127, 127, 127)
         label = BoomLabel(text)
         label.set_margin(5)
         label.border_width = 1
         label.border_color = (0, 0, 0)
-        label.bg_color = (127, 127, 127)
+        label.bg_color = bg_color
         label.fg_color = (0, 0, 0)
         image = Surface(label.size)
         rect = Rect((x, y), label.size)