Ignore:
Timestamp:
Sep 6, 2013, 11:04:01 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
rebase_source:
cfdbf911c96183a66f8127a1ff9fcbbe16ebc497
Message:

Use Result to handle firing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/screens/area.py

    r391 r393  
    99    COLLISION_TYPE_FURNITURE, COLLISION_TYPE_WEREWOLF_ATTACK,
    1010    CMD_TOGGLE_FORM, CMD_ACTION)
    11 from nagslang.events import (
    12     ScreenChange, DoorEvent, EnemyDeathEvent, FireEvent, ClawEvent)
     11from nagslang.events import ScreenChange, DoorEvent, EnemyDeathEvent, ClawEvent
    1312from nagslang.level import Level
    1413from nagslang.screens.base import Screen
    15 from nagslang.game_object import Bullet, ClawAttack
     14from nagslang.game_object import ClawAttack
    1615from nagslang.sound import sound
    1716
     
    179178            # else we're teleporting within the screen, and just the
    180179            # position change is enough
    181         elif FireEvent.matches(ev):
    182             bullet = Bullet(self.space, ev.source, ev.impulse, ev.damage,
    183                             ev.bullet_type, ev.source_collision_type)
    184             self._drawables.add(bullet)
    185180        elif EnemyDeathEvent.matches(ev):
    186181            self.world.kills += 1
     
    234229        self.protagonist.set_direction(dx, dy)
    235230        if self.keys.is_attacking():
    236             self.protagonist.handle_attack_key_down()
     231            self._handle_result(self.protagonist.handle_attack_key_down())
    237232
    238233    def tick(self, seconds):
     
    240235        self.tick_protagonist()
    241236        for drawable in self._drawables:
    242             result = drawable.update(seconds)
    243             if result is not None:
    244                 for new_drawable in result.add:
    245                     self._drawables.add(new_drawable)
    246                 for old_drawable in result.remove:
    247                     self._drawables.remove(old_drawable)
     237            self._handle_result(drawable.update(seconds))
     238
     239    def _handle_result(self, result):
     240        if result is not None:
     241            for drawable in result.add:
     242                self._drawables.add(drawable)
     243            for drawable in result.remove:
     244                self._drawables.remove(drawable)
    248245
    249246    def render_health_bar(self, surface, damage_experienced=None):
Note: See TracChangeset for help on using the changeset viewer.