diff --git a/models.py b/models.py index da60e32..3c56030 100644 --- a/models.py +++ b/models.py @@ -273,7 +273,7 @@ class Player(): def fire(self,name,texture): 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.last_fire = time() self.ammo = self.ammo -1 @@ -296,6 +296,10 @@ class Enemy(): posy_screen = self.posy-offsety 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): print(f"{self.name} died with honor.") del game.enemies[index] @@ -303,7 +307,8 @@ class Enemy(): 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.speed = speed self.posx = position[0] @@ -340,7 +345,9 @@ class Projectile(): 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])): print("Impact on enemy {} at position {}".format(enemy.name,(enemy.posx,enemy.posy))) - enemy.die(game,k) + enemy.touched(self) + if enemy.life <= 0: + enemy.die(game,k) impact = True return impact \ No newline at end of file