45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
from gamedata.objects.ingame.ennemies.ennemy import Ennemy
|
|
from gamedata.objects.ingame.ennemies.projectile import Projectile
|
|
|
|
class Shooter(Ennemy):
|
|
|
|
def __init__(self,*args):
|
|
|
|
super().__init__(*args)
|
|
|
|
self.sprites = self.game.getSpriteDir("shooter/")
|
|
self.projectilesprite = self.game.getSpriteDir("shooter/spike.png")
|
|
self.sprite = self.sprites[0]
|
|
self.spriteindex = 0
|
|
self.animspeed = 6
|
|
|
|
self.rect[2],self.rect[3] = self.sprite.get_size()
|
|
|
|
self.rect[0]+=(16-self.rect[2])/2
|
|
self.rect[1]+=(16-self.rect[3])/2
|
|
|
|
self.shoottimer = self.game.lib.Timer(2)
|
|
|
|
self.candie = False
|
|
|
|
def step(self):
|
|
|
|
if self.spriteindex == 0:
|
|
self.sprite = self.sprites[0]
|
|
if self.shoottimer.tick(self.game.dt):
|
|
self.spriteindex+=self.animspeed*self.game.dt
|
|
# Shoot
|
|
p = Projectile(self.rect.center[0],self.rect.center[1],self.game,self.nodes,self.customvalues)
|
|
self.game.gameloop.summon(p)
|
|
else:
|
|
self.spriteindex+=self.animspeed*self.game.dt
|
|
self.sprite = self.sprites[int(self.spriteindex)%len(self.sprites)]
|
|
if int(self.spriteindex)>=len(self.sprites):
|
|
self.spriteindex = 0
|
|
|
|
super().step()
|
|
|
|
def draw(self):
|
|
sprite = self.game.pygame.transform.flip(self.sprite,self.customvalues["flip"],False)
|
|
self.game.window.blit(sprite,(self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]))
|