Unlocks showing on gameover and options
This commit is contained in:
parent
0f8d3f6883
commit
9276b216ae
@ -16,12 +16,25 @@ class GameOver(BaseObject):
|
|||||||
|
|
||||||
# Updating highscore
|
# Updating highscore
|
||||||
self.highscore = False
|
self.highscore = False
|
||||||
|
self.newunlocks = []
|
||||||
if game.globals["highscore"]<game.globals["score"]:
|
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"]
|
game.globals["highscore"] = game.globals["score"]
|
||||||
self.highscore = True
|
self.highscore = True
|
||||||
|
|
||||||
self.game.lib.savescore(self.game.datadir,self.game.globals["highscore"],self.game.dataname)
|
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.displayscore = 0
|
||||||
|
|
||||||
self.launched = False
|
self.launched = False
|
||||||
@ -31,8 +44,11 @@ class GameOver(BaseObject):
|
|||||||
self.scale = 1
|
self.scale = 1
|
||||||
|
|
||||||
# Highscore texts
|
# Highscore texts
|
||||||
self.highscorewhite = game.fontfilebig.render("New Highscore !",False,[255]*3)
|
text = "New Highscore !"
|
||||||
self.highscoreflash = game.fontfilebig.render("New Highscore !",False,[255,230,55])
|
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)
|
self.flashtimer = game.lib.Timer(0.4)
|
||||||
|
|
||||||
def step(self):
|
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)
|
self.game.lib.drawcenter(self.game,txt,self.game.DISPLAY_WIDTH/2,self.game.DISPLAY_HEIGHT*0.4)
|
||||||
# Display new highscore
|
# Display new highscore
|
||||||
if self.highscore:
|
if self.highscore:
|
||||||
txt = [self.highscorewhite,self.highscoreflash][self.flashtimer.getloops()%2]
|
|
||||||
if not self.launched:
|
if not self.launched:
|
||||||
txt.set_alpha((1-self.launchtimer.getratio())**2*255)
|
alpha = (1-self.launchtimer.getratio())**2*255
|
||||||
else:
|
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)
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ from gamedata.objects.ingame.demo import Demo
|
|||||||
class Manager(BaseObject):
|
class Manager(BaseObject):
|
||||||
def __init__(self,game):
|
def __init__(self,game):
|
||||||
super().__init__(0,0,game)
|
super().__init__(0,0,game)
|
||||||
self.score = 0
|
self.score = 250
|
||||||
self.lives = 5
|
self.lives = 5
|
||||||
self.basetime = 10
|
self.basetime = 10
|
||||||
self.steptime = 2
|
self.steptime = 2
|
||||||
@ -43,7 +43,7 @@ class Manager(BaseObject):
|
|||||||
|
|
||||||
# Unlocks
|
# Unlocks
|
||||||
self.skins = game.lib.getunlocks(self.game.globals["highscore"])
|
self.skins = game.lib.getunlocks(self.game.globals["highscore"])
|
||||||
|
|
||||||
# Spawn the first batch
|
# 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))
|
||||||
self.game.gameloop.summon(Spawner(self.game,self.tiles,skins=self.skins))
|
self.game.gameloop.summon(Spawner(self.game,self.tiles,skins=self.skins))
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import gamedata.objects.menu.menu as menu
|
import gamedata.objects.menu.menu as menu
|
||||||
|
import math
|
||||||
|
|
||||||
class OptionMenu(menu.Menu):
|
class OptionMenu(menu.Menu):
|
||||||
def __init__(self,x,y,game,w=100,h=100):
|
def __init__(self,x,y,game,w=100,h=100):
|
||||||
@ -18,8 +19,15 @@ class OptionMenu(menu.Menu):
|
|||||||
|
|
||||||
self.depth = -1
|
self.depth = -1
|
||||||
|
|
||||||
self.highscore = self.game.fontfile.render(f"Highscore : {self.game.globals['highscore']}",False,[255,230,50])
|
# Getting the number of unlocks ( minus 1 because the base skin isn't really an "unlock" )
|
||||||
self.highscoreblack= self.game.fontfile.render(f"Highscore : {self.game.globals['highscore']}",False,[0,0,0])
|
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):
|
def draw(self):
|
||||||
margin = 2
|
margin = 2
|
||||||
|
Loading…
Reference in New Issue
Block a user