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

29 lines
925 B
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
def step(self):
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.game.gameloop.delid(self.id)
# 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