From 4bcdf83da7408d4c30ca35b16ed932e3515fc05c Mon Sep 17 00:00:00 2001 From: Arthur 'Grizzly' Grisel-Davy Date: Sun, 10 May 2020 23:50:50 -0400 Subject: [PATCH] Remove hardcoded hud variable to config file --- config.yaml | 6 ++++++ models.py | 14 +++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/config.yaml b/config.yaml index 9db6408..fbb8cd5 100644 --- a/config.yaml +++ b/config.yaml @@ -26,6 +26,12 @@ path_projectile : 'projectile1_right.png' # Projectile max_fire_rate : 10 +# HUD +font_name : 'GlacialIndifference-Regular' +font_large : 72 +font_small : 40 +health_width : 30 + # Controls (not used yet) up : z right : d diff --git a/models.py b/models.py index e4568a0..389ae44 100644 --- a/models.py +++ b/models.py @@ -18,6 +18,10 @@ with open(r'./config.yaml') as file: acceleration = data['acceleration'] deceleration = data['deceleration'] img_path = data['texture_path'] + font_large_size = data['font_large'] + font_small_size = data['font_small'] + health_width = data['health_width'] + font_name = data['font_name'] @@ -59,7 +63,7 @@ class Game(): pause_screen.set_alpha(128) pause_screen.fill((255,255,255)) surface.blit(pause_screen, (0,0)) - text = self.hud.font.render(str('...PAUSED...'), True, (255, 255, 255)) + text = self.hud.font_large.render(str('...PAUSED...'), True, (255, 255, 255)) surface.blit(text, (int(surface.get_width()/2-text.get_width()/2),int(0.3*surface.get_height()-text.get_height()/2))) def get_offset(self): @@ -71,13 +75,13 @@ class Hud(): def __init__(self,player): self.player = player self.ratio = 1 - self.font_large = pygame.font.SysFont('GlacialIndifference-Regular', 72) - self.font_small = pygame.font.SysFont('GlacialIndifference-Regular', 40) + self.font_large = pygame.font.SysFont(font_name, font_large_size) + self.font_small = pygame.font.SysFont(font_name, font_small_size) def draw(self,surface): # draw the life bar - pygame.draw.rect(surface,(255,0,0),(10,10,round(self.player.life/100*surface.get_width()/3),30),0) - pygame.draw.rect(surface,(255,255,255),(10,10,int(surface.get_width()/3),30),3) + pygame.draw.rect(surface,(255,0,0),(10,10,round(self.player.life/100*surface.get_width()/3),health_width),0) + pygame.draw.rect(surface,(255,255,255),(10,10,int(surface.get_width()/3),health_width),3) text = self.font_large.render(str(self.player.ammo), True, (255, 255, 255)) surface.blit(text, (int(surface.get_width()-1.5*text.get_width()),int(surface.get_height()-1.5*text.get_height())))