Changeset 444:547320870aed for nagslang


Ignore:
Timestamp:
Sep 7, 2013, 12:47:34 PM (7 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Message:

Herd ALL THE SHEEPS.

Location:
nagslang
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • nagslang/constants.py

    r410 r444  
    2626COLLISION_TYPE_WEREWOLF_ATTACK = 8
    2727COLLISION_TYPE_SHEEP = 9
     28COLLISION_TYPE_SHEEP_PEN = 10
    2829
    2930SWITCH_PUSHERS = [COLLISION_TYPE_PLAYER, COLLISION_TYPE_FURNITURE]
  • nagslang/game_object.py

    r437 r444  
    1010from nagslang.constants import (
    1111    COLLISION_TYPE_DOOR, COLLISION_TYPE_FURNITURE, COLLISION_TYPE_PROJECTILE,
    12     COLLISION_TYPE_SWITCH, COLLISION_TYPE_WEREWOLF_ATTACK,
    13     SWITCH_PUSHERS, ZORDER_FLOOR, ZORDER_LOW, ZORDER_HIGH)
     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)
    1415from nagslang.resources import resources
    1516from nagslang.events import DoorEvent
     
    684685        return [("name", "string"), ("position", "coordinates"),
    685686                ("outline", "polygon (convex)")]
     687
     688
     689class SheepPen(GameObject):
     690    zorder = ZORDER_FLOOR
     691
     692    def __init__(self, space, position, outline, sheep_count):
     693        body = make_body(None, None, position)
     694        # Adjust shape relative to position
     695        shape_outline = [(p[0] - position[0], p[1] - position[1]) for
     696                         p in outline]
     697        self.shape = pymunk.Poly(body, shape_outline)
     698        self.shape.collision_type = COLLISION_TYPE_SHEEP_PEN
     699        self.shape.sensor = True
     700        super(SheepPen, self).__init__(
     701            SingleShapePhysicser(space, self.shape),
     702            render.Renderer(),
     703            puzzle.MultiCollidePuzzler(sheep_count, COLLISION_TYPE_SHEEP),
     704        )
     705
     706    @classmethod
     707    def requires(cls):
     708        return [("name", "string"), ("position", "coordinates"),
     709                ("outline", "polygon (convex)"), ("sheep_count", "int")]
  • nagslang/puzzle.py

    r328 r444  
    7171        self._collision_types = collision_types
    7272
     73    def get_colliders(self):
     74        space = self.game_object.get_space()
     75        my_shape = self.game_object.get_shape()
     76        shapes = [shape for shape in space.shapes
     77                  if shape.collision_type in self._collision_types]
     78        return [shape for shape in shapes
     79                if my_shape in space.point_query(shape.body.position)]
     80
    7381    def get_state(self):
    74         space = self.game_object.get_space()
    75         for shape in space.shape_query(self.game_object.get_shape()):
    76             if shape.collision_type in self._collision_types:
    77                 return True
    78         return False
     82        return bool(self.get_colliders())
    7983
    8084    @classmethod
    8185    def requires(cls):
    8286        return [("name", "string"), ("collision_types", "list of ints")]
     87
     88
     89class MultiCollidePuzzler(CollidePuzzler):
     90    def __init__(self, min_count, *collision_types):
     91        self._min_count = min_count
     92        super(MultiCollidePuzzler, self).__init__(*collision_types)
     93
     94    def get_state(self):
     95        return len(self.get_colliders()) >= self._min_count
     96
     97    @classmethod
     98    def requires(cls):
     99        return [("name", "string"), ("min_count", "int"),
     100                ("collision_types", "list of ints")]
    83101
    84102
Note: See TracChangeset for help on using the changeset viewer.