Overflown/gamedata/objects/ingame/endflag.py

75 lines
3.2 KiB
Python
Raw Normal View History

2021-11-23 11:11:13 +01:00
from gamedata.objects.ingame.ennemies.ennemy import Ennemy
2021-11-24 15:47:52 +01:00
from gamedata.objects.results import Results
2021-11-23 11:11:13 +01:00
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
2021-11-23 11:24:59 +01:00
self.endtimer = self.game.lib.Timer(0.5)
2021-11-23 11:11:13 +01:00
self.ended = False
2021-11-23 17:55:48 +01:00
self.sfx = self.game.sound_lib["sfx/win.wav"]
2021-11-23 11:11:13 +01:00
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
2021-11-25 08:11:08 +01:00
if self.player.tileset.bgm:
self.player.tileset.bgm.stop()
2021-11-23 11:11:13 +01:00
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)
2021-11-23 18:08:17 +01:00
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"])
2021-11-24 15:47:52 +01:00
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"])
2021-11-23 17:55:48 +01:00
self.sfx.play()
2021-11-23 11:11:13 +01:00
if self.ended:
2021-11-24 15:47:52 +01:00
if self.endtimer.tick(self.game.dt) and self.endtimer.getloops()<2:
r = Results(self.game)
self.game.gameloop.summon(r)
2021-11-23 11:11:13 +01:00
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"]])