Added new highscore display

This commit is contained in:
theo@manjaro 2021-09-16 09:33:38 +02:00
parent 5494a23541
commit 43ff99dc1f

View File

@ -28,16 +28,21 @@ class GameOver(BaseObject):
self.color = [255]*3
self.scale = 1
# Highscore texts
self.highscorewhite = game.fontfilebig.render("New Highscore !",False,[255]*3)
self.highscoreflash = game.fontfilebig.render("New Highscore !",False,[255,230,55])
self.flashtimer = game.lib.Timer(0.4)
def step(self):
self.displayscore+=(self.game.globals["score"]-self.displayscore)*self.game.dt*0.4+self.game.dt*2
self.displayscore = min(self.game.globals["score"],self.displayscore)
colorvalue = self.displayscore*1.5
colorvalue = self.displayscore*0.9
self.scale = min(2,colorvalue**0.9/250+1)
if colorvalue>255: # Green to red
colorvalue-=255
colorvalue = min(255,colorvalue**0.99)
colorvalue = min(255,colorvalue**0.95)
self.color = [colorvalue,255-colorvalue,0]
else: # White to green
self.color = [255-colorvalue,255,255-colorvalue]
@ -45,14 +50,27 @@ class GameOver(BaseObject):
if not self.launched and int(self.displayscore)==int(self.game.globals["score"]):
if self.launchtimer.tick(self.game.dt):
# Launch particles
pass
self.launched = True
if self.launched:
self.flashtimer.tick(self.game.dt)
if self.game.inputs["mouse"]["click"]==1:
# skip animation
self.displayscore = int(self.game.globals["score"])
def draw(self):
# Display score and highscore
# Display score
txt = self.game.fontfilebig.render("Score : "+str(int(self.displayscore)),False,self.color)
txt = self.game.pygame.transform.scale(txt,(round(txt.get_width()*self.scale),round(txt.get_height()*self.scale)))
self.game.lib.drawcenter(self.game,txt,self.game.DISPLAY_WIDTH/2,self.game.DISPLAY_HEIGHT*0.4)
# Display new highscore
if self.highscore:
txt = [self.highscorewhite,self.highscoreflash][self.flashtimer.getloops()%2]
if not self.launched:
txt.set_alpha((1-self.launchtimer.getratio())**2*255)
else:
txt.set_alpha(255)
self.game.lib.drawcenter(self.game,txt,self.game.DISPLAY_WIDTH/2,self.game.DISPLAY_HEIGHT*0.6)