Display game over when time is up

master
David Raison 2014-08-30 16:28:56 +02:00
parent 7f3e0b210b
commit 2ab3d85c71
2 changed files with 26 additions and 13 deletions

37
game.py
View File

@ -7,30 +7,42 @@ import os, random
import pygame
from pygame.locals import *
from support import colors
from support.colors import *
from interface import hud
# Move this outside
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width,screen_height))
bg = (0,0,0)
screen.fill(bg)
def main():
pygame.init()
pygame.display.set_caption('Avocados')
clock = pygame.time.Clock()
# Move this outside the main code?
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width,screen_height))
bg = (0,0,0)
screen.fill(bg)
desired_fps = 60
font = pygame.font.Font(None, 40)
game_over = font.render('GAME OVER', 0, RED)
score = 0
time = 33
time = 10
running = True
timeleft = time
while running:
# Limit to 50 fps
time_passed = clock.tick(30)
# Limit to XY fps
time_passed = clock.tick(desired_fps)
#time_since = clock.get_time() #Same as above
fps = clock.get_fps()
my_hud = hud.draw_hud(score, time, fps)
timeleft -= time_passed / 1000
timeleft = round(timeleft,2)
if timeleft <= 0:
screen.blit(game_over, (screen_width/3, screen_height/2))
my_hud = hud.draw_hud(score, timeleft, fps)
screen.blit(my_hud, (10,10))
for event in pygame.event.get():
@ -39,5 +51,6 @@ def main():
pygame.display.flip()
if __name__ == '__main__':
main()

View File

@ -11,7 +11,7 @@ def draw_hud(score, timeleft, fps):
# Adding items to the hud
hud.blit(draw_score(font, score), (0, 0))
hud.blit(draw_timeleft(font, timeleft), (100, 0))
hud.blit(draw_fps(font, fps), (150, 0))
hud.blit(draw_fps(font, fps), (200, 0))
return hud
def draw_score(font, score):