Added fps, time left

master
David Raison 2014-08-30 16:06:02 +02:00
parent 80e0b7be4e
commit 7f3e0b210b
2 changed files with 20 additions and 7 deletions

View File

@ -21,13 +21,17 @@ def main():
pygame.init()
pygame.display.set_caption('Avocados')
clock = pygame.time.Clock()
score = 0
time = 33
running = True
while running:
# Limit to 50 fps
time_passed = clock.tick(30)
my_hud = hud.draw_hud(10)
screen.blit(my_hud, (0,0))
fps = clock.get_fps()
my_hud = hud.draw_hud(score, time, fps)
screen.blit(my_hud, (10,10))
for event in pygame.event.get():
if event.type == pygame.QUIT:

View File

@ -4,15 +4,24 @@ import pygame
from pygame.locals import *
from support.colors import *
def draw_hud(score):
def draw_hud(score, timeleft, fps):
hud = pygame.Surface((800, 100))
font = pygame.font.Font(None, 30)
# Adding items to the hud
hud.blit(draw_score(score), (0, 0))
#hud.blit(get_timeleft, (200, 0))
hud.blit(draw_score(font, score), (0, 0))
hud.blit(draw_timeleft(font, timeleft), (100, 0))
hud.blit(draw_fps(font, fps), (150, 0))
return hud
def draw_score(score):
font = pygame.font.Font(None, 30)
def draw_score(font, score):
score = font.render('Score: ' + str(score), 0, WHITE)
return score
def draw_timeleft(font, time):
# Add a clock icon here (maybe egg-clock)
time = font.render(str(time), 1, WHITE)
return time
def draw_fps(font, fps):
return font.render('fps: ' + str(fps), 10, RED)