From 80e0b7be4e9c6b6d52d401f58a34571139fbce31 Mon Sep 17 00:00:00 2001 From: David Raison Date: Sat, 30 Aug 2014 15:52:27 +0200 Subject: [PATCH] Display current score in the upper left corner --- game.py | 4 +++- interface/__init__.py | 0 interface/hud.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 interface/__init__.py create mode 100644 interface/hud.py diff --git a/game.py b/game.py index 3861a43..7ac1e65 100644 --- a/game.py +++ b/game.py @@ -8,7 +8,7 @@ import pygame from pygame.locals import * from support import colors -import hud +from interface import hud # Move this outside screen_width = 800 @@ -26,6 +26,8 @@ def main(): while running: # Limit to 50 fps time_passed = clock.tick(30) + my_hud = hud.draw_hud(10) + screen.blit(my_hud, (0,0)) for event in pygame.event.get(): if event.type == pygame.QUIT: diff --git a/interface/__init__.py b/interface/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interface/hud.py b/interface/hud.py new file mode 100644 index 0000000..b309cfa --- /dev/null +++ b/interface/hud.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +import pygame +from pygame.locals import * +from support.colors import * + +def draw_hud(score): + hud = pygame.Surface((800, 100)) + + # Adding items to the hud + hud.blit(draw_score(score), (0, 0)) + #hud.blit(get_timeleft, (200, 0)) + return hud + +def draw_score(score): + font = pygame.font.Font(None, 30) + score = font.render('Score: ' + str(score), 0, WHITE) + return score