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

Better protagonist physicser.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r211 r215  
    2626
    2727    def add_to_space(self):
    28         raise NotImplementedError()
     28        shape = self.get_shape()
     29        self.get_space().add(shape)
     30        if not shape.body.is_static:
     31            self.get_space().add(shape.body)
    2932
    3033    def remove_from_space(self):
    31         raise NotImplementedError()
     34        shape = self.get_shape()
     35        self.get_space().remove(shape)
     36        if not shape.body.is_static:
     37            self.get_space().remove(shape.body)
    3238
    3339    def get_render_position(self, surface):
    34         raise NotImplementedError()
     40        pos = self.get_shape().body.position
     41        return pymunk.pygame_util.to_pygame(pos, surface)
    3542
    3643    def get_angle(self):
    37         raise NotImplementedError()
     44        return self.get_shape().body.angle
     45
     46    @property
     47    def position(self):
     48        return self.get_shape().body.position
     49
     50    @position.setter
     51    def position(self, position):
     52        self.get_shape().body.position = position
    3853
    3954    def apply_impulse(self, j, r=(0, 0)):
    40         raise NotImplementedError()
     55        return self.get_shape().body.apply_impulse(j, r)
    4156
    4257
     
    4964    def get_shape(self):
    5065        return self._shape
    51 
    52     def add_to_space(self):
    53         self.get_space().add(self._shape)
    54         if not self._shape.body.is_static:
    55             self.get_space().add(self._shape.body)
    56 
    57     def remove_from_space(self):
    58         self.get_space().remove(self._shape)
    59         if not self._shape.body.is_static:
    60             self.get_space().remove(self._shape.body)
    61 
    62     def get_render_position(self, surface):
    63         pos = self._shape.body.position
    64         return pymunk.pygame_util.to_pygame(pos, surface)
    65 
    66     def get_angle(self):
    67         return self._shape.body.angle
    68 
    69     def apply_impulse(self, j, r=(0, 0)):
    70         return self._shape.body.apply_impulse(j, r)
    7166
    7267
Note: See TracChangeset for help on using the changeset viewer.