added ennemies' shoot

This commit is contained in:
kleph 2010-02-23 00:18:20 +01:00
parent 85982e9fca
commit bb4ff64e60

View file

@ -201,7 +201,9 @@ class Enemy(Object):
def __init__(self, frames, type, pos): def __init__(self, frames, type, pos):
Object.__init__(self, frames, pos, (-1, 0)) Object.__init__(self, frames, pos, (-1, 0))
self.counter = 0 self.counter = 0
self.counter_fire = 0
self.threshold = 2 self.threshold = 2
self.threshold_fire = 100
self.dying = False self.dying = False
def update(self): def update(self):
@ -218,8 +220,25 @@ class Enemy(Object):
else: else:
self.counter += 1 self.counter += 1
if not self.dying:
if self.counter_fire == self.threshold_fire:
self.shoot_player()
self.counter_fire = 0
else:
self.counter_fire += 1
def shoot_player(self):
""" shoot a bullet to the player """
speed = self.aim_player()
bullet = globals.bullet_factory.create_type2(self.rect.midleft, speed)
globals.bullets_list.add(bullet)
def aim_player(self): def aim_player(self):
""" compute speed vector to aim at current player position """ """ compute speed vector to aim at current player position """
# get player position
player_pos = globals.player.rect
return (-10, 0)
def die(self): def die(self):
""" make the enemy dying """ """ make the enemy dying """