117 lines
4.8 KiB
Python
117 lines
4.8 KiB
Python
from gamedata.objects.base import BaseObject
|
|
from gamedata.objects.transition import Transition
|
|
|
|
class Results(BaseObject):
|
|
|
|
def __init__(self,game):
|
|
|
|
super().__init__(0,0,game)
|
|
|
|
self.maxcount = self.game.globals["totaltrashes"]
|
|
self.currentcount = 0
|
|
self.count = self.game.globals["trashes"]
|
|
|
|
self.lastlevel = self.game.globals["nblevels"]-1==self.game.globals["levelname"]
|
|
|
|
self.maxtime = self.game.globals["timetobeat"]
|
|
self.currenttime = 99
|
|
self.time = min(99,self.game.globals["timer"])
|
|
|
|
self.sparkles = game.getSpriteDir("particles/dust/")
|
|
self.medalsfx = self.game.sound_lib["sfx/select.wav"]
|
|
self.backsfx = self.game.sound_lib["sfx/return.wav"]
|
|
|
|
self.text = self.game.getchars("Cleared : 0 / "+str(self.maxcount))
|
|
self.levelname = self.game.getchars("Level "+str(self.game.globals["levelname"]+1))
|
|
self.levellore = None
|
|
txt = "Time : 0"
|
|
txt += " ( "+str(self.game.globals["timetobeat"])+" for medal )"
|
|
self.seconds = self.game.getchars(txt)
|
|
if self.game.globals["levellore"]:
|
|
self.levellore = self.game.getchars(self.game.globals["levellore"])
|
|
|
|
self.fill = self.game.pygame.Surface((self.game.globals["cameraw"],self.game.globals["camerah"]))
|
|
self.fill.fill([62,33,55])
|
|
|
|
self.fadetimer = self.game.lib.Timer(2)
|
|
self.faded = False
|
|
self.alphamax = 200
|
|
self.alpha = 0
|
|
|
|
self.medalwave = self.game.sprite_lib["medals/wave.png"]
|
|
self.medalclock= self.game.sprite_lib["medals/clock.png"]
|
|
self.medalwaveoff = self.game.sprite_lib["medals/waveoff.png"]
|
|
self.medalclockoff = self.game.sprite_lib["medals/clockoff.png"]
|
|
|
|
self.transition = False
|
|
|
|
self.depth = 3
|
|
|
|
self.centerx = self.game.globals["cameraw"]/2
|
|
self.centery = self.game.globals["camerah"]/2
|
|
|
|
def step(self):
|
|
|
|
past = int(self.currentcount)
|
|
self.currentcount+=self.game.dt
|
|
self.currentcount += (self.count - self.currentcount)*self.game.dt
|
|
self.currentcount = min(self.currentcount,self.count)
|
|
|
|
if int(self.currentcount)>past:
|
|
# Make a noise
|
|
self.text = self.game.getchars("Cleared : "+str(int(self.currentcount))+" / "+str(self.maxcount))
|
|
if self.currentcount == self.maxcount: # Spawn sparkles
|
|
self.game.addParticle(self.sparkles,self.centerx+150+self.game.globals["camerax"],self.centery+self.game.globals["cameray"],fps=6,depth=4)
|
|
self.medalsfx.play()
|
|
|
|
past = int(self.currenttime)
|
|
self.currenttime-=self.game.dt
|
|
self.currenttime+= (self.time- self.currenttime)*self.game.dt
|
|
self.currenttime= max(self.currenttime,self.time)
|
|
|
|
if int(self.currenttime)<past:
|
|
# Make a noise
|
|
txt = "Time : "+str(int(self.currenttime))
|
|
txt += " ( "+str(self.game.globals["timetobeat"])+" for medal )"
|
|
self.seconds = self.game.getchars(txt)
|
|
if int(self.time)==int(self.currenttime) and int(self.game.globals["timetobeat"]) >= int(self.currenttime): # Spawn sparkles
|
|
self.game.addParticle(self.sparkles,self.centerx+150+self.game.globals["camerax"],self.centery+20+self.game.globals["cameray"],fps=6,depth = 4)
|
|
self.medalsfx.play()
|
|
|
|
if not self.transition:
|
|
keys = ["up","down","left","right"]
|
|
for i in keys:
|
|
self.transition = self.transition or self.game.inputs["keys"][i]["timer"]==1
|
|
if self.transition:
|
|
t = Transition(self.game,endcinematic=self.lastlevel)
|
|
self.game.gameloop.summon(t)
|
|
self.backsfx.play()
|
|
|
|
if not self.faded:
|
|
self.alpha = (1-self.fadetimer.getratio())*self.alphamax
|
|
if self.fadetimer.tick(self.game.dt):
|
|
self.faded = True
|
|
else:
|
|
self.alpha = self.alphamax
|
|
|
|
def draw(self):
|
|
self.fill.set_alpha(self.alpha)
|
|
self.game.window.blit(self.fill,[0,0])
|
|
|
|
cx,cy = self.centerx,self.centery
|
|
|
|
self.game.lib.drawcenter(self.game,self.levelname,cx,cy-50) # Level names
|
|
if self.levellore:
|
|
self.game.lib.drawcenter(self.game,self.levellore,cx,cy-39)
|
|
|
|
self.game.lib.drawcenter(self.game,self.text,cx,cy) # Clean
|
|
self.game.lib.drawcenter(self.game,self.seconds,cx,cy+20)
|
|
medal = self.medalwaveoff
|
|
if self.currentcount == self.maxcount: # Medals
|
|
medal = self.medalwave
|
|
self.game.lib.drawcenter(self.game,medal,cx+150,cy)
|
|
medal = self.medalclockoff
|
|
if int(self.time)==int(self.currenttime) and int(self.game.globals["timetobeat"]) >= int(self.currenttime):
|
|
medal = self.medalclock
|
|
self.game.lib.drawcenter(self.game,medal,cx+150,cy+20)
|