from gamedata.objects.ingame.ennemies.ennemy import Ennemy from gamedata.objects.results import Results class EndFlag(Ennemy): def __init__(self,*args): super().__init__(*args) self.blueflags = self.game.getSpriteDir("flags/blue/") self.greenflags = self.game.getSpriteDir("flags/green/") self.confettis = {} self.confettiscolors = ["red","blue","yellow"] for i in self.confettiscolors: self.confettis[i] = self.game.getSpriteDir("particles/confetti/"+i+"/") self.sprites = self.blueflags self.depth = -1 self.spriteindex = 0 self.animspeed = 10 self.rect[2],self.rect[3] = self.sprites[0].get_size() self.candie = False self.canhit = False self.endtimer = self.game.lib.Timer(0.5) self.ended = False self.sfx = self.game.sound_lib["sfx/win.wav"] def step(self): super().step() self.spriteindex+=self.animspeed*self.game.dt if self.player: if self.player.rect.colliderect(self.rect): self.sprites = self.greenflags self.player.canmove = False if self.player.tileset.bgm: self.player.tileset.bgm.stop() if not self.ended: self.ended = True nb = 30 for i in range(nb): color = self.game.lib.choice(self.confettiscolors) sprites = self.confettis[color] velx = self.game.lib.randint(-1,1) vely = self.game.lib.randint(-5,-4)/3 steps = 5 offsetx = self.game.lib.randint(-10*steps,10*steps)/(steps) offsety = self.game.lib.randint(-5,5) self.game.addParticle(sprites,self.rect.center[0]+offsetx,self.rect.center[1]+offsety,velx=velx,vely=vely,modvely=0.1,fps=2) if not self.game.globals["levelname"] in self.game.globals["finishedlevels"]: self.game.globals["finishedlevels"].append(self.game.globals["levelname"]) if self.game.globals["totaltrashes"]==self.game.globals["trashes"]: if not self.game.globals["levelname"] in self.game.globals["completedlevels"]: self.game.globals["completedlevels"].append(self.game.globals["levelname"]) if int(self.game.globals["timetobeat"])>=int(self.game.globals["timer"]): if not self.game.globals["levelname"] in self.game.globals["speedrunlevels"]: self.game.globals["speedrunlevels"].append(self.game.globals["levelname"]) self.sfx.play() if self.ended: if self.endtimer.tick(self.game.dt) and self.endtimer.getloops()<2: r = Results(self.game) self.game.gameloop.summon(r) def draw(self): sprite = self.sprites[int(self.spriteindex)%len(self.sprites)] self.game.window.blit(sprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]])