Added fps, time left
parent
80e0b7be4e
commit
7f3e0b210b
8
game.py
8
game.py
|
@ -21,13 +21,17 @@ def main():
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.display.set_caption('Avocados')
|
pygame.display.set_caption('Avocados')
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
score = 0
|
||||||
|
time = 33
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
while running:
|
while running:
|
||||||
# Limit to 50 fps
|
# Limit to 50 fps
|
||||||
time_passed = clock.tick(30)
|
time_passed = clock.tick(30)
|
||||||
my_hud = hud.draw_hud(10)
|
fps = clock.get_fps()
|
||||||
screen.blit(my_hud, (0,0))
|
|
||||||
|
my_hud = hud.draw_hud(score, time, fps)
|
||||||
|
screen.blit(my_hud, (10,10))
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
|
|
|
@ -4,15 +4,24 @@ import pygame
|
||||||
from pygame.locals import *
|
from pygame.locals import *
|
||||||
from support.colors import *
|
from support.colors import *
|
||||||
|
|
||||||
def draw_hud(score):
|
def draw_hud(score, timeleft, fps):
|
||||||
hud = pygame.Surface((800, 100))
|
hud = pygame.Surface((800, 100))
|
||||||
|
font = pygame.font.Font(None, 30)
|
||||||
|
|
||||||
# Adding items to the hud
|
# Adding items to the hud
|
||||||
hud.blit(draw_score(score), (0, 0))
|
hud.blit(draw_score(font, score), (0, 0))
|
||||||
#hud.blit(get_timeleft, (200, 0))
|
hud.blit(draw_timeleft(font, timeleft), (100, 0))
|
||||||
|
hud.blit(draw_fps(font, fps), (150, 0))
|
||||||
return hud
|
return hud
|
||||||
|
|
||||||
def draw_score(score):
|
def draw_score(font, score):
|
||||||
font = pygame.font.Font(None, 30)
|
|
||||||
score = font.render('Score: ' + str(score), 0, WHITE)
|
score = font.render('Score: ' + str(score), 0, WHITE)
|
||||||
return score
|
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)
|
||||||
|
|
Loading…
Reference in New Issue