Mercurial > nagslang
comparison nagslang/game_object.py @ 145:0c49627920eb
Load game objects from level.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Mon, 02 Sep 2013 23:05:25 +0200 |
parents | deac6a4008e7 |
children | b455873020be |
comparison
equal
deleted
inserted
replaced
144:829c8b6e142d | 145:0c49627920eb |
---|---|
14 """ | 14 """ |
15 def __init__(self): | 15 def __init__(self): |
16 self._components = {} | 16 self._components = {} |
17 | 17 |
18 def add_component(self, name, puzzler): | 18 def add_component(self, name, puzzler): |
19 if not isinstance(puzzler, Puzzler): | |
20 puzzler = puzzler.puzzler | |
19 self._components[name] = puzzler | 21 self._components[name] = puzzler |
20 puzzler.set_glue(self) | 22 puzzler.set_glue(self) |
21 | 23 |
22 def get_state_of(self, name): | 24 def get_state_of(self, name): |
23 return self._components[name].get_state() | 25 return self._components[name].get_state() |
274 return pymunk.Body.update_velocity(body, gravity, damping, dt) | 276 return pymunk.Body.update_velocity(body, gravity, damping, dt) |
275 | 277 |
276 | 278 |
277 def make_body(mass, moment, position, damping=None): | 279 def make_body(mass, moment, position, damping=None): |
278 body = pymunk.Body(mass, moment) | 280 body = pymunk.Body(mass, moment) |
279 body.position = position | 281 body.position = tuple(position) |
280 if damping is not None: | 282 if damping is not None: |
281 body.damping = damping | 283 body.damping = damping |
282 body.velocity_func = damping_velocity_func | 284 body.velocity_func = damping_velocity_func |
283 return body | 285 return body |
284 | 286 |
319 self.renderer.animate() | 321 self.renderer.animate() |
320 | 322 |
321 | 323 |
322 class FloorSwitch(GameObject): | 324 class FloorSwitch(GameObject): |
323 def __init__(self, space, position): | 325 def __init__(self, space, position): |
324 body = pymunk.Body() | 326 body = make_body(None, None, position) |
325 body.position = position | |
326 self.shape = pymunk.Circle(body, 30) | 327 self.shape = pymunk.Circle(body, 30) |
327 self.shape.collision_type = COLLISION_TYPE_SWITCH | 328 self.shape.collision_type = COLLISION_TYPE_SWITCH |
328 self.shape.sensor = True | 329 self.shape.sensor = True |
329 super(FloorSwitch, self).__init__( | 330 super(FloorSwitch, self).__init__( |
330 SingleShapePhysicser(space, self.shape), | 331 SingleShapePhysicser(space, self.shape), |
333 ) | 334 ) |
334 | 335 |
335 | 336 |
336 class FloorLight(GameObject): | 337 class FloorLight(GameObject): |
337 def __init__(self, space, position, state_source): | 338 def __init__(self, space, position, state_source): |
338 body = pymunk.Body() | 339 body = make_body(None, None, position) |
339 body.position = position | |
340 self.shape = pymunk.Circle(body, 10) | 340 self.shape = pymunk.Circle(body, 10) |
341 self.shape.collision_type = COLLISION_TYPE_SWITCH | 341 self.shape.collision_type = COLLISION_TYPE_SWITCH |
342 self.shape.sensor = True | 342 self.shape.sensor = True |
343 super(FloorLight, self).__init__( | 343 super(FloorLight, self).__init__( |
344 SingleShapePhysicser(space, self.shape), | 344 SingleShapePhysicser(space, self.shape), |