75 lines
2.1 KiB
Python
75 lines
2.1 KiB
Python
from gamedata.objects.ingame.ennemies.ennemy import Ennemy
|
|
|
|
class Squid(Ennemy):
|
|
|
|
def __init__(self,*args):
|
|
|
|
super().__init__(*args)
|
|
|
|
self.sprites = self.game.getSpriteDir("squid/")
|
|
self.sprite = self.sprites[0]
|
|
self.deadsprite = self.game.sprite_lib["squid/death.png"]
|
|
|
|
self.rect[2],self.rect[3] = self.deadsprite.get_size()
|
|
|
|
self.flip = False
|
|
|
|
self.speed = 40
|
|
self.spriteindex = 0
|
|
|
|
self.respawn = False
|
|
|
|
self.fallingway = 1 # Horizontal flip
|
|
|
|
# Offset it correctly
|
|
self.rect[1] += 8-self.rect[3]/2
|
|
|
|
self.collisions = False
|
|
|
|
# Movement boundaries
|
|
if self.nodes:
|
|
self.endpoints = [x["y"] for x in self.nodes[:2]] # Get only the two first y positions
|
|
self.endpoints.sort()
|
|
else:
|
|
self.endpoints = None
|
|
|
|
self.game.globals["totaltrashes"]+=1
|
|
|
|
def deadtrigger(self):
|
|
self.game.globals["trashes"]+=1
|
|
|
|
def step(self):
|
|
|
|
if not self.dead:
|
|
|
|
# Flipping horizontally
|
|
if self.endpoints:
|
|
if self.rect.center[1]<self.endpoints[0]:
|
|
self.fallingway = 1
|
|
if self.rect.center[1]>self.endpoints[1]:
|
|
self.fallingway = -1
|
|
|
|
speedmult = [0.5,0,2][int(self.spriteindex)%len(self.sprites)]
|
|
|
|
if self.fallingway<0:
|
|
self.verspd = self.speed*self.game.dt*speedmult*-1
|
|
else:
|
|
self.verspd += self.speed*self.game.dt/10
|
|
|
|
self.spriteindex += self.speed*self.game.dt*0.15
|
|
|
|
if self.player:
|
|
self.flip = self.player.rect.center[0]>self.rect.center[0]
|
|
|
|
super().step() # Actually move
|
|
|
|
|
|
def draw(self):
|
|
|
|
if not self.dead:
|
|
self.sprite = self.sprites[int(self.spriteindex)%len(self.sprites)]
|
|
if self.fallingway>0:
|
|
self.sprite = self.sprites[1]
|
|
sprite = self.game.pygame.transform.flip(self.sprite,self.flip,False)
|
|
self.game.window.blit(sprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]])
|