Skip to content

Commit

Permalink
added ingame timer and text for counted coins
Browse files Browse the repository at this point in the history
  • Loading branch information
NYC00kie committed Feb 3, 2022
1 parent 3c51830 commit 0cc5804
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def checkforfinish(self, Level):
return False

def drawlevel(self, Level, pygame, volume=0.1):
font = pygame.font.SysFont(pygame.font.get_fonts()[0], 30)

Level.musicobject = pygame.mixer.Sound(Level.levelmusicpath)
Level.musicobject.set_volume(volume)
Expand All @@ -132,7 +133,18 @@ def drawlevel(self, Level, pygame, volume=0.1):

screen = pygame.display.set_mode(Level.size)

# a check for when the Player has finished the map
if self.checkforfinish(Level):
münzentext = font.render(
f"Münzen gesammelt: {Level.coincount}", False, (
255, 255, 255
)
)
timertext = font.render(
f"Sekunden gebraucht: {Level.framecount/30}s", False, (
255, 255, 255
)
)
endscreen = pygame.image.load(Level.winpicpath).convert_alpha()
endscreensize = endscreen.get_size()
print(endscreensize)
Expand All @@ -144,6 +156,24 @@ def drawlevel(self, Level, pygame, volume=0.1):
int(height/2-(endscreensize[1]/2))
)
)
screen.blit(
münzentext, (
int(width/2-(münzentext.get_width()/2)),
int(
(height/2+(endscreensize[1]/2))
+ (münzentext.get_height()+20)
)
)
)
screen.blit(
timertext, (
int(width/2-(timertext.get_width()/2)),
int(
(height/2+(endscreensize[1]/2))
+ (münzentext.get_height()+20+timertext.get_height())
)
)
)
pygame.display.flip()
Level.musicobject.stop()
time.sleep(2)
Expand Down Expand Up @@ -208,6 +238,7 @@ def drawlevel(self, Level, pygame, volume=0.1):
# which in return results in a constant and playable playspeed
if diff < 1/30:
time.sleep(1/30-(diff))
Level.framecount += 1

def drawmenu(self, Levelist, pygame):

Expand Down
1 change: 1 addition & 0 deletions level.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, levelmatrixpath, levelpicpath, pygame, levelmusicpath="backgr
self.obstaclelist = self.loadobstacle()
self.coinlist = self.loadcoins()
self.coincount = 0
self.framecount = 0
self.Player.rect = self.Player.rect.move(self.start)

def loadPlayerposstart(self):
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def resource_path(relative_path):

if __name__ == "__main__":
pygame.init()
pygame.font.init()
pygame.display.set_mode((1920, 1080))
level1 = Level(levelmatrixpath=resource_path("Levels/Level1.json.bz"),
levelpicpath=resource_path("Levelpictures/Level1.png"),
Expand Down

0 comments on commit 0cc5804

Please sign in to comment.