Ignore:
Timestamp:
09/05/13 22:37:26 (9 years ago)
Author:
David Sharpe
Branch:
default
Phase:
public
Rebase:
36376630353139353836626165396336663535386431643932383332613364336634636231386363
Message:

Basic claw attack, stealing liberally from other people's code! ;)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r307 r312  
    33
    44import math
     5import time
    56
    67from nagslang import environment
     
    1011from nagslang.constants import (
    1112    SWITCH_PUSHERS, COLLISION_TYPE_SWITCH, COLLISION_TYPE_BOX, ZORDER_LOW,
    12     ZORDER_FLOOR, COLLISION_TYPE_DOOR, COLLISION_TYPE_PROJECTILE)
     13    ZORDER_FLOOR, COLLISION_TYPE_DOOR, COLLISION_TYPE_PROJECTILE,
     14    COLLISION_TYPE_WEREWOLF_ATTACK)
    1315from nagslang.resources import resources
    1416from nagslang.events import DoorEvent
     
    405407            render.ImageRenderer(resources.get_image('objects', 'bullet.png')),
    406408        )
     409
     410
     411class ClawAttack(GameObject):
     412    def __init__(self, space, position, vector, source_collision_type):
     413        body = make_body(1, pymunk.inf, position)
     414        self.last_position = position
     415        self.shape = pymunk.Circle(body, 30)
     416        self.shape.sensor = True
     417        self.shape.collision_type = COLLISION_TYPE_WEREWOLF_ATTACK
     418        self.source_collision_type = source_collision_type
     419        super(ClawAttack, self).__init__(
     420            SingleShapePhysicser(space, self.shape),
     421            render.ImageRenderer(resources.get_image
     422                                ('objects', 'werewolf_SW_claw_attack.png')),
     423        )
     424        self.time_created = time.time()
     425
     426    def animate(self):
     427        super(ClawAttack, self).animate()
     428        position = (self.physicser.position.x, self.physicser.position.y)
     429        r = self.get_space().segment_query(self.last_position, position)
     430        self.last_position = position
     431        for collision in r:
     432            shape = collision.shape
     433            if (shape.collision_type == self.source_collision_type
     434                or shape == self.physicser.get_shape()
     435                or shape.sensor):
     436                continue
     437            if hasattr(shape, 'physicser'):
     438                shape.physicser.game_object.hit(self)
     439        if time.time() - self.time_created > 0.2:
     440            self.physicser.remove_from_space()
     441            self.remove = True
     442
Note: See TracChangeset for help on using the changeset viewer.