Changeset 391:866cdc74b26a


Ignore:
Timestamp:
Sep 6, 2013, 10:42:09 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Message:

Use Result to handle enemy death (but keep the event for accounting purposes)

Location:
nagslang
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • nagslang/enemies.py

    r385 r391  
    99from nagslang.constants import (COLLISION_TYPE_ENEMY, COLLISION_TYPE_FURNITURE,
    1010                                ACID_SPEED, ACID_DAMAGE, ZORDER_MID)
    11 from nagslang.events import EnemyDeathEvent, FireEvent
     11from nagslang.events import FireEvent, EnemyDeathEvent
    1212from nagslang.game_object import (GameObject, SingleShapePhysicser, Result,
    1313                                  make_body)
     
    7171        self.health -= amount
    7272        if self.health <= 0:
     73            EnemyDeathEvent.post()
    7374            self.physicser.remove_from_space()
    74             EnemyDeathEvent.post(self.physicser.position, self.enemy_type)
    7575
    7676    def set_direction(self, dx, dy):
     
    129129        super(Enemy, self).update(dt)
    130130        if self.health <= 0:
    131             return Result(remove=[self])
     131            return Result(
     132                add=[DeadEnemy(self.get_space(), self.world,
     133                               self.physicser.position, self.enemy_type)],
     134                remove=[self])
    132135
    133136
  • nagslang/events.py

    r363 r391  
    5757class EnemyDeathEvent(UserEvent):
    5858    @classmethod
    59     def post(cls, position, enemy_type):
    60         super(EnemyDeathEvent, cls).post(position=position,
    61                                          enemy_type=enemy_type)
     59    def post(cls):
     60        super(EnemyDeathEvent, cls).post()
    6261
    6362
  • nagslang/screens/area.py

    r385 r391  
    99    COLLISION_TYPE_FURNITURE, COLLISION_TYPE_WEREWOLF_ATTACK,
    1010    CMD_TOGGLE_FORM, CMD_ACTION)
    11 from nagslang.enemies import DeadEnemy
    1211from nagslang.events import (
    13     ScreenChange, DoorEvent, FireEvent, EnemyDeathEvent, ClawEvent)
     12    ScreenChange, DoorEvent, EnemyDeathEvent, FireEvent, ClawEvent)
    1413from nagslang.level import Level
    1514from nagslang.screens.base import Screen
     
    186185        elif EnemyDeathEvent.matches(ev):
    187186            self.world.kills += 1
    188             dead_enemy = DeadEnemy(self.space, self.world, ev.position,
    189                                    ev.enemy_type)
    190             self._drawables.add(dead_enemy)
    191187        elif ClawEvent.matches(ev):
    192188            claw_attack = ClawAttack(self.space, ev.source, ev.vector,
Note: See TracChangeset for help on using the changeset viewer.