Overflown/gamedata/objects/results.py

79 lines
3.0 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.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 : "+str(int(self.game.globals["timer"]))
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.transition = False
self.depth = 3
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 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)
self.game.gameloop.summon(t)
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 = self.game.globals["cameraw"]/2
cy = self.game.globals["camerah"]/2
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)
if self.currentcount == self.maxcount: # Medals
self.game.lib.drawcenter(self.game,self.medalwave,cx+150,cy)
if int(self.game.globals["timetobeat"]) >= int(self.game.globals["timer"]):
self.game.lib.drawcenter(self.game,self.medalclock,cx+150,cy+20)