started refactoring main class
parent
9bcf82045a
commit
2168d2376c
53
game.py
53
game.py
|
@ -15,8 +15,12 @@ class TheGame:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
""" foo """
|
""" foo """
|
||||||
|
# initialize the game canvas
|
||||||
|
self.size = (800, 600)
|
||||||
|
self.screen = pygame.display.set_mode(self.size)
|
||||||
self.colors = [BLUE, GREEN, RED, YELLOW]
|
self.colors = [BLUE, GREEN, RED, YELLOW]
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
self.font = pygame.font.Font(None, 60)
|
||||||
self.pinned = []
|
self.pinned = []
|
||||||
try:
|
try:
|
||||||
pygame.mixer.init()
|
pygame.mixer.init()
|
||||||
|
@ -29,14 +33,6 @@ class TheGame:
|
||||||
pygame.display.set_caption('Pin Avo, the Cado!')
|
pygame.display.set_caption('Pin Avo, the Cado!')
|
||||||
|
|
||||||
|
|
||||||
def initialize_screen(self):
|
|
||||||
displayInfo = pygame.display.Info()
|
|
||||||
zoom = 1.3
|
|
||||||
WIDTH = int(displayInfo.current_w / zoom)
|
|
||||||
HEIGHT = int(displayInfo.current_h / zoom)
|
|
||||||
return (WIDTH, HEIGHT)
|
|
||||||
|
|
||||||
|
|
||||||
def mute(self,mute=False,sound=True):
|
def mute(self,mute=False,sound=True):
|
||||||
if not sound:
|
if not sound:
|
||||||
return
|
return
|
||||||
|
@ -71,17 +67,23 @@ class TheGame:
|
||||||
return self.click
|
return self.click
|
||||||
|
|
||||||
|
|
||||||
def gameOver(self,screen,gameOverImage):
|
def gameOver(self):
|
||||||
screen.blit(pygame.transform.scale(gameOverImage, (800, 600)), (0, 0))
|
screen_width, screen_height = self.size
|
||||||
|
gameOverImage = pygame.image.load("img/gameOver.png")
|
||||||
|
gameOverText = self.font.render('GAME OVER', 0, RED)
|
||||||
|
gameOverImage.blit(game_over, (screen_width/3, screen_height/2))
|
||||||
|
self.screen.blit(pygame.transform.scale(gameOverImage, self.size), (0, 0))
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
pygame.time.wait(3000)
|
pygame.time.wait(3000)
|
||||||
|
pygame.quit()
|
||||||
|
|
||||||
|
|
||||||
def keepPinned(self, avocado):
|
def keepPinned(self, avocado):
|
||||||
self.pinned.append(avocado)
|
self.pinned.append(avocado)
|
||||||
|
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
size = (800, 600)
|
|
||||||
bg = pygame.image.load("img/background.png")
|
bg = pygame.image.load("img/background.png")
|
||||||
desired_fps = 60
|
desired_fps = 60
|
||||||
multiplier = 3
|
multiplier = 3
|
||||||
|
@ -90,19 +92,11 @@ class TheGame:
|
||||||
level = 1
|
level = 1
|
||||||
levelChange = 0
|
levelChange = 0
|
||||||
reachScore = 200
|
reachScore = 200
|
||||||
font = pygame.font.Font(None, 60)
|
|
||||||
avoClick = game.loadClick()
|
avoClick = game.loadClick()
|
||||||
|
|
||||||
# I don't know, should we move this text out of the way?
|
|
||||||
game_over = font.render('GAME OVER', 0, RED)
|
|
||||||
gameOverImage = pygame.image.load("img/gameOver.png")
|
|
||||||
|
|
||||||
# initialize the game canvas
|
|
||||||
screen = pygame.display.set_mode(size)
|
|
||||||
|
|
||||||
# initialize the HUD class and the lawyer
|
# initialize the HUD class and the lawyer
|
||||||
the_hud = hud.Hud(screen)
|
the_hud = hud.Hud(self.screen)
|
||||||
fullegast = lawyer.Lawyer(screen)
|
fullegast = lawyer.Lawyer(self.screen)
|
||||||
|
|
||||||
# Initial color
|
# Initial color
|
||||||
color = self.chooseRandomColor()
|
color = self.chooseRandomColor()
|
||||||
|
@ -114,12 +108,12 @@ class TheGame:
|
||||||
|
|
||||||
time_passed = clock.tick(desired_fps)
|
time_passed = clock.tick(desired_fps)
|
||||||
fps = clock.get_fps()
|
fps = clock.get_fps()
|
||||||
screen_width, screen_height = size
|
screen_width, screen_height = self.size
|
||||||
|
|
||||||
if type(bg) is tuple:
|
if type(bg) is tuple:
|
||||||
screen.fill(bg)
|
self.screen.fill(bg)
|
||||||
else:
|
else:
|
||||||
screen.blit(pygame.transform.scale(bg, (800, 600)), (0, 0))
|
self.screen.blit(pygame.transform.scale(bg, (800, 600)), (0, 0))
|
||||||
|
|
||||||
# Next level?
|
# Next level?
|
||||||
if score >= reachScore:
|
if score >= reachScore:
|
||||||
|
@ -136,18 +130,14 @@ class TheGame:
|
||||||
fullegast.blitme()
|
fullegast.blitme()
|
||||||
|
|
||||||
if levelChange > 0:
|
if levelChange > 0:
|
||||||
levelText = font.render('Level ' + str(level), 0, WHITE)
|
levelText = self.font.render('Level ' + str(level), 0, WHITE)
|
||||||
screen.blit(levelText, (screen_width / 3, screen_height / 2))
|
screen.blit(levelText, (screen_width / 3, screen_height / 2))
|
||||||
levelChange -= 1
|
levelChange -= 1
|
||||||
|
|
||||||
timeleft -= time_passed / 1000
|
timeleft -= time_passed / 1000
|
||||||
timeleft = round(timeleft, 2)
|
timeleft = round(timeleft, 2)
|
||||||
if timeleft <= 0:
|
if timeleft <= 0:
|
||||||
screen.blit(game_over, (screen_width/3, screen_height/2))
|
self.gameOver()
|
||||||
displaytime = 'Timed out!'
|
|
||||||
pygame.display.flip()
|
|
||||||
game.gameOver(screen,gameOverImage)
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
displaytime = timeleft
|
displaytime = timeleft
|
||||||
|
|
||||||
|
@ -162,7 +152,7 @@ class TheGame:
|
||||||
for i in range(avocados_in_game, avocadosWanted):
|
for i in range(avocados_in_game, avocadosWanted):
|
||||||
avocolor = self.chooseRandomColor()
|
avocolor = self.chooseRandomColor()
|
||||||
avosize = (50, 50) # should we randomize this?
|
avosize = (50, 50) # should we randomize this?
|
||||||
a = avocado.Avocado(screen, avocolor, avosize, color)
|
a = avocado.Avocado(self.screen, avocolor, avosize, color)
|
||||||
avocados.append(a)
|
avocados.append(a)
|
||||||
|
|
||||||
# Remove avocados from the list if they no longer exist
|
# Remove avocados from the list if they no longer exist
|
||||||
|
@ -193,7 +183,6 @@ class TheGame:
|
||||||
# Had enough of this?
|
# Had enough of this?
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
running = False
|
running = False
|
||||||
game.gameOver(screen,gameOverImage)
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue