Overflown/gamedata/objects/results.py

115 lines
4.7 KiB
Python
Raw Normal View History

2021-11-24 15:47:52 +01:00
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"]
2021-11-25 09:21:42 +01:00
self.maxtime = self.game.globals["timetobeat"]
self.currenttime = 99
self.time = min(99,self.game.globals["timer"])
self.sparkles = game.getSpriteDir("particles/dust/")
2021-11-26 16:28:28 +01:00
self.medalsfx = self.game.sound_lib["sfx/select.wav"]
self.backsfx = self.game.sound_lib["sfx/return.wav"]
2021-11-25 09:21:42 +01:00
2021-11-24 15:47:52 +01:00
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
2021-11-25 09:21:42 +01:00
txt = "Time : 0"
2021-11-24 15:47:52 +01:00
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"]
2021-11-25 09:21:42 +01:00
self.medalwaveoff = self.game.sprite_lib["medals/waveoff.png"]
self.medalclockoff = self.game.sprite_lib["medals/clockoff.png"]
2021-11-24 15:47:52 +01:00
self.transition = False
self.depth = 3
2021-11-25 09:21:42 +01:00
self.centerx = self.game.globals["cameraw"]/2
self.centery = self.game.globals["camerah"]/2
2021-11-24 15:47:52 +01:00
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))
2021-11-25 09:21:42 +01:00
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)
2021-11-26 16:28:28 +01:00
self.medalsfx.play()
2021-11-25 09:21:42 +01:00
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)
2021-11-26 16:28:28 +01:00
self.medalsfx.play()
2021-11-24 15:47:52 +01:00
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)
2021-11-26 16:28:28 +01:00
self.backsfx.play()
2021-11-24 15:47:52 +01:00
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])
2021-11-25 09:21:42 +01:00
cx,cy = self.centerx,self.centery
2021-11-24 15:47:52 +01:00
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)
2021-11-25 09:21:42 +01:00
medal = self.medalwaveoff
2021-11-24 15:47:52 +01:00
if self.currentcount == self.maxcount: # Medals
2021-11-25 09:21:42 +01:00
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)