From 1194ccfd550d50ac609b8a0ed62d8de313d138c7 Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Mon, 13 Sep 2021 11:33:40 +0200 Subject: [PATCH] Added score et lives display --- gamedata/objects/base.py | 5 ++++- gamedata/objects/gameloop.py | 2 ++ gamedata/objects/ingame/manager.py | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gamedata/objects/base.py b/gamedata/objects/base.py index 1bb1b63..40c79bf 100644 --- a/gamedata/objects/base.py +++ b/gamedata/objects/base.py @@ -12,7 +12,10 @@ class BaseObject(): def step(self): pass - def draw(self): + def draw(self): # Drawed on the surface with camera adjustement if self.sprite: self.game.window.blit(self.sprite,self.rect[:2]) + def afterdraw(self): # Drawed on the surface after camera adjustement, must draw on game.realwindow + pass + diff --git a/gamedata/objects/gameloop.py b/gamedata/objects/gameloop.py index a005996..211e70a 100644 --- a/gamedata/objects/gameloop.py +++ b/gamedata/objects/gameloop.py @@ -66,3 +66,5 @@ class GameLoop(): game.globals["tempsubsurface"].blit(game.window,[0,0]) temp = game.pygame.transform.scale(game.globals["tempsubsurface"],(game.DISPLAY_WIDTH,game.DISPLAY_HEIGHT)) game.realwindow.blit(temp,[0,0]) + for i in values: + i.afterdraw() # Draw on the "real screen" diff --git a/gamedata/objects/ingame/manager.py b/gamedata/objects/ingame/manager.py index 3609526..09d7e01 100644 --- a/gamedata/objects/ingame/manager.py +++ b/gamedata/objects/ingame/manager.py @@ -38,7 +38,6 @@ class Manager(BaseObject): if self.invincible: if self.deathtimer.tick(self.game.dt): self.invincible = False - print(self.lives) def death(self): if not self.invincible: @@ -48,3 +47,9 @@ class Manager(BaseObject): def draw(self): pass + 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]) + self.game.realwindow.blit(txtsurfacescore,[20,20]) + self.game.realwindow.blit(txtsurfacelives,[20,20*2+txtsurfacescore.get_height()]) +