Changeset 351:50fce787ae17


Ignore:
Timestamp:
Sep 6, 2013, 2:13:43 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
rebase_source:
b00bb90c8c9bb2cbe08d07e2387e8be6a7eefbbf
Message:

Hostile terrian objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r346 r351  
    481481            self.physicser.remove_from_space()
    482482            self.remove = True
     483
     484
     485class HostileTerrain(GameObject):
     486    zorder = ZORDER_FLOOR
     487    damage = None
     488    tile = None
     489    # How often to hit the player
     490    rate = 5
     491
     492    def __init__(self, space, position, outline):
     493        body = make_body(10, pymunk.inf, position)
     494        # Adjust shape relative to position
     495        shape_outline = [(p[0] - position[0], p[1] - position[1]) for
     496                         p in outline]
     497        self.shape = pymunk.Poly(body, shape_outline)
     498        self._ticks = 0
     499        self.shape.collision_type = COLLISION_TYPE_SWITCH
     500        self.shape.sensor = True
     501        super(HostileTerrain, self).__init__(
     502            SingleShapePhysicser(space, self.shape),
     503            render.TiledRenderer(outline,
     504                                 resources.get_image('tiles', self.tile)))
     505
     506    def collide_with_protagonist(self, protagonist):
     507        # We're called every frame we're colliding, so
     508        # There are timing issues with stepping on and
     509        # off terrian, but as long as the rate is reasonably
     510        # low, they shouldn't impact gameplay
     511        if self._ticks == 0:
     512            protagonist.lose_health(self.damage)
     513        self._ticks += 1
     514        if self._ticks > self.rate:
     515            self._ticks = 0
     516
     517    @classmethod
     518    def requires(cls):
     519        return [("name", "string"), ("position", "coordinates"),
     520                ("outline", "polygon")]
     521
     522
     523class AcidFloor(HostileTerrain):
     524    damage = 1
     525    tile = 'acid.png'
Note: See TracChangeset for help on using the changeset viewer.