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

Better wolf claw attack.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/screens/area.py

    r321 r333  
    77from nagslang.constants import (
    88    COLLISION_TYPE_WALL, COLLISION_TYPE_PLAYER, CALLBACK_COLLIDERS,
    9     COLLISION_TYPE_FURNITURE)
     9    COLLISION_TYPE_FURNITURE, COLLISION_TYPE_WEREWOLF_ATTACK)
    1010from nagslang.enemies import DeadEnemy
    11 from nagslang.events import ScreenChange, DoorEvent, FireEvent, \
    12     EnemyDeathEvent, ClawEvent
     11from nagslang.events import (
     12    ScreenChange, DoorEvent, FireEvent, EnemyDeathEvent, ClawEvent)
    1313from nagslang.level import Level
    1414from nagslang.screens.base import Screen
     
    9494        # accidentally reject collisions from handlers that return `None`, so
    9595        # we explicitly check for `False` and treate everything else as `True`.
    96         if result is False:
    97             return False
    98         return True
     96        return result is not False
     97
     98    def _claw_attack_collision_pre_solve_handler(self, space, arbiter):
     99        claw = arbiter.shapes[0].physicser.game_object
     100        gobj = arbiter.shapes[1].physicser.game_object
     101        result = gobj.collide_with_claw_attack(claw)
     102        return result is not False
    99103
    100104    def _furniture_collision_pre_solve_handler(self, space, arbiter):
     
    112116                COLLISION_TYPE_FURNITURE, collision_type,
    113117                pre_solve=self._furniture_collision_pre_solve_handler)
     118            self.space.add_collision_handler(
     119                COLLISION_TYPE_WEREWOLF_ATTACK, collision_type,
     120                pre_solve=self._claw_attack_collision_pre_solve_handler)
    114121
    115122    def add_walls(self):
     
    174181        elif ClawEvent.matches(ev):
    175182            claw_attack = ClawAttack(self.space, ev.source, ev.vector,
    176                                      ev.source_collision_type)
     183                                     ev.damage)
    177184            self._drawables.add(claw_attack)
    178185        self.keys.handle_event(ev)
     
    235242        else:
    236243            health_box_colour = pygame.color.THECOLORS['white']
    237         pygame.draw.rect(surface,  health_box_colour, rect, 0)
     244        pygame.draw.rect(surface, health_box_colour, rect, 0)
    238245        if self.protagonist.in_human_form():
    239246            health_colour = pygame.color.THECOLORS['red']
     
    241248            health_colour = pygame.color.THECOLORS['purple']
    242249        rect = pygame.Rect(55, 505, self.protagonist.get_health_level(), 40)
    243         pygame.draw.rect(surface,  health_colour,
    244                          rect, 0)
     250        pygame.draw.rect(surface, health_colour, rect, 0)
Note: See TracChangeset for help on using the changeset viewer.