ugly code to switch levels
parent
fd8cbc74d0
commit
e5a0c81056
|
@ -37,7 +37,7 @@ class Avocado:
|
||||||
self.has_been_pinned = False
|
self.has_been_pinned = False
|
||||||
|
|
||||||
|
|
||||||
def updateTargetColor(self, targetColor):
|
def setTargetColor(self, targetColor):
|
||||||
self.target = targetColor
|
self.target = targetColor
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class Avocado:
|
||||||
def hasLanded(self):
|
def hasLanded(self):
|
||||||
if self.rect.bottom > self.screen_height or self.rect.top < 0:
|
if self.rect.bottom > self.screen_height or self.rect.top < 0:
|
||||||
self.is_falling = False
|
self.is_falling = False
|
||||||
print('platch')
|
print('DEBUG :: splatsh!')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
32
game.py
32
game.py
|
@ -18,14 +18,6 @@ class TheGame:
|
||||||
self.colors = [BLUE, GREEN, RED, YELLOW]
|
self.colors = [BLUE, GREEN, RED, YELLOW]
|
||||||
|
|
||||||
|
|
||||||
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 main(self):
|
def main(self):
|
||||||
pygame.init()
|
pygame.init()
|
||||||
try:
|
try:
|
||||||
|
@ -33,14 +25,12 @@ class TheGame:
|
||||||
pygame.mixer.music.set_volume(0.5)
|
pygame.mixer.music.set_volume(0.5)
|
||||||
noSound = False
|
noSound = False
|
||||||
except:
|
except:
|
||||||
print("Y U NO sound? :(")
|
print("DEBUG :: Y U NO sound? :(")
|
||||||
noSound = True
|
noSound = True
|
||||||
|
|
||||||
pygame.display.set_caption('Pin Avo, the Cado!')
|
pygame.display.set_caption('Pin Avo, the Cado!')
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
# initialize_screen() won't work for dualscreen
|
|
||||||
#size = initialize_screen()
|
|
||||||
size = (800, 600)
|
size = (800, 600)
|
||||||
bg = pygame.image.load("img/background.png")
|
bg = pygame.image.load("img/background.png")
|
||||||
desired_fps = 15
|
desired_fps = 15
|
||||||
|
@ -48,7 +38,9 @@ class TheGame:
|
||||||
score = 0
|
score = 0
|
||||||
time = timeleft = 30
|
time = timeleft = 30
|
||||||
level = 1
|
level = 1
|
||||||
font = pygame.font.Font(None, 40)
|
levelChange = 0
|
||||||
|
reachScore = 200
|
||||||
|
font = pygame.font.Font(None, 60)
|
||||||
|
|
||||||
# I don't know, should we move this text out of the way?
|
# I don't know, should we move this text out of the way?
|
||||||
game_over = font.render('GAME OVER', 0, RED)
|
game_over = font.render('GAME OVER', 0, RED)
|
||||||
|
@ -70,6 +62,7 @@ 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
|
||||||
|
|
||||||
if type(bg) is tuple:
|
if type(bg) is tuple:
|
||||||
screen.fill(bg)
|
screen.fill(bg)
|
||||||
|
@ -77,18 +70,24 @@ class TheGame:
|
||||||
screen.blit(pygame.transform.scale(bg, (800, 600)), (0, 0))
|
screen.blit(pygame.transform.scale(bg, (800, 600)), (0, 0))
|
||||||
|
|
||||||
# Next level?
|
# Next level?
|
||||||
if score >= 500:
|
if score >= reachScore:
|
||||||
score = 0
|
score = 0
|
||||||
level += 1
|
level += 1
|
||||||
print('DEBUG :: Level ' + string(level))
|
levelChange = 35
|
||||||
|
avocados = []
|
||||||
|
print('DEBUG :: Level ' + str(level))
|
||||||
|
|
||||||
# Let's add the lawyer
|
# Let's add the lawyer
|
||||||
fullegast.blitme()
|
fullegast.blitme()
|
||||||
|
|
||||||
|
if levelChange > 0:
|
||||||
|
levelText = font.render('Level ' + str(level), 0, WHITE)
|
||||||
|
screen.blit(levelText, (screen_width / 3, screen_height / 2))
|
||||||
|
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_width, screen_height = size
|
|
||||||
screen.blit(game_over, (screen_width/3, screen_height/2))
|
screen.blit(game_over, (screen_width/3, screen_height/2))
|
||||||
displaytime = 'Timed out!'
|
displaytime = 'Timed out!'
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
@ -100,6 +99,7 @@ class TheGame:
|
||||||
the_hud.draw_hud(score, displaytime, round(fps, 2))
|
the_hud.draw_hud(score, displaytime, round(fps, 2))
|
||||||
|
|
||||||
# Initialize a number of avocados, depending on the level
|
# Initialize a number of avocados, depending on the level
|
||||||
|
if levelChange == 0:
|
||||||
avocados_in_game = len(avocados)
|
avocados_in_game = len(avocados)
|
||||||
avocadosWanted = level * multiplier
|
avocadosWanted = level * multiplier
|
||||||
if avocados_in_game < avocadosWanted:
|
if avocados_in_game < avocadosWanted:
|
||||||
|
@ -113,7 +113,7 @@ class TheGame:
|
||||||
# E.g. have been pinned or fallen down
|
# E.g. have been pinned or fallen down
|
||||||
avocados[:] = [ x for x in avocados if x.exists() ]
|
avocados[:] = [ x for x in avocados if x.exists() ]
|
||||||
for a in avocados:
|
for a in avocados:
|
||||||
a.updateTargetColor(color)
|
a.setTargetColor(color)
|
||||||
a.move()
|
a.move()
|
||||||
a.blitme()
|
a.blitme()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue