2014-08-30 15:52:27 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2014-08-30 17:20:20 +02:00
|
|
|
import os, pygame
|
2014-08-30 15:52:27 +02:00
|
|
|
from pygame.locals import *
|
|
|
|
from support.colors import *
|
2014-08-30 17:24:11 +02:00
|
|
|
from support import operations
|
2014-08-30 15:52:27 +02:00
|
|
|
|
2014-08-30 16:53:03 +02:00
|
|
|
class Hud:
|
2014-08-30 15:52:27 +02:00
|
|
|
|
2014-08-30 20:47:21 +02:00
|
|
|
def __init__(self, screen):
|
|
|
|
self.screen = screen
|
|
|
|
self.screen_width, self.screen_height = screen.get_size()
|
2014-08-30 16:53:03 +02:00
|
|
|
self.font = pygame.font.Font(None, 30)
|
2014-08-31 01:24:10 +02:00
|
|
|
self.hud = pygame.Surface((self.screen_width, 25))
|
2014-08-30 15:52:27 +02:00
|
|
|
|
2014-08-30 16:53:03 +02:00
|
|
|
def draw_hud(self, score, timeleft, fps):
|
2014-08-30 20:47:21 +02:00
|
|
|
self.hud.fill(BLACK)
|
|
|
|
self.hud.blit(self.draw_score(score), (0, 0))
|
|
|
|
self.hud.blit(self.draw_timeleft(timeleft), (self.screen_width / 2, 0))
|
2014-08-30 17:05:01 +02:00
|
|
|
thefps = self.draw_fps(fps)
|
|
|
|
fps_rect = thefps.get_rect()
|
2014-08-30 20:47:21 +02:00
|
|
|
self.hud.blit(thefps, (self.screen_width - fps_rect.w, 0))
|
|
|
|
self.blitme()
|
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)
|
2014-08-30 20:47:21 +02:00
|
|
|
|
|
|
|
def blitme(self):
|
|
|
|
self.screen.blit(self.hud, (10, 10))
|