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

61 lines
1.9 KiB
Python
Raw Normal View History

2021-11-16 23:36:56 +01:00
from gamedata.objects.combat.movable import Movable
class Robot(Movable):
def __init__(self,x,y,game,nodes=None):
super().__init__(game,x,y)
self.sprites = game.getSpriteDir("robot/")
self.sprite = self.sprites[0]
self.deadsprite = 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.gravityway = 1 # Vertical flip
self.walkingway = 1 # Horizontal flip
# Offset it correctly
self.rect[0] = x+8-self.rect[2]/2
# Movement boundaries
if nodes:
self.endpoints = [x["x"] for x in nodes[:2]] # Get only x positions
self.endpoints.sort()
else:
self.endpoints = None
def step(self):
# 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
super().step() # Actually move
self.spriteindex += self.speed*self.game.dt*0.15
def draw(self):
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"]])