comparison gamelib/state.py @ 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 686bb74a52f8
comparison
equal deleted inserted replaced
129:4223d66d88b4 130:11afefc4aeaf
3 from albow.resource import get_image 3 from albow.resource import get_image
4 from albow.utils import frame_rect 4 from albow.utils import frame_rect
5 from widgets import BoomLabel, MessageDialog 5 from widgets import BoomLabel, MessageDialog
6 from pygame.locals import BLEND_ADD 6 from pygame.locals import BLEND_ADD
7 from pygame.rect import Rect 7 from pygame.rect import Rect
8 from pygame.surface import Surface
8 from pygame.color import Color 9 from pygame.color import Color
9 10
10 import constants 11 import constants
11 from sound import get_sound 12 from sound import get_sound
12 from cursor import HAND 13 from cursor import HAND
38 state.load_scenes("cryo") 39 state.load_scenes("cryo")
39 state.load_scenes("bridge") 40 state.load_scenes("bridge")
40 #state.load_scenes("mess") 41 #state.load_scenes("mess")
41 #state.load_scenes("engine") 42 #state.load_scenes("engine")
42 #state.load_scenes("machine") 43 #state.load_scenes("machine")
43 #state.load_scenes("map") 44 state.load_scenes("map")
44 state.set_current_scene("cryo") 45 state.set_current_scene("cryo")
45 state.set_do_enter_leave() 46 state.set_do_enter_leave()
46 return state 47 return state
47 48
48 49
212 self.name = self.NAME if self.NAME is not None else self.FOLDER 213 self.name = self.NAME if self.NAME is not None else self.FOLDER
213 # link back to state object 214 # link back to state object
214 self.state = state 215 self.state = state
215 # map of thing names -> Thing objects 216 # map of thing names -> Thing objects
216 self.things = {} 217 self.things = {}
217 self._background = get_image(self.FOLDER, self.BACKGROUND) 218 if self.BACKGROUND is not None:
219 self._background = get_image(self.FOLDER, self.BACKGROUND)
220 else:
221 self._background = None
218 self._current_thing = None 222 self._current_thing = None
219 self._current_description = None 223 self._current_description = None
220 224
221 def add_item(self, item): 225 def add_item(self, item):
222 self.state.add_item(item) 226 self.state.add_item(item)
244 sub = surface.subsurface( 248 sub = surface.subsurface(
245 Rect(5, 5, *self._current_description.size)) 249 Rect(5, 5, *self._current_description.size))
246 self._current_description.draw_all(sub) 250 self._current_description.draw_all(sub)
247 251
248 def draw_background(self, surface): 252 def draw_background(self, surface):
249 surface.blit(self._background, (0, 0), None) 253 if self._background is not None:
254 surface.blit(self._background, (0, 0), None)
255 else:
256 surface.fill((200, 200, 200))
250 257
251 def draw_things(self, surface): 258 def draw_things(self, surface):
252 for thing in self.things.itervalues(): 259 for thing in self.things.itervalues():
253 thing.draw(surface) 260 thing.draw(surface)
254 261
337 344
338 def __init__(self, x, y, w, h): 345 def __init__(self, x, y, w, h):
339 super(InteractNoImage, self).__init__(None, None, Rect(x, y, w, h)) 346 super(InteractNoImage, self).__init__(None, None, Rect(x, y, w, h))
340 347
341 348
349 class InteractText(Interact):
350 """Display box with text to interact with -- mostly for debugging."""
351
352 def __init__(self, x, y, text):
353 label = BoomLabel(text)
354 label.set_margin(5)
355 label.border_width = 1
356 label.border_color = (0, 0, 0)
357 label.bg_color = (127, 127, 127)
358 label.fg_color = (0, 0, 0)
359 image = Surface(label.size)
360 rect = Rect((x, y), label.size)
361 label.draw_all(image)
362 super(InteractText, self).__init__(image, rect, rect)
363
364
342 class InteractRectUnion(Interact): 365 class InteractRectUnion(Interact):
343 366
344 def __init__(self, rect_list): 367 def __init__(self, rect_list):
345 # pygame.rect.Rect.unionall should do this, but is broken 368 # pygame.rect.Rect.unionall should do this, but is broken
346 # in some pygame versions (including 1.8, it appears) 369 # in some pygame versions (including 1.8, it appears)