Overflown/gamedata/objects/combat/ennemies/ennemy.py

49 lines
1.8 KiB
Python

from gamedata.objects.combat.movable import Movable
class Ennemy(Movable):
def __init__(self,x,y,game,nodes=None):
super().__init__(game,x,y)
self.player = None
self.respawnmargin = 30
self.respawn = True
self.dead = False
self.dustparticles = game.getSpriteDir("particles/dust/")
def step(self):
if not self.dead:
super().step()
# Check for collision with player
if not self.player:
self.player = next(iter(self.game.gameloop.findname("Player")),None)
else:
if self.player.canhit:
if self.rect.colliderect(self.player.hitrect):
# Die
self.dead = True
# Add particles
self.game.addParticle(self.dustparticles,self.rect.center[0],self.rect.center[1]) # Dust
self.game.addParticle([self.deadsprite],self.rect.center[0],self.rect.center[1],fps=0.6,vely=-1.5,modvely=0.15) # Die sprite
# Boost the player vertically
if not self.player.fastfall:
if self.player.rect[1]>self.rect[1]:
direction = 1
else:
direction = -1
self.player.verspd = self.player.gravity/3*direction
elif self.respawn:
if self.rect.center[0] < self.game.globals["camerax"]-self.respawnmargin:
self.dead = False # Respawn
if self.rect.center[0] > self.game.globals["camerax"]+self.game.globals["cameraw"]+self.respawnmargin:
self.dead = False # Respawn
else:
self.game.gameloop.delid(self.id)