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

Rectangular human protagonist shape, refactored physicsers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/protagonist.py

    r81 r93  
    1818    WOLF_FORM = 'wolf'
    1919
    20     def __init__(self, position):
    21         self._setup_physics(position)
     20    def __init__(self, space, position):
     21        self._setup_physics(space, position)
    2222        self._setup_renderers()
    2323        self.inventory = {}
     
    2525
    2626        super(Protagonist, self).__init__(
    27             self._renderers[self.form], SingleShapePhysicser(self.shape))
     27            self._physicsers[self.form], self._renderers[self.form])
    2828
    2929        self.go_human()
    3030
    31     def _setup_physics(self, position):
    32         self._body = pymunk.Body(10, 10000)
     31    def _setup_physics(self, space, position):
     32        self._body = pymunk.Body(10, pymunk.inf)
    3333        self._body.position = position
    3434        self._body.velocity_func = self.velocity_func
    3535
    36         self.shape = pymunk.Circle(self._body, 30)
    37         self.shape.elasticity = 1.0
    38         self.shape.friction = 10.0
    39         self.shape.collision_type = COLLISION_TYPE_PLAYER
     36        self._shapes = {
     37            self.HUMAN_FORM: pymunk.Poly(
     38                self._body, [(-15, -30), (15, -30), (15, 30), (-15, 30)]),
     39            self.WOLF_FORM: pymunk.Circle(self._body, 30),
     40        }
     41        self._physicsers = {}
     42        for form, shape in self._shapes.iteritems():
     43            shape.elasticity = 1.0
     44            shape.friction = 10.0
     45            shape.collision_type = COLLISION_TYPE_PLAYER
     46            self._physicsers[form] = SingleShapePhysicser(space, shape)
     47        self.angle = 0
    4048
    4149    def _get_image(self, name, *transforms):
     
    6371        return pymunk.Body.update_velocity(body, gravity, self.damping, dt)
    6472
     73    def get_render_angle(self):
     74        return self.angle
     75
    6576    def go_werewolf(self):
     77        self._physicsers[self.form].remove_from_space()
    6678        self.form = self.WOLF_FORM
     79        self._physicsers[self.form].add_to_space()
    6780        self._body.mass = 100
    68         self._body.moment = 10000
    6981        self._body.velocity_limit = 1000
    7082        self.impulse_factor = 4000
     
    7385
    7486    def go_human(self):
     87        self._physicsers[self.form].remove_from_space()
    7588        self.form = self.HUMAN_FORM
     89        self._physicsers[self.form].add_to_space()
    7690        self._body.mass = 10
    77         self._body.moment = 1000
    7891        self._body.velocity_limit = 1000
    7992        self.impulse_factor = 500
     
    8497        if (dx, dy) == (0, 0):
    8598            return
    86         vec = pymunk.Vec2d((dx, dy))
    87         self._body.angle = vec.angle
     99        self.angle = pymunk.Vec2d((dx, dy)).angle
    88100        self._body.apply_impulse(
    89101            (dx * self.impulse_factor, dy * self.impulse_factor))
     
    119131            return
    120132        self._body.apply_impulse((dx, dy))
     133
     134    def render(self, surface):
     135        pymunk.pygame_util.draw(surface, self._shapes[self.form])
     136        super(Protagonist, self).render(surface)
Note: See TracChangeset for help on using the changeset viewer.