implement ennemy life
This commit is contained in:
parent
5a6d1ae458
commit
ab6fb53b6a
1 changed files with 10 additions and 3 deletions
11
models.py
11
models.py
|
@ -273,7 +273,7 @@ class Player():
|
||||||
|
|
||||||
def fire(self,name,texture):
|
def fire(self,name,texture):
|
||||||
if (time()-self.last_fire> 1/max_fire_rate):
|
if (time()-self.last_fire> 1/max_fire_rate):
|
||||||
new_proj = Projectile(name,self.texture_proj,(self.posx,self.posy),20,self.degres_canon)
|
new_proj = Projectile(name,self.texture_proj,(self.posx,self.posy),20,self.degres_canon,50)
|
||||||
self.projectiles.append(new_proj)
|
self.projectiles.append(new_proj)
|
||||||
self.last_fire = time()
|
self.last_fire = time()
|
||||||
self.ammo = self.ammo -1
|
self.ammo = self.ammo -1
|
||||||
|
@ -296,6 +296,10 @@ class Enemy():
|
||||||
posy_screen = self.posy-offsety
|
posy_screen = self.posy-offsety
|
||||||
surface.blit(self.img,(posx_screen-self.rect.center[0],posy_screen-self.rect.center[1]))
|
surface.blit(self.img,(posx_screen-self.rect.center[0],posy_screen-self.rect.center[1]))
|
||||||
|
|
||||||
|
def touched(self, proj):
|
||||||
|
self.life -= proj.damage
|
||||||
|
print(f"life down to {self.life}")
|
||||||
|
|
||||||
def die(self,game,index):
|
def die(self,game,index):
|
||||||
print(f"{self.name} died with honor.")
|
print(f"{self.name} died with honor.")
|
||||||
del game.enemies[index]
|
del game.enemies[index]
|
||||||
|
@ -303,7 +307,8 @@ class Enemy():
|
||||||
|
|
||||||
class Projectile():
|
class Projectile():
|
||||||
|
|
||||||
def __init__(self,name,texture,position,speed,angle):
|
def __init__(self,name,texture,position,speed,angle,damage):
|
||||||
|
self.damage = damage
|
||||||
self.name = name
|
self.name = name
|
||||||
self.speed = speed
|
self.speed = speed
|
||||||
self.posx = position[0]
|
self.posx = position[0]
|
||||||
|
@ -340,6 +345,8 @@ class Projectile():
|
||||||
for k,enemy in enumerate(game.enemies):
|
for k,enemy in enumerate(game.enemies):
|
||||||
if enemy.mask.overlap(self.mask, (enemy.posx+enemy.rect.center[0]-self.posx-self.rect.center[0],enemy.posy+enemy.rect.center[1]-self.posy-self.rect.center[1])):
|
if enemy.mask.overlap(self.mask, (enemy.posx+enemy.rect.center[0]-self.posx-self.rect.center[0],enemy.posy+enemy.rect.center[1]-self.posy-self.rect.center[1])):
|
||||||
print("Impact on enemy {} at position {}".format(enemy.name,(enemy.posx,enemy.posy)))
|
print("Impact on enemy {} at position {}".format(enemy.name,(enemy.posx,enemy.posy)))
|
||||||
|
enemy.touched(self)
|
||||||
|
if enemy.life <= 0:
|
||||||
enemy.die(game,k)
|
enemy.die(game,k)
|
||||||
impact = True
|
impact = True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue