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/game_object.py

    r332 r333  
    33
    44import math
    5 import time
    65
    76from nagslang import environment
     
    112111    def __init__(self, physicser, renderer, puzzler=None, overlay=None,
    113112                 interactible=None):
     113        self.lifetime = 0
    114114        self.physicser = physicser
    115115        physicser.set_game_object(self)
     
    148148        return self.renderer.render(surface)
    149149
    150     def update(self, seconds):
    151         self.renderer.update(seconds)
     150    def update(self, dt):
     151        self.lifetime += dt
     152        self.renderer.update(dt)
    152153
    153154    def hit(self, weapon):
     
    164165
    165166    def collide_with_furniture(self, furniture):
     167        return True
     168
     169    def collide_with_claw_attack(self, claw_attack):
    166170        return True
    167171
     
    365369        self.physicser.apply_impulse(impulse)
    366370
    367     def update(self, seconds):
    368         super(Bullet, self).update(seconds)
     371    def update(self, dt):
     372        super(Bullet, self).update(dt)
    369373        position = (self.physicser.position.x, self.physicser.position.y)
    370374        r = self.get_space().segment_query(self.last_position, position)
     
    415419
    416420class ClawAttack(GameObject):
    417     def __init__(self, space, position, vector, source_collision_type):
    418         body = make_body(1, pymunk.inf, position)
    419         self.last_position = position
     421    def __init__(self, space, position, vector, damage):
     422        body = make_body(1, pymunk.inf, position + vector)
     423        body.angle = vector.angle
    420424        self.shape = pymunk.Circle(body, 30)
    421425        self.shape.sensor = True
    422426        self.shape.collision_type = COLLISION_TYPE_WEREWOLF_ATTACK
    423         self.source_collision_type = source_collision_type
     427        self.damage = damage
    424428        super(ClawAttack, self).__init__(
    425429            SingleShapePhysicser(space, self.shape),
    426             render.ImageRenderer(resources.get_image
    427                                 ('objects', 'werewolf_SW_claw_attack.png')),
    428         )
    429         self.time_created = time.time()
    430 
    431     def update(self, seconds):
    432         super(ClawAttack, self).update(seconds)
    433         position = (self.physicser.position.x, self.physicser.position.y)
    434         r = self.get_space().segment_query(self.last_position, position)
    435         self.last_position = position
    436         for collision in r:
    437             shape = collision.shape
    438             if (shape.collision_type == self.source_collision_type
    439                     or shape == self.physicser.get_shape()
    440                     or shape.sensor):
    441                 continue
    442             if hasattr(shape, 'physicser'):
    443                 shape.physicser.game_object.hit(self)
    444         if time.time() - self.time_created > 0.2:
     430            render.ImageRenderer(resources.get_image(
     431                'objects', 'werewolf_SW_claw_attack.png',
     432                transforms=(FLIP_H,))),
     433        )
     434
     435    def update(self, dt):
     436        super(ClawAttack, self).update(dt)
     437        if self.lifetime > 0.2:
    445438            self.physicser.remove_from_space()
    446439            self.remove = True
Note: See TracChangeset for help on using the changeset viewer.