Changeset 416:bea0ea5b98df


Ignore:
Timestamp:
Sep 7, 2013, 10:52:16 AM (7 years ago)
Author:
davidsharpe@…
Branch:
default
Message:

Well, gravity.

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • data/levels/level1

    r379 r416  
    6363  classname: PuzzleDoor
    6464  name: switch_door
     65- args:
     66  - [600, 600]
     67  - 100
     68  - 1000
     69  classname: GravityWell
    6570lines:
    6671- - [750, 680]
  • nagslang/game_object.py

    r402 r416  
    212212        return True
    213213
     214    def environmental_movement(self, dx, dy):
     215        if (dx, dy) == (0, 0):
     216            return
     217        self.physicser.apply_impulse((dx, dy))
     218
    214219    @classmethod
    215220    def requires(cls):
     
    594599    def apply_effect(self, protagonist):
    595600        protagonist.force_wolf_form()
     601
     602class GravityWell(GameObject):
     603    zorder = ZORDER_FLOOR
     604    # How often to hit the player
     605    rate = 5
     606
     607    def __init__(self, space, position, size, force):
     608        body = make_body(10, pymunk.inf, position)
     609        # Adjust shape relative to position
     610        self.shape = pymunk.Circle(body, size)
     611        self._ticks = 0
     612        self.force = force
     613        self.shape.collision_type = COLLISION_TYPE_SWITCH
     614        self.shape.sensor = True
     615        super(GravityWell, self).__init__(
     616            SingleShapePhysicser(space, self.shape),
     617            render.ImageRenderer(resources.get_image(
     618                'objects', 'gravity_well.png')),
     619        )
     620
     621    def collide_with_protagonist(self, protagonist):
     622        # We're called every frame we're colliding, so
     623        # There are timing issues with stepping on and
     624        # off terrian, but as long as the rate is reasonably
     625        # low, they shouldn't impact gameplay
     626        if self._ticks == 0:
     627            self.apply_effect(protagonist)
     628        self._ticks += 1
     629        if self._ticks > self.rate:
     630            self._ticks = 0
     631
     632    def collide_with_furniture(self, furniture):
     633        # We're called every frame we're colliding, so
     634        # There are timing issues with stepping on and
     635        # off terrian, but as long as the rate is reasonably
     636        # low, they shouldn't impact gameplay
     637        if self._ticks == 0:
     638            self.apply_effect(furniture)
     639        self._ticks += 1
     640        if self._ticks > self.rate:
     641            self._ticks = 0
     642
     643    def apply_effect(self, object):
     644        object.environmental_movement(self.force, self.force)
     645
     646    @classmethod
     647    def requires(cls):
     648        return [("name", "string"), ("position", "coordinates"),
     649                ("outline", "polygon (convex)")]
  • nagslang/protagonist.py

    r399 r416  
    327327        self.world.inventory.add(item)
    328328
    329     def environmental_movement(self, dx, dy):
    330         if (dx, dy) == (0, 0):
    331             return
    332         self.physicser.apply_impulse((dx, dy))
    333 
    334329    def get_health_level(self):
    335330        """Return current health level
Note: See TracChangeset for help on using the changeset viewer.