Added score display on game over

This commit is contained in:
theo@manjaro 2021-09-16 09:11:55 +02:00
parent 16c0e57376
commit 5494a23541
2 changed files with 35 additions and 1 deletions

View File

@ -20,6 +20,39 @@ class GameOver(BaseObject):
game.globals["highscore"] = game.globals["score"]
self.highscore = True
self.displayscore = 0
self.launched = False
self.launchtimer = game.lib.Timer(0.5)
self.color = [255]*3
self.scale = 1
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
self.scale = min(2,colorvalue**0.9/250+1)
if colorvalue>255: # Green to red
colorvalue-=255
colorvalue = min(255,colorvalue**0.99)
self.color = [colorvalue,255-colorvalue,0]
else: # White to green
self.color = [255-colorvalue,255,255-colorvalue]
if not self.launched and int(self.displayscore)==int(self.game.globals["score"]):
if self.launchtimer.tick(self.game.dt):
# Launch particles
pass
if self.game.inputs["mouse"]["click"]==1:
# skip animation
self.displayscore = int(self.game.globals["score"])
def draw(self):
# Display score and highscore
pass
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)

View File

@ -53,6 +53,7 @@ class Manager(BaseObject):
# Game over
if self.endtimer.tick(self.game.dt):
self.game.globals["score"] = self.score
print(self.game.globals["score"])
self.game.scenes.gameover(self.game)
if self.invincible: