69 lines
2.7 KiB
Python
69 lines
2.7 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.particleoffsetx = 0
|
|
self.particleoffsety = 0
|
|
|
|
self.canhit = True
|
|
self.candie = True
|
|
self.cancombo = True
|
|
|
|
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.canhit:
|
|
if self.rect.colliderect(self.player):
|
|
# Knock it horizontally
|
|
if self.player.rect[0]>self.rect[0]:
|
|
hor = 1
|
|
else:
|
|
hor = -1
|
|
self.player.horkb = hor*6
|
|
self.player.verkb = self.player.gravityway*-3
|
|
self.player.combo = 0
|
|
if self.candie and 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.particleoffsetx,self.rect.center[1]+self.particleoffsety) # Dust
|
|
self.game.addParticle([self.deadsprite],self.rect.center[0]+self.particleoffsetx,self.rect.center[1]+self.particleoffsety,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
|
|
if not self.player.fastfall:
|
|
self.player.canfastfall = True
|
|
self.player.upcombo()
|
|
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)
|