72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
from gamedata.objects.ingame.ennemies.ennemy import Ennemy
|
|
|
|
class Robot(Ennemy):
|
|
|
|
def __init__(self,*args):
|
|
|
|
super().__init__(*args)
|
|
|
|
self.sprites = self.game.getSpriteDir("robot/")
|
|
self.sprite = self.sprites[0]
|
|
self.deadsprite = self.game.sprite_lib["robot/death.png"]
|
|
|
|
self.rect[2],self.rect[3] = self.deadsprite.get_size()
|
|
|
|
self.speed = 30
|
|
self.falling = 20
|
|
self.spriteindex = 0
|
|
|
|
self.respawn = False
|
|
|
|
self.gravityway = 1 # Vertical flip
|
|
self.walkingway = 1 # Horizontal flip
|
|
|
|
# Offset it correctly
|
|
self.rect[0] += 8-self.rect[2]/2
|
|
|
|
# Movement boundaries
|
|
if self.nodes:
|
|
self.endpoints = [x["x"] for x in self.nodes[:2]] # Get only x 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 vertically
|
|
if self.water and self.rect.center[1]>self.water.rect[1]:
|
|
self.gravityway = -1
|
|
else:
|
|
self.gravityway = 1
|
|
|
|
# Flipping horizontally
|
|
if self.endpoints:
|
|
if self.rect.center[0]>self.endpoints[1]:
|
|
self.walkingway = -1
|
|
if self.rect.center[0]<self.endpoints[0]:
|
|
self.walkingway = 1
|
|
|
|
speedmult = [1,0.5,0][int(self.spriteindex)%3]
|
|
|
|
self.horspd = self.walkingway*self.speed*self.game.dt*speedmult
|
|
self.verspd = self.gravityway*self.falling*self.game.dt
|
|
|
|
self.spriteindex += self.speed*self.game.dt*0.15
|
|
|
|
super().step() # Actually move
|
|
|
|
|
|
def draw(self):
|
|
|
|
if not self.dead:
|
|
self.sprite = self.sprites[int(self.spriteindex)%len(self.sprites)]
|
|
drawnsprite = self.game.pygame.transform.flip(self.sprite,self.walkingway==-1,self.gravityway==-1)
|
|
self.game.window.blit(drawnsprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]])
|