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

89 lines
3.3 KiB
Python
Raw Normal View History

2021-11-21 12:28:27 +01:00
from gamedata.objects.ingame.movable import Movable
2021-11-17 15:01:25 +01:00
class Ennemy(Movable):
2021-11-18 17:58:38 +01:00
def __init__(self,x,y,game,nodes,customvalues):
2021-11-17 15:01:25 +01:00
super().__init__(game,x,y)
self.player = None
2021-11-24 19:59:23 +01:00
self.damage = 1
2021-11-17 15:30:46 +01:00
self.respawnmargin = 30
self.respawn = True
2021-11-27 19:18:25 +01:00
self.autorespawn = False
2021-11-17 15:30:46 +01:00
self.dead = False
2021-11-17 16:14:29 +01:00
self.particleoffsetx = 0
self.particleoffsety = 0
2021-11-17 16:42:10 +01:00
self.canhit = True
2021-11-18 09:12:09 +01:00
self.candie = True
self.cancombo = True
2021-11-17 16:42:10 +01:00
2021-11-25 15:11:23 +01:00
self.onscreen = True
2021-11-18 17:58:38 +01:00
self.nodes = nodes
self.customvalues = customvalues
2021-11-17 15:16:07 +01:00
self.dustparticles = game.getSpriteDir("particles/dust/")
2021-11-24 15:47:52 +01:00
def deadtrigger(self):
pass
2021-11-17 15:01:25 +01:00
def step(self):
2021-11-25 15:11:23 +01:00
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
2021-11-17 15:30:46 +01:00
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:
2021-11-17 16:42:10 +01:00
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
2021-11-24 19:59:23 +01:00
self.player.yeet(hor*6,self.player.gravityway*-3,dmg=self.damage)
2021-11-18 09:12:09 +01:00
if self.candie and self.player.canhit:
2021-11-17 15:30:46 +01:00
if self.rect.colliderect(self.player.hitrect):
# Die
self.dead = True
2021-11-24 15:47:52 +01:00
self.deadtrigger()
2021-11-17 15:30:46 +01:00
# Add particles
2021-11-17 16:14:29 +01:00
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
2021-11-17 15:30:46 +01:00
# 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
2021-11-18 09:16:03 +01:00
if not self.player.fastfall:
self.player.canfastfall = True
2021-11-18 09:12:09 +01:00
self.player.upcombo()
2021-11-17 15:30:46 +01:00
elif self.respawn:
2021-11-25 15:11:23 +01:00
if not self.onscreen:
self.dead = False
2021-11-27 19:18:25 +01:00
if self.autorespawn:
if self.autorespawn.tick(self.game.dt):
self.dead = False
self.autorespawn.reset()
2021-11-17 15:01:25 +01:00
else:
2021-11-17 15:30:46 +01:00
self.game.gameloop.delid(self.id)