Changeset 305:ce11e1cae0ed


Ignore:
Timestamp:
Sep 5, 2013, 10:17:22 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
amend_source:
1aeacbea95041ff8c1d13e22b0ec7438887bf8a9
rebase_source:
adace333cb953613df6f300375ab3a7bee7123c4
Message:

Enemies now die

Location:
nagslang
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • nagslang/enemies.py

    r278 r305  
    2626        self._setup_physics(space, position)
    2727        self._setup_renderer()
     28        self.health = 42
    2829
    2930        super(Enemy, self).__init__(
     
    4748    def requires(cls):
    4849        return [("name", "string"), ("position", "coordinates")]
     50
     51    def lose_health(self, amount):
     52        self.health -= amount
     53        if self.health < 0:
     54            self.world.kills += 1
     55            self.physicser.remove_from_space()
     56            self.remove = True
    4957
    5058
     
    130138    def collide_with_protagonist(self, protagonist):
    131139        protagonist.lose_health(15)
     140
     141    def hit(self, weapon):
     142        self.lose_health(weapon.damage)
    132143
    133144    @classmethod
  • nagslang/events.py

    r293 r305  
    4949class FireEvent(UserEvent):
    5050    @classmethod
    51     def post(cls, source, impulse, source_collision_type):
     51    def post(cls, source, impulse, damage, source_collision_type):
    5252        super(FireEvent, cls).post(source=source, impulse=impulse,
     53                                   damage=damage,
    5354                                   source_collision_type=source_collision_type)
  • nagslang/game_object.py

    r302 r305  
    343343
    344344class Bullet(GameObject):
    345     def __init__(self, space, position, impulse, source_collision_type):
     345    def __init__(self, space, position, impulse, damage,
     346                 source_collision_type):
    346347        body = make_body(1, pymunk.inf, position)
    347348        self.last_position = position
     
    349350        self.shape.sensor = True
    350351        self.shape.collision_type = COLLISION_TYPE_PROJECTILE
     352        self.damage = damage
    351353        self.source_collision_type = source_collision_type
    352354        super(Bullet, self).__init__(
  • nagslang/protagonist.py

    r293 r305  
    262262        vec.angle = self.angle
    263263        vec.length = 1000
    264         FireEvent.post(self.physicser.position, vec, COLLISION_TYPE_PLAYER)
     264        FireEvent.post(self.physicser.position, vec, 10, COLLISION_TYPE_PLAYER)
    265265
    266266    def in_wolf_form(self):
  • nagslang/screens/area.py

    r303 r305  
    148148            # position change is enough
    149149        elif FireEvent.matches(ev):
    150             bullet = Bullet(self.space, ev.source, ev.impulse,
     150            bullet = Bullet(self.space, ev.source, ev.impulse, ev.damage,
    151151                            ev.source_collision_type)
    152152            self._drawables.add(bullet)
Note: See TracChangeset for help on using the changeset viewer.