source: nagslang/game_object.py@ 563:a68951a9fe40

Last change on this file since 563:a68951a9fe40 was 563:a68951a9fe40, checked in by David Sharpe <decoydavid@…>, 8 years ago

More Cargo bay.

File size: 25.2 KB
Line 
1import pymunk
2import pymunk.pygame_util
3
4import math
5
6from nagslang import environment
7from nagslang import puzzle
8from nagslang import render
9from nagslang.mutators import FLIP_H, ImageOverlay, rotator
10from nagslang.constants import (
11 COLLISION_TYPE_DOOR, COLLISION_TYPE_FURNITURE, COLLISION_TYPE_PROJECTILE,
12 COLLISION_TYPE_SWITCH, COLLISION_TYPE_SHEEP, COLLISION_TYPE_SHEEP_PEN,
13 COLLISION_TYPE_WEREWOLF_ATTACK, SWITCH_PUSHERS, ZORDER_FLOOR, ZORDER_LOW,
14 ZORDER_HIGH)
15from nagslang.resources import resources
16from nagslang.events import DoorEvent
17
18
19class Result(object):
20 '''
21 Return from an update() function, to add new objects to the world, and/or
22 remove old objects.
23 '''
24 def __init__(self, add=(), remove=()):
25 self.add = add
26 self.remove = remove
27
28 def merge(self, result):
29 if result is not None:
30 self.add += result.add
31 self.remove += result.remove
32 return self
33
34
35def get_editable_game_objects():
36 classes = []
37 for cls_name, cls in globals().iteritems():
38 if isinstance(cls, type) and hasattr(cls, 'requires'):
39 classes.append((cls_name, cls))
40 return classes
41
42
43class Physicser(object):
44 def __init__(self, space):
45 self._space = space
46
47 def get_space(self):
48 return self._space
49
50 def set_space(self, new_space):
51 self._space = new_space
52
53 def set_game_object(self, game_object):
54 self.game_object = game_object
55
56 def get_shape(self):
57 raise NotImplementedError()
58
59 def add_to_space(self):
60 shape = self.get_shape()
61 self.get_space().add(shape)
62 if not shape.body.is_static:
63 self.get_space().add(shape.body)
64
65 def remove_from_space(self):
66 shape = self.get_shape()
67 self.get_space().remove(shape)
68 if not shape.body.is_static:
69 self.get_space().remove(shape.body)
70
71 def get_render_position(self, surface):
72 pos = self.get_shape().body.position
73 return pymunk.pygame_util.to_pygame(pos, surface)
74
75 def get_angle(self):
76 return self.get_shape().body.angle
77
78 def get_velocity(self):
79 return self.get_shape().body.velocity
80
81 def _get_position(self):
82 return self.get_shape().body.position
83
84 def _set_position(self, position):
85 self.get_shape().body.position = position
86
87 position = property(_get_position, _set_position)
88
89 def apply_impulse(self, j, r=(0, 0)):
90 return self.get_shape().body.apply_impulse(j, r)
91
92
93class SingleShapePhysicser(Physicser):
94 def __init__(self, space, shape):
95 super(SingleShapePhysicser, self).__init__(space)
96 self._shape = shape
97 shape.physicser = self
98
99 def get_shape(self):
100 return self._shape
101
102
103class MultiShapePhysicser(Physicser):
104 def __init__(self, space, shape, *extra_shapes):
105 super(MultiShapePhysicser, self).__init__(space)
106 self._shape = shape
107 self._extra_shapes = extra_shapes
108 shape.physicser = self
109
110 def get_shape(self):
111 return self._shape
112
113 def add_to_space(self):
114 shape = self.get_shape()
115 self.get_space().add(shape)
116 if not shape.body.is_static:
117 self.get_space().add(shape.body)
118 for s in self._extra_shapes:
119 self.get_space().add(s)
120
121 def remove_from_space(self):
122 shape = self.get_shape()
123 self.get_space().remove(shape)
124 if not shape.body.is_static:
125 self.get_space().remove(shape.body)
126 for s in self._extra_shapes:
127 self.get_space().remove(s)
128
129
130def damping_velocity_func(body, gravity, damping, dt):
131 """Apply custom damping to this body's velocity.
132 """
133 damping = getattr(body, 'damping', damping)
134 return pymunk.Body.update_velocity(body, gravity, damping, dt)
135
136
137def make_body(mass, moment, position, damping=None):
138 body = pymunk.Body(mass, moment)
139 body.position = tuple(position)
140 if damping is not None:
141 body.damping = damping
142 body.velocity_func = damping_velocity_func
143 return body
144
145
146class GameObject(object):
147 """A representation of a thing in the game world.
148
149 This has a rendery thing, physicsy things and maybe some other things.
150 """
151
152 zorder = ZORDER_LOW
153 is_moving = False # `True` if a movement animation should play.
154
155 def __init__(self, physicser, renderer, puzzler=None, overlay=None,
156 interactible=None):
157 self.lifetime = 0
158 self.physicser = physicser
159 if physicser is not None:
160 physicser.set_game_object(self)
161 self.physicser.add_to_space()
162 self.renderer = renderer
163 renderer.set_game_object(self)
164 self.puzzler = puzzler
165 if puzzler is not None:
166 puzzler.set_game_object(self)
167 self.overlay = overlay
168 if overlay is not None:
169 self.overlay.set_game_object(self)
170 self.interactible = interactible
171 if interactible is not None:
172 self.interactible.set_game_object(self)
173 self._timers = {}
174 self._active_timers = {}
175
176 def add_timer(self, name, secs):
177 self._timers[name] = secs
178
179 def start_timer(self, name, secs=None):
180 if secs is None:
181 secs = self._timers[name]
182 self._active_timers[name] = secs
183
184 def check_timer(self, name):
185 return name in self._active_timers
186
187 def set_stored_state_dict(self, stored_state):
188 """Override this to set up whatever state storage you want.
189
190 The `stored_state` dict passed in contains whatever saved state we
191 might have for this object. If the return value of this method
192 evaluates to `True`, the contents of the `stored_state` dict will be
193 saved, otherwise it will be discarded.
194 """
195 pass
196
197 def get_space(self):
198 return self.physicser.get_space()
199
200 def get_shape(self):
201 return self.physicser.get_shape()
202
203 def get_render_position(self, surface):
204 return self.physicser.get_render_position(surface)
205
206 def get_render_angle(self):
207 return self.physicser.get_angle()
208
209 def get_facing_direction(self):
210 """Used by rendererd that care what direction an object is facing.
211 """
212 return None
213
214 def render(self, surface):
215 return self.renderer.render(surface)
216
217 def update(self, dt):
218 self.lifetime += dt
219 for timer in self._active_timers.keys():
220 self._active_timers[timer] -= dt
221 if self._active_timers[timer] <= 0:
222 self._active_timers.pop(timer)
223 self.renderer.update(dt)
224
225 def hit(self, weapon):
226 '''Was hit with a weapon (such as a bullet)'''
227 pass
228
229 def collide_with_protagonist(self, protagonist):
230 """Called as a `pre_solve` collision callback with the protagonist.
231
232 You can return `False` to ignore the collision, anything else
233 (including `None`) to process the collision as normal.
234 """
235 return True
236
237 def collide_with_furniture(self, furniture):
238 return True
239
240 def collide_with_claw_attack(self, claw_attack):
241 return True
242
243 def environmental_movement(self, vec):
244 self.physicser.apply_impulse(vec)
245
246 @classmethod
247 def requires(cls):
248 """Hints for the level editor"""
249 return [("name", "string")]
250
251 @classmethod
252 def movable(cls):
253 # Are we movable
254 hints = cls.requires()
255 for x in hints:
256 if 'position' in x:
257 return True
258 return False
259
260
261class FloorSwitch(GameObject):
262 zorder = ZORDER_FLOOR
263
264 def __init__(self, space, position):
265 body = make_body(None, None, position)
266 self.shape = pymunk.Circle(body, 30)
267 self.shape.collision_type = COLLISION_TYPE_SWITCH
268 self.shape.sensor = True
269 super(FloorSwitch, self).__init__(
270 SingleShapePhysicser(space, self.shape),
271 render.ImageStateRenderer({
272 True: resources.get_image('objects', 'sensor_on.png'),
273 False: resources.get_image('objects', 'sensor_off.png'),
274 }),
275 puzzle.CollidePuzzler(*SWITCH_PUSHERS),
276 )
277
278 @classmethod
279 def requires(cls):
280 return [("name", "string"), ("position", "coordinates")]
281
282
283class Note(GameObject):
284 zorder = ZORDER_FLOOR
285
286 def __init__(self, space, position, message):
287 body = make_body(None, None, position)
288 self.shape = pymunk.Circle(body, 30)
289 self.shape.sensor = True
290 super(Note, self).__init__(
291 SingleShapePhysicser(space, self.shape),
292 render.ImageRenderer(resources.get_image('objects', 'note.png')),
293 puzzle.CollidePuzzler(),
294 render.TextOverlay(message),
295 )
296
297 @classmethod
298 def requires(cls):
299 return [("name", "string"), ("position", "coordinates"),
300 ("message", "text")]
301
302
303class EphemeralNote(GameObject):
304 def __init__(self, message, timeout, **kwargs):
305 kwargs.setdefault('bg_colour', (255, 180, 180, 192))
306 super(EphemeralNote, self).__init__(
307 None,
308 render.NullRenderer(),
309 puzzle.YesPuzzler(),
310 render.TextOverlay(message, **kwargs),
311 )
312 self.add_timer('timeout', timeout)
313 self.start_timer('timeout')
314
315 def update(self, dt):
316 super(EphemeralNote, self).update(dt)
317 if not self.check_timer('timeout'):
318 return Result(remove=[self])
319
320
321class FloorLight(GameObject):
322 zorder = ZORDER_FLOOR
323
324 def __init__(self, space, position, state_source):
325 body = make_body(None, None, position)
326 self.shape = pymunk.Circle(body, 10)
327 self.shape.collision_type = COLLISION_TYPE_SWITCH
328 self.shape.sensor = True
329 super(FloorLight, self).__init__(
330 SingleShapePhysicser(space, self.shape),
331 render.ImageStateRenderer({
332 True: resources.get_image('objects', 'light_on.png'),
333 False: resources.get_image('objects', 'light_off.png'),
334 }),
335 puzzle.StateProxyPuzzler(state_source),
336 )
337
338 @classmethod
339 def requires(cls):
340 return [("name", "string"), ("position", "coordinates"),
341 ("state_source", "puzzler")]
342
343
344class Box(GameObject):
345 def __init__(self, space, position):
346 body = make_body(10, 10000, position, damping=0.5)
347 self.shape = pymunk.Poly(
348 body, [(-20, -20), (20, -20), (20, 20), (-20, 20)])
349 self.shape.friction = 0.5
350 self.shape.collision_type = COLLISION_TYPE_FURNITURE
351 super(Box, self).__init__(
352 SingleShapePhysicser(space, self.shape),
353 render.ImageRenderer(resources.get_image('objects', 'crate.png')),
354 )
355
356 @classmethod
357 def requires(cls):
358 return [("name", "string"), ("position", "coordinates"),
359 ("state_source", "puzzler")]
360
361
362class SokoBox(GameObject):
363 def __init__(self, space, position):
364 body = make_body(1, pymunk.inf, position, 0.2)
365 self.shape = pymunk.Poly(
366 body, [(-40, -40), (40, -40), (40, 40), (-40, 40)])
367 self.shape.friction = 0.5
368 self.shape.collision_type = COLLISION_TYPE_FURNITURE
369 super(SokoBox, self).__init__(
370 SingleShapePhysicser(space, self.shape),
371 render.ImageRenderer(
372 resources.get_image('objects', 'sokobox.png')),
373 )
374
375 @classmethod
376 def requires(cls):
377 return [("name", "string"), ("position", "coordinates"),
378 ("state_source", "puzzler")]
379
380
381class BaseDoor(GameObject):
382 zorder = ZORDER_FLOOR
383 is_open = True
384
385 def __init__(self, space, position, destination, dest_pos, angle,
386 renderer, condition):
387 body = make_body(pymunk.inf, pymunk.inf, position, damping=0.5)
388 self.shape = pymunk.Circle(body, 30)
389 self.shape.collision_type = COLLISION_TYPE_DOOR
390 self.shape.body.angle = float(angle) / 180 * math.pi
391 self.shape.sensor = True
392 self.destination = destination
393 self.dest_pos = tuple(dest_pos)
394 super(BaseDoor, self).__init__(
395 SingleShapePhysicser(space, self.shape),
396 renderer,
397 puzzle.ParentAttrPuzzler('is_open'),
398 interactible=environment.Interactible(
399 environment.Action(self._post_door_event, condition)),
400 )
401
402 def _post_door_event(self, protagonist):
403 DoorEvent.post(self.destination, self.dest_pos)
404
405
406class Door(BaseDoor):
407 def __init__(self, space, position, destination, dest_pos, angle):
408 super(Door, self).__init__(
409 space, position, destination, dest_pos, angle,
410 render.ImageRenderer(resources.get_image('objects', 'door.png')),
411 environment.YesCondition(),
412 )
413
414 @classmethod
415 def requires(cls):
416 return [("name", "string"), ("position", "coordinates"),
417 ("destination", "level name"), ("dest_pos", "coordinate"),
418 ("angle", "degrees")]
419
420
421class RestartGameDoor(Door):
422 def _post_door_event(self, protagonist):
423 protagonist.world.reset()
424 super(RestartGameDoor, self)._post_door_event(protagonist)
425
426
427class ContinueGameDoor(Door):
428 def _post_door_event(self, protagonist):
429 world = protagonist.world
430 if world.level[0]:
431 DoorEvent.post(world.level[0], world.level[1])
432 else:
433 # New game?
434 super(ContinueGameDoor, self)._post_door_event(protagonist)
435
436
437def make_overlay_image(image_name, angle):
438 transforms = ()
439 if angle != 0:
440 transforms = (rotator(-angle),)
441 return resources.get_image('objects', image_name, transforms=transforms)
442
443
444class PuzzleDoor(BaseDoor):
445 def __init__(self, space, position, destination, dest_pos, angle,
446 key_state):
447 self._key_state = key_state
448 overlay = ImageOverlay(make_overlay_image('lock.png', angle))
449 super(PuzzleDoor, self).__init__(
450 space, position, destination, dest_pos, angle,
451 render.ImageStateRenderer({
452 True: resources.get_image('objects', 'door.png'),
453 False: resources.get_image(
454 'objects', 'door.png', transforms=(overlay,)),
455 }),
456 environment.FunctionCondition(lambda p: self.is_open),
457 )
458
459 @property
460 def is_open(self):
461 return self._stored_state['is_open']
462
463 def set_stored_state_dict(self, stored_state):
464 self._stored_state = stored_state
465 self._stored_state.setdefault('is_open', False)
466 return True
467
468 def update(self, dt):
469 if not self.is_open:
470 self._stored_state['is_open'] = self.puzzler.glue.get_state_of(
471 self._key_state)
472 super(PuzzleDoor, self).update(dt)
473
474 @classmethod
475 def requires(cls):
476 return [("name", "string"), ("position", "coordinates"),
477 ("destination", "level name"), ("dest_pos", "coordinate"),
478 ("angle", "degrees"),
479 ("key_state", "puzzler")]
480
481
482class KeyedDoor(BaseDoor):
483 def __init__(self, space, position, destination, dest_pos, angle,
484 key_item=None):
485 self._key_item = key_item
486 overlay = ImageOverlay(
487 make_overlay_image('%s.png' % (key_item,), angle))
488 super(KeyedDoor, self).__init__(
489 space, position, destination, dest_pos, angle,
490 render.ImageRenderer(resources.get_image(
491 'objects', 'door.png', transforms=(overlay,))),
492 environment.ItemRequiredCondition(key_item),
493 )
494
495 @classmethod
496 def requires(cls):
497 return [("name", "string"), ("position", "coordinates"),
498 ("destination", "level name"), ("dest_pos", "coordinate"),
499 ("angle", "degrees"), ("key_item", "item name")]
500
501
502class Hatch(GameObject):
503 zorder = ZORDER_FLOOR
504
505 def __init__(self, space, end1, end2, key_state=None):
506 body = make_body(None, None, (0, 0))
507 self.shape = pymunk.Segment(body, tuple(end1), tuple(end2), 7)
508 self.shape.collision_type = COLLISION_TYPE_DOOR
509 if key_state is None:
510 puzzler = puzzle.YesPuzzler()
511 else:
512 puzzler = puzzle.StateProxyPuzzler(key_state)
513 super(Hatch, self).__init__(
514 SingleShapePhysicser(space, self.shape),
515 render.HatchRenderer(),
516 puzzler,
517 )
518
519 def collide_with_protagonist(self, protagonist):
520 if self.puzzler.get_state():
521 # Reject the collision, we can walk through.
522 return False
523 return True
524
525 collide_with_furniture = collide_with_protagonist
526
527 @classmethod
528 def requires(cls):
529 return [("name", "string"), ("end1", "coordinates"),
530 ("end2", "coordinates"), ("key_state", "puzzler")]
531
532
533class ToggleSwitch(GameObject):
534 zorder = ZORDER_LOW
535
536 def __init__(self, space, position):
537 body = make_body(None, None, position)
538 self.shape = pymunk.Circle(body, 20)
539 self.shape.sensor = True
540 super(ToggleSwitch, self).__init__(
541 SingleShapePhysicser(space, self.shape),
542 render.ImageStateRenderer({
543 True: resources.get_image('objects', 'lever.png'),
544 False: resources.get_image(
545 'objects', 'lever.png', transforms=(FLIP_H,)),
546 }),
547 puzzle.ParentAttrPuzzler('toggle_on'),
548 interactible=environment.Interactible(
549 environment.Action(self._toggle)),
550 )
551
552 @property
553 def toggle_on(self):
554 return self._stored_state['toggle_on']
555
556 def _toggle(self, protagonist):
557 self._stored_state['toggle_on'] = not self.toggle_on
558
559 def set_stored_state_dict(self, stored_state):
560 self._stored_state = stored_state
561 # We start in the "off" position.
562 self._stored_state.setdefault('toggle_on', False)
563 return True
564
565 @classmethod
566 def requires(cls):
567 return [("name", "string"), ("position", "coordinates")]
568
569
570class Bullet(GameObject):
571 def __init__(self, space, position, impulse, damage, bullet_type,
572 source_collision_type):
573 body = make_body(1, pymunk.inf, position)
574 body.angle = impulse.angle
575 self.last_position = position
576 self.shape = pymunk.Circle(body, 2)
577 self.shape.sensor = True
578 self.shape.collision_type = COLLISION_TYPE_PROJECTILE
579 self.damage = damage
580 self.type = bullet_type
581 self.source_collision_type = source_collision_type
582 super(Bullet, self).__init__(
583 SingleShapePhysicser(space, self.shape),
584 render.ImageRenderer(resources.get_image(
585 'objects', '%s.png' % self.type)),
586 )
587 self.physicser.apply_impulse(impulse)
588
589 def update(self, dt):
590 super(Bullet, self).update(dt)
591 position = (self.physicser.position.x, self.physicser.position.y)
592 r = self.get_space().segment_query(self.last_position, position)
593 self.last_position = position
594 for collision in r:
595 shape = collision.shape
596 if (shape.collision_type == self.source_collision_type
597 or shape == self.physicser.get_shape()
598 or shape.sensor):
599 continue
600 if hasattr(shape, 'physicser'):
601 shape.physicser.game_object.hit(self)
602 self.physicser.remove_from_space()
603 return Result(remove=[self])
604
605
606class ClawAttack(GameObject):
607 def __init__(self, space, pos, vector, damage):
608 body = make_body(1, pymunk.inf,
609 (pos[0] + (vector.length * math.cos(vector.angle)),
610 pos[1] + (vector.length * math.sin(vector.angle))))
611 body.angle = vector.angle
612 self.shape = pymunk.Circle(body, 30)
613 self.shape.sensor = True
614 self.shape.collision_type = COLLISION_TYPE_WEREWOLF_ATTACK
615 self.damage = damage
616 super(ClawAttack, self).__init__(
617 SingleShapePhysicser(space, self.shape),
618 render.ImageRenderer(resources.get_image(
619 'objects', 'werewolf_SW_claw_attack.png',
620 transforms=(FLIP_H,))),
621 )
622
623 def update(self, dt):
624 super(ClawAttack, self).update(dt)
625 if self.lifetime > 0.1:
626 self.physicser.remove_from_space()
627 return Result(remove=[self])
628
629
630class HostileTerrain(GameObject):
631 zorder = ZORDER_FLOOR
632 damage = None
633 tiles = []
634 tile_alpha = 255
635 tile_frame_ticks = 3
636 # How often to hit the player
637 rate = 5
638
639 def __init__(self, space, position, outline):
640 body = make_body(10, pymunk.inf, position)
641 # Adjust shape relative to position
642 shape_outline = [(p[0] - position[0], p[1] - position[1]) for
643 p in outline]
644 self.shape = pymunk.Poly(body, shape_outline)
645 self._ticks = 0
646 self.shape.collision_type = COLLISION_TYPE_SWITCH
647 self.shape.sensor = True
648 renderer = self._fix_image(outline)
649 super(HostileTerrain, self).__init__(
650 SingleShapePhysicser(space, self.shape),
651 renderer)
652
653 def _fix_image(self, outline):
654 if len(self.tiles) > 1:
655 tile_images = [resources.get_image('tiles', x)
656 for x in self.tiles]
657 renderer = render.TimedTiledRenderer(outline, tile_images,
658 self.tile_frame_ticks,
659 self.tile_alpha)
660 else:
661 tile_image = resources.get_image('tiles', self.tiles[0])
662 renderer = render.TiledRenderer(outline, tile_image,
663 self.tile_alpha)
664 return renderer
665
666 def update_image(self, new_outline):
667 self.renderer = self._fix_image(new_outline)
668
669 def collide_with_protagonist(self, protagonist):
670 # We're called every frame we're colliding, so
671 # There are timing issues with stepping on and
672 # off terrian, but as long as the rate is reasonably
673 # low, they shouldn't impact gameplay
674 if self._ticks == 0:
675 self.apply_effect(protagonist)
676 self._ticks += 1
677 if self._ticks > self.rate:
678 self._ticks = 0
679
680 def apply_effect(self, protagonist):
681 protagonist.lose_health(self.damage)
682
683 @classmethod
684 def requires(cls):
685 return [("name", "string"), ("position", "coordinates"),
686 ("outline", "polygon (convex)")]
687
688
689class AcidFloor(HostileTerrain):
690 damage = 1
691 tiles = ['acid.png', 'acid2.png', 'acid3.png']
692 tile_alpha = 200
693 tile_frame_ticks = 10
694
695
696class ForceWolfFloor(HostileTerrain):
697 tiles = ['moonlight.png']
698 rate = 0
699 tile_alpha = 150
700 zorder = ZORDER_HIGH
701
702 def apply_effect(self, protagonist):
703 protagonist.force_wolf_form()
704
705
706class GravityWell(GameObject):
707 zorder = ZORDER_FLOOR
708 # How often to hit the player
709 rate = 5
710
711 def __init__(self, space, position, radius, force):
712 body = make_body(None, None, position)
713 # Adjust shape relative to position
714 self._radius = radius
715 self.shape = pymunk.Circle(body, radius)
716 self.centre = pymunk.Circle(body, 10)
717 self.centre.friction = pymunk.inf
718 self._ticks = 0
719 self.force = force
720 self.shape.collision_type = COLLISION_TYPE_SWITCH
721 self.shape.sensor = True
722 super(GravityWell, self).__init__(
723 MultiShapePhysicser(space, self.shape, self.centre),
724 render.ImageRenderer(resources.get_image(
725 'objects', 'gravity_well.png')),
726 )
727
728 def collide_with_protagonist(self, protagonist):
729 # We're called every frame we're colliding, so
730 # There are timing issues with stepping on and
731 # off terrian, but as long as the rate is reasonably
732 # low, they shouldn't impact gameplay
733 self.apply_effect(protagonist)
734
735 def collide_with_furniture(self, furniture):
736 # We're called every frame we're colliding, so
737 # There are timing issues with stepping on and
738 # off terrian, but as long as the rate is reasonably
739 # low, they shouldn't impact gameplay
740 self.apply_effect(furniture)
741
742 def apply_effect(self, object_to_move):
743 movement = self.physicser.position - object_to_move.physicser.position
744 local_force = self.force * (1 - (self._radius / movement.length))
745 movement.length = local_force
746 object_to_move.environmental_movement(-movement)
747
748 @classmethod
749 def requires(cls):
750 return [("name", "string"), ("position", "coordinates"),
751 ("outline", "polygon (convex)")]
752
753
754class SheepPen(GameObject):
755 zorder = ZORDER_FLOOR
756
757 def __init__(self, space, position, outline, sheep_count):
758 body = make_body(None, None, position)
759 # Adjust shape relative to position
760 shape_outline = [(p[0] - position[0], p[1] - position[1]) for
761 p in outline]
762 self.shape = pymunk.Poly(body, shape_outline)
763 self.shape.collision_type = COLLISION_TYPE_SHEEP_PEN
764 self.shape.sensor = True
765 super(SheepPen, self).__init__(
766 SingleShapePhysicser(space, self.shape),
767 render.Renderer(),
768 puzzle.MultiCollidePuzzler(sheep_count, COLLISION_TYPE_SHEEP),
769 )
770
771 @classmethod
772 def requires(cls):
773 return [("name", "string"), ("position", "coordinates"),
774 ("outline", "polygon (convex)"), ("sheep_count", "int")]
Note: See TracBrowser for help on using the repository browser.