Remove hardcoded hud variable to config file
This commit is contained in:
parent
60cc17e5d4
commit
4bcdf83da7
2 changed files with 15 additions and 5 deletions
|
@ -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
|
||||
|
|
14
models.py
14
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())))
|
||||
|
|
Loading…
Reference in a new issue