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

84 lines
3.1 KiB
Python

from gamedata.objects.ingame.movable import Movable
class Ennemy(Movable):
def __init__(self,x,y,game,nodes,customvalues):
super().__init__(game,x,y)
self.player = None
self.damage = 1
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.onscreen = True
self.nodes = nodes
self.customvalues = customvalues
self.dustparticles = game.getSpriteDir("particles/dust/")
def deadtrigger(self):
pass
def step(self):
self.onscreen = True
if self.rect.center[0] < self.game.globals["camerax"]-self.respawnmargin:
self.onscreen = False
if self.rect.center[0] > self.game.globals["camerax"]+self.game.globals["cameraw"]+self.respawnmargin:
self.onscreen = False
if self.rect.center[1] < self.game.globals["cameray"]-self.respawnmargin:
self.onscreen = False
if self.rect.center[1] > self.game.globals["cameray"]+self.game.globals["camerah"]+self.respawnmargin:
self.onscreen = False
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.yeet(hor*6,self.player.gravityway*-3,dmg=self.damage)
if self.candie and self.player.canhit:
if self.rect.colliderect(self.player.hitrect):
# Die
self.dead = True
self.deadtrigger()
# 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 not self.onscreen:
self.dead = False
else:
self.game.gameloop.delid(self.id)