Unlocks showing on gameover and options

This commit is contained in:
theo@manjaro 2021-09-18 18:56:17 +02:00
parent 0f8d3f6883
commit 9276b216ae
3 changed files with 42 additions and 9 deletions

View File

@ -16,12 +16,25 @@ class GameOver(BaseObject):
# Updating highscore
self.highscore = False
self.newunlocks = []
if game.globals["highscore"]<game.globals["score"]:
self.pastunlocks = game.lib.getunlocks(game.globals["highscore"])
self.currentunlocks = game.lib.getunlocks(game.globals["score"])
game.globals["highscore"] = game.globals["score"]
self.highscore = True
self.game.lib.savescore(self.game.datadir,self.game.globals["highscore"],self.game.dataname)
# Get if there's an unlock
self.newunlocks = []
self.unlocksprites = {}
for unlocktype in ["normal","specials"]:
for unlock in self.currentunlocks[unlocktype]:
if not unlock in self.pastunlocks[unlocktype]:
self.newunlocks.append(unlock)
sprite = game.sprite_lib["lemmings/"+unlock+"/falling.png"]
self.unlocksprites[unlock] = game.pygame.transform.scale(sprite,[sprite.get_width()*3,sprite.get_height()*3])
self.displayscore = 0
self.launched = False
@ -31,8 +44,11 @@ class GameOver(BaseObject):
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])
text = "New Highscore !"
if len(self.newunlocks)>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)

View File

@ -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

View File

@ -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