From 9276b216ae991ef4a7d9976f2d1599fd6fec9eca Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Sat, 18 Sep 2021 18:56:17 +0200 Subject: [PATCH] Unlocks showing on gameover and options --- gamedata/objects/gameover.py | 35 ++++++++++++++++++++++++----- gamedata/objects/ingame/manager.py | 4 ++-- gamedata/objects/menu/optionmenu.py | 12 ++++++++-- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/gamedata/objects/gameover.py b/gamedata/objects/gameover.py index 39782ac..5618955 100644 --- a/gamedata/objects/gameover.py +++ b/gamedata/objects/gameover.py @@ -16,12 +16,25 @@ class GameOver(BaseObject): # Updating highscore self.highscore = False + self.newunlocks = [] if game.globals["highscore"]0: + text+=" You unlocked :" + self.highscorewhite = game.fontfilebig.render(text,False,[255]*3) + self.highscoreflash = game.fontfilebig.render(text,False,[255,230,55]) self.flashtimer = game.lib.Timer(0.4) def step(self): @@ -68,11 +84,20 @@ class GameOver(BaseObject): 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) + alpha = (1-self.launchtimer.getratio())**2*255 else: - txt.set_alpha(255) + alpha = 255 + txt = [self.highscorewhite,self.highscoreflash][self.flashtimer.getloops()%2] + txt.set_alpha(alpha) self.game.lib.drawcenter(self.game,txt,self.game.DISPLAY_WIDTH/2,self.game.DISPLAY_HEIGHT*0.6) + # Draw unlocks + for i in range(len(self.newunlocks)): + posx = self.game.DISPLAY_WIDTH/(len(self.newunlocks)+1)*(i+1) + posy = self.game.DISPLAY_HEIGHT*0.7 + sprite = self.unlocksprites[self.newunlocks[i]] + sprite.set_alpha(alpha) + self.game.lib.drawcenter(self.game,sprite,posx,posy) + diff --git a/gamedata/objects/ingame/manager.py b/gamedata/objects/ingame/manager.py index a7e030b..089e588 100644 --- a/gamedata/objects/ingame/manager.py +++ b/gamedata/objects/ingame/manager.py @@ -8,7 +8,7 @@ from gamedata.objects.ingame.demo import Demo class Manager(BaseObject): def __init__(self,game): super().__init__(0,0,game) - self.score = 0 + self.score = 250 self.lives = 5 self.basetime = 10 self.steptime = 2 @@ -43,7 +43,7 @@ class Manager(BaseObject): # Unlocks self.skins = game.lib.getunlocks(self.game.globals["highscore"]) - + # Spawn the first batch self.game.gameloop.summon(Spawner(self.game,self.tiles,skins=self.skins)) self.game.gameloop.summon(Spawner(self.game,self.tiles,skins=self.skins)) diff --git a/gamedata/objects/menu/optionmenu.py b/gamedata/objects/menu/optionmenu.py index 4a5a8a2..34aab27 100644 --- a/gamedata/objects/menu/optionmenu.py +++ b/gamedata/objects/menu/optionmenu.py @@ -1,4 +1,5 @@ import gamedata.objects.menu.menu as menu +import math class OptionMenu(menu.Menu): def __init__(self,x,y,game,w=100,h=100): @@ -18,8 +19,15 @@ class OptionMenu(menu.Menu): self.depth = -1 - self.highscore = self.game.fontfile.render(f"Highscore : {self.game.globals['highscore']}",False,[255,230,50]) - self.highscoreblack= self.game.fontfile.render(f"Highscore : {self.game.globals['highscore']}",False,[0,0,0]) + # Getting the number of unlocks ( minus 1 because the base skin isn't really an "unlock" ) + unlocks = game.lib.getunlocks(game.globals["highscore"]) + currentunlocks = len(unlocks["normal"]+unlocks["specials"])-1 + unlocks = game.lib.getunlocks(math.inf) + totalunlocks= len(unlocks["normal"]+unlocks["specials"])-1 + + text = f"Highscore : {self.game.globals['highscore']} Unlocks : {currentunlocks}/{totalunlocks}" + self.highscore = self.game.fontfile.render(text,False,[255,230,50]) + self.highscoreblack= self.game.fontfile.render(text,False,[0,0,0]) def draw(self): margin = 2