Ignore:
Timestamp:
09/02/13 16:05:03 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

A box.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r126 r133  
    66
    77from nagslang.constants import (
    8     SWITCH_PUSHERS, COLLISION_TYPE_SWITCH, ZORDER_LOW)
     8    SWITCH_PUSHERS, COLLISION_TYPE_SWITCH, COLLISION_TYPE_BOX, ZORDER_LOW)
    99from nagslang.options import options
    1010
     
    175175
    176176
    177 class ShapeStateRenderer(Renderer):
     177class ShapeRenderer(Renderer):
     178    def render(self, surface):
     179        self._render_shape(surface)
     180        super(ShapeRenderer, self).render(surface)
     181
     182
     183class ShapeStateRenderer(ShapeRenderer):
    178184    """Renders the shape in a different colour depending on the state.
    179185
     
    187193
    188194        self.game_object.get_shape().color = color
    189         self._render_shape(surface)
    190195        super(ShapeStateRenderer, self).render(surface)
     196
     197
     198def damping_velocity_func(body, gravity, damping, dt):
     199    """Apply custom damping to this body's velocity.
     200    """
     201    damping = getattr(body, 'damping', damping)
     202    return pymunk.Body.update_velocity(body, gravity, damping, dt)
     203
     204
     205def make_body(mass, moment, position, damping=None):
     206    body = pymunk.Body(mass, moment)
     207    body.position = position
     208    if damping is not None:
     209        body.damping = damping
     210        body.velocity_func = damping_velocity_func
     211    return body
    191212
    192213
     
    250271            StateProxyPuzzler(state_source),
    251272        )
     273
     274
     275class Box(GameObject):
     276    def __init__(self, space, position):
     277        body = make_body(10, 10000, position, damping=0.5)
     278        self.shape = pymunk.Poly(
     279            body, [(-20, -20), (20, -20), (20, 20), (-20, 20)])
     280        self.shape.collision_type = COLLISION_TYPE_BOX
     281        super(Box, self).__init__(
     282            SingleShapePhysicser(space, self.shape),
     283            ShapeRenderer(),
     284        )
Note: See TracChangeset for help on using the changeset viewer.