from gamedata.objects.base import BaseObject from gamedata.objects.button import Button class GameOver(BaseObject): def __init__(self,game): super().__init__(0,0,game) # Back button function def fnBack(self,game): game.scene = game.scenes.main # Creating the back button btn = Button(int(game.DISPLAY_WIDTH/4),int(game.DISPLAY_HEIGHT*0.8),game,game.DISPLAY_WIDTH//2,int(game.DISPLAY_HEIGHT*0.1)) btn.text = "Back" btn.click = fnBack game.gameloop.summon(btn) # Updating highscore self.highscore = False if game.globals["highscore"]255: # Green to red colorvalue-=255 colorvalue = min(255,colorvalue**0.95) 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 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 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)