comparison gamelib/state.py @ 68:158a13a48d48

Show interact rectangles when constants.DEBUG is True.
author Simon Cross <hodgestar+bzr@gmail.com>
date Mon, 23 Aug 2010 20:34:38 +0200
parents cab924519037
children 99c5506de7ea
comparison
equal deleted inserted replaced
67:6b0f7364f3bf 68:158a13a48d48
1 """Utilities and base classes for dealing with scenes.""" 1 """Utilities and base classes for dealing with scenes."""
2 2
3 from albow.resource import get_image, get_sound 3 from albow.resource import get_image, get_sound
4 from albow.utils import frame_rect
4 from pygame.locals import BLEND_ADD 5 from pygame.locals import BLEND_ADD
5 from pygame.rect import Rect 6 from pygame.rect import Rect
7 from pygame.color import Color
8
9 import constants
6 10
7 11
8 def initial_state(): 12 def initial_state():
9 """Load the initial state.""" 13 """Load the initial state."""
10 state = State() 14 state = State()
160 FOLDER = None 164 FOLDER = None
161 165
162 # name of image resource 166 # name of image resource
163 IMAGE = None 167 IMAGE = None
164 168
169 # Interact rectangle hi-light color (for debugging)
170 # (set to None to turn off)
171 if constants.DEBUG:
172 _interact_hilight_color = Color('Red')
173 else:
174 _interact_hilight_color = None
175
165 def __init__(self, name, rect): 176 def __init__(self, name, rect):
166 StatefulGizmo.__init__(self) 177 StatefulGizmo.__init__(self)
167 self.name = name 178 self.name = name
179 # area within scene to render to
180 self.rect = Rect(rect)
168 # area within scene that triggers calls to interact 181 # area within scene that triggers calls to interact
169 self.rect = rect 182 self.interact_rect = Rect(rect)
170 # these are set by set_scene 183 # these are set by set_scene
171 self.scene = None 184 self.scene = None
172 self.state = None 185 self.state = None
173 # TODO: add masks 186 # TODO: add masks
174 # TODO: add images 187 # TODO: add images
204 217
205 def interact_default(self, item): 218 def interact_default(self, item):
206 self.message("It doesn't work.") 219 self.message("It doesn't work.")
207 220
208 def draw(self, surface): 221 def draw(self, surface):
209 pass 222 if self._interact_hilight_color is not None:
223 frame_rect(surface, self._interact_hilight_color,
224 self.interact_rect.inflate(1, 1), 1)
225 # TODO: draw image if there is one
210 226
211 227
212 class Item(object): 228 class Item(object):
213 """Base class for inventory items.""" 229 """Base class for inventory items."""
214 230