changeset 130:11afefc4aeaf

InteractText for mocking up scenes. Allow backgrounds to be None. Mock up map.
author Simon Cross <hodgestar+bzr@gmail.com>
date Tue, 24 Aug 2010 18:38:44 +0200
parents 4223d66d88b4
children 97c5ff0a05bb
files gamelib/scenes/map.py gamelib/state.py
diffstat 2 files changed, 95 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/scenes/map.py	Tue Aug 24 18:36:31 2010 +0200
+++ b/gamelib/scenes/map.py	Tue Aug 24 18:38:44 2010 +0200
@@ -7,7 +7,7 @@
    Many parts of the ship are derelict and inaccessible.
    """
 
-from gamelib.state import Scene, Item, Thing
+from gamelib.state import Scene, Item, Thing, InteractText
 
 
 class Map(Scene):
@@ -19,5 +19,73 @@
         'accessible': True,
         }
 
+    def __init__(self, state):
+        super(Map, self).__init__(state)
+        self.add_thing(ToCryo())
+        self.add_thing(ToBridge())
+        self.add_thing(ToMess())
+        self.add_thing(ToEngine())
+        self.add_thing(ToMachine())
+
+
+class ToCryo(Thing):
+    "Way to cryo room."
+
+    NAME = "map.tocryo"
+
+    INTERACTS = {
+        "room": InteractText(100, 200, "To Cryo"),
+        }
+
+    INITIAL = "room"
+
+
+class ToBridge(Thing):
+    "Way to bridge room."
+
+    NAME = "map.tobridge"
+
+    INTERACTS = {
+        "room": InteractText(300, 200, "To Bridge"),
+        }
+
+    INITIAL = "room"
+
+
+class ToMess(Thing):
+    "Way to cryo room."
+
+    NAME = "map.tomess"
+
+    INTERACTS = {
+        "room": InteractText(100, 300, "To Mess"),
+        }
+
+    INITIAL = "room"
+
+
+class ToEngine(Thing):
+    "Way to engine room."
+
+    NAME = "map.toengine"
+
+    INTERACTS = {
+        "room": InteractText(300, 300, "To Engine"),
+        }
+
+    INITIAL = "room"
+
+
+class ToMachine(Thing):
+    "Way to machine room."
+
+    NAME = "map.tomachine"
+
+    INTERACTS = {
+        "room": InteractText(100, 400, "To Machine"),
+        }
+
+    INITIAL = "room"
+
 
 SCENES = [Map]
--- a/gamelib/state.py	Tue Aug 24 18:36:31 2010 +0200
+++ b/gamelib/state.py	Tue Aug 24 18:38:44 2010 +0200
@@ -5,6 +5,7 @@
 from widgets import BoomLabel, MessageDialog
 from pygame.locals import BLEND_ADD
 from pygame.rect import Rect
+from pygame.surface import Surface
 from pygame.color import Color
 
 import constants
@@ -40,7 +41,7 @@
     #state.load_scenes("mess")
     #state.load_scenes("engine")
     #state.load_scenes("machine")
-    #state.load_scenes("map")
+    state.load_scenes("map")
     state.set_current_scene("cryo")
     state.set_do_enter_leave()
     return state
@@ -214,7 +215,10 @@
         self.state = state
         # map of thing names -> Thing objects
         self.things = {}
-        self._background = get_image(self.FOLDER, self.BACKGROUND)
+        if self.BACKGROUND is not None:
+            self._background = get_image(self.FOLDER, self.BACKGROUND)
+        else:
+            self._background = None
         self._current_thing = None
         self._current_description = None
 
@@ -246,7 +250,10 @@
             self._current_description.draw_all(sub)
 
     def draw_background(self, surface):
-        surface.blit(self._background, (0, 0), None)
+        if self._background is not None:
+            surface.blit(self._background, (0, 0), None)
+        else:
+            surface.fill((200, 200, 200))
 
     def draw_things(self, surface):
         for thing in self.things.itervalues():
@@ -339,6 +346,22 @@
         super(InteractNoImage, self).__init__(None, None, Rect(x, y, w, h))
 
 
+class InteractText(Interact):
+    """Display box with text to interact with -- mostly for debugging."""
+
+    def __init__(self, x, y, text):
+        label = BoomLabel(text)
+        label.set_margin(5)
+        label.border_width = 1
+        label.border_color = (0, 0, 0)
+        label.bg_color = (127, 127, 127)
+        label.fg_color = (0, 0, 0)
+        image = Surface(label.size)
+        rect = Rect((x, y), label.size)
+        label.draw_all(image)
+        super(InteractText, self).__init__(image, rect, rect)
+
+
 class InteractRectUnion(Interact):
 
     def __init__(self, rect_list):