avocados/interface/hud.py

41 lines
1.5 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2014-08-30 17:20:20 +02:00
import os, pygame
from pygame.locals import *
from support.colors import *
2014-08-30 17:24:11 +02:00
from support import operations
2014-08-30 16:53:03 +02:00
class Hud:
2014-08-30 16:53:03 +02:00
def __init__(self, screensize):
self.screen_width, self.screen_height = screensize
self.font = pygame.font.Font(None, 30)
2014-08-30 18:46:55 +02:00
self.screen = pygame.Surface((self.screen_width, self.screen_height / 8))
2014-08-30 16:53:03 +02:00
def draw_hud(self, score, timeleft, fps):
self.screen.fill(BLACK)
self.screen.blit(self.draw_score(score), (0, 0))
self.screen.blit(self.draw_timeleft(timeleft), (self.screen_width / 2, 0))
thefps = self.draw_fps(fps)
fps_rect = thefps.get_rect()
self.screen.blit(thefps, (self.screen_width - fps_rect.w, 0))
2014-08-30 16:53:03 +02:00
return self.screen
2014-08-30 16:06:02 +02:00
2014-08-30 16:53:03 +02:00
def draw_score(self, score):
score = self.font.render('Score: ' + str(score), 0, WHITE)
return score
2014-08-30 16:06:02 +02:00
2014-08-30 16:53:03 +02:00
def draw_timeleft(self, time):
2014-08-30 17:20:20 +02:00
# Not sure this is clever, to recreate the surface each time ;)
timesurface = pygame.Surface((200, 20))
hourglass = pygame.image.load(os.path.join('img', 'hourglass.png')).convert_alpha()
hourglass = pygame.transform.scale(hourglass, (15, 18))
2014-08-30 17:24:11 +02:00
operations.color_surface(hourglass, WHITE)
2014-08-30 16:53:03 +02:00
time = self.font.render(str(time), 1, WHITE)
2014-08-30 17:20:20 +02:00
timesurface.blit(hourglass, (0, 0))
timesurface.blit(time, (40, 0))
return timesurface
2014-08-30 16:53:03 +02:00
def draw_fps(self, fps):
return self.font.render('fps: ' + str(fps), 10, RED)