added ennemies' shoot
This commit is contained in:
parent
85982e9fca
commit
bb4ff64e60
1 changed files with 19 additions and 0 deletions
19
pyshoot.py
19
pyshoot.py
|
@ -201,7 +201,9 @@ class Enemy(Object):
|
|||
def __init__(self, frames, type, pos):
|
||||
Object.__init__(self, frames, pos, (-1, 0))
|
||||
self.counter = 0
|
||||
self.counter_fire = 0
|
||||
self.threshold = 2
|
||||
self.threshold_fire = 100
|
||||
self.dying = False
|
||||
|
||||
def update(self):
|
||||
|
@ -218,8 +220,25 @@ class Enemy(Object):
|
|||
else:
|
||||
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):
|
||||
""" compute speed vector to aim at current player position """
|
||||
# get player position
|
||||
player_pos = globals.player.rect
|
||||
return (-10, 0)
|
||||
|
||||
|
||||
def die(self):
|
||||
""" make the enemy dying """
|
||||
|
|
Loading…
Reference in a new issue