diff --git a/gamedata/game.py b/gamedata/game.py index 6b7cb82..d26d1cd 100644 --- a/gamedata/game.py +++ b/gamedata/game.py @@ -49,6 +49,7 @@ class Game(): self.globals["scamerax"] = 3 self.globals["scameray"] = 0 self.globals["debug"] = True + self.globals["highscore"] = 0 self.scaleCamera() settings = {"sfx":1,"bgm":1} diff --git a/gamedata/objects/gameover.py b/gamedata/objects/gameover.py new file mode 100644 index 0000000..0054e64 --- /dev/null +++ b/gamedata/objects/gameover.py @@ -0,0 +1,25 @@ +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"]0 and nblemmings>0 and self.spawntimer.tick(self.game.dt): - self.game.gameloop.summon(Spawner(self.game,self.tiles,speedmargin=int(self.speedmargin+0.5))) - self.spawntimer = self.game.lib.Timer(self.basetime+nblemmings*self.steptime) + if (self.lives>0 and nblemmings>0): + if self.spawntimer.tick(self.game.dt): + self.game.gameloop.summon(Spawner(self.game,self.tiles,speedmargin=int(self.speedmargin+0.5))) + self.spawntimer = self.game.lib.Timer(self.basetime+nblemmings*self.steptime) + else: + # Game over + if self.endtimer.tick(self.game.dt): + self.game.globals["score"] = self.score + self.game.scenes.gameover(self.game) if self.invincible: if self.deathtimer.tick(self.game.dt): @@ -49,7 +59,12 @@ class Manager(BaseObject): def afterdraw(self): txtsurfacescore = self.game.fontfile.render("Score : "+str(int(self.score)),False,[150,255,150]) - txtsurfacelives = self.game.fontfile.render("Lives : "+str(int(self.lives)),False,[255,150,150]) + txtsurfacelives = self.game.fontfile.render("Lives : "+str(int(max(0,self.lives))),False,[255,150,150]) self.game.realwindow.blit(txtsurfacescore,[20,20]) self.game.realwindow.blit(txtsurfacelives,[20,20*2+txtsurfacescore.get_height()]) + self.endrect.set_alpha((1-self.endtimer.getratio())*255) + self.game.realwindow.blit(self.endrect,[0,0]) + + + diff --git a/gamedata/scenes.py b/gamedata/scenes.py index 66f2817..44a5ddc 100644 --- a/gamedata/scenes.py +++ b/gamedata/scenes.py @@ -6,6 +6,7 @@ from gamedata.objects.sliders.bgmslider import BGMSlider from gamedata.objects.sliders.sfxslider import SFXSlider from gamedata.objects.ingame.lemmings import Lemming from gamedata.objects.ingame.manager import Manager +from gamedata.objects.gameover import GameOver def main(game): game.scaleCamera() @@ -28,3 +29,8 @@ def options(game): menu = OptionMenu(round(game.DISPLAY_WIDTH/8),round(game.DISPLAY_HEIGHT*9/10),game,round(game.DISPLAY_WIDTH*6/8),round(game.DISPLAY_HEIGHT/10-game.DISPLAY_HEIGHT/30)) game.gameloop.summon(s) game.gameloop.summon(s2) + +def gameover(game): + game.gameloop.reinit() + go = GameOver(game) + game.gameloop.summon(go)