- no changes are good changes?
commit
b02e5db10c
22
avocado.py
22
avocado.py
|
@ -5,7 +5,9 @@ from support import operations
|
|||
|
||||
class Avocado:
|
||||
|
||||
def __init__(self, screen, color, size, select, sound=True, filename='img/AvoCado_0.png'):
|
||||
def __init__(self, screen, color, size, target, sound=True, filename='img/AvoCado_0.png'):
|
||||
|
||||
# HELP please!!
|
||||
# We randomly decide whether we should instanciate or not
|
||||
# I'd rather just not return an instance,
|
||||
# but I don't know how to do that :(
|
||||
|
@ -14,13 +16,11 @@ class Avocado:
|
|||
self.has_been_pinned = False
|
||||
return None
|
||||
|
||||
print('New avocado is ' + ','.join(str(color)))
|
||||
# Set up our instance variables
|
||||
self.screen = screen
|
||||
self.color = color
|
||||
self.select = select
|
||||
self.target = target
|
||||
self.screen_width, self.screen_height = screen.get_size()
|
||||
self.x = random.randint(0, self.screen_width)
|
||||
self.y = 0 # change this to start somewhere above the screen
|
||||
self.w, self.y = size
|
||||
|
||||
# Initialize the image
|
||||
|
@ -36,6 +36,9 @@ class Avocado:
|
|||
self.is_falling = True
|
||||
self.has_been_pinned = False
|
||||
|
||||
def updateTargetColor(self, targetColor):
|
||||
self.target = targetColor
|
||||
|
||||
|
||||
def blitme(self):
|
||||
self.screen.blit(self.image, self.rect)
|
||||
|
@ -49,13 +52,15 @@ class Avocado:
|
|||
def isHit(self, click):
|
||||
"""
|
||||
Checks whether this object collides with the given position
|
||||
of a mouse-click
|
||||
of a mouse-click. Return true is the correct color was hit and
|
||||
false if it was the wrong one.
|
||||
Just returns void if no avocado was hit
|
||||
"""
|
||||
mousex, mousey = click
|
||||
if self.rect.left < mousex and self.rect.right > mousex and \
|
||||
self.rect.top < mousey and self.rect.bottom > mousey:
|
||||
|
||||
if self.color == self.select:
|
||||
if self.color == self.target:
|
||||
self.has_been_pinned = True
|
||||
return True
|
||||
else:
|
||||
|
@ -93,6 +98,7 @@ class Avocado:
|
|||
else:
|
||||
pygame.mixer.music.set_volume(0.5)
|
||||
|
||||
|
||||
def playLevel(self,lvl=1):
|
||||
if not sound:
|
||||
return
|
||||
|
@ -104,11 +110,13 @@ class Avocado:
|
|||
pygame.mixer.music.load("""audio/level3.wav""")
|
||||
pygame.mixer.music.play()
|
||||
|
||||
|
||||
def fade(self):
|
||||
if not sound:
|
||||
return
|
||||
pygame.mixer.music.fadeout(3000)
|
||||
|
||||
|
||||
def loadClick(self):
|
||||
if not sound:
|
||||
return
|
||||
|
|
59
game.py
59
game.py
|
@ -3,7 +3,7 @@
|
|||
Avocados and stuff
|
||||
"""
|
||||
|
||||
import os, random, sys
|
||||
import os, random
|
||||
import pygame
|
||||
import avocado, lawyer
|
||||
from pygame.locals import *
|
||||
|
@ -11,23 +11,29 @@ from support.colors import *
|
|||
from interface import hud
|
||||
|
||||
|
||||
def initialize_screen():
|
||||
class TheGame:
|
||||
|
||||
def __init__(self):
|
||||
""" foo """
|
||||
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():
|
||||
def main(self):
|
||||
pygame.init()
|
||||
try:
|
||||
pygame.mixer.init()
|
||||
pygame.mixer.music.set_volume(0.5)
|
||||
noSound = False
|
||||
except:
|
||||
print("Setting no sound :(")
|
||||
print("Y U NO sound? :(")
|
||||
noSound = True
|
||||
|
||||
pygame.display.set_caption('Pin Avo, the Cado!')
|
||||
|
@ -50,20 +56,18 @@ def main():
|
|||
the_hud = hud.Hud(screen)
|
||||
fullegast = lawyer.Lawyer(screen)
|
||||
|
||||
# Well, we want this to select between several colors, so we need a list
|
||||
# of colors, right?
|
||||
colors = [BLUE, GREEN, RED, YELLOW]
|
||||
selected = random.randint(0, 3)
|
||||
color = colors[selected]
|
||||
# Initial color
|
||||
color = self.chooseRandomColor()
|
||||
fullegast.setColor(color)
|
||||
|
||||
score = 0
|
||||
time = 15
|
||||
time = timeleft = 15
|
||||
level = 5
|
||||
|
||||
running = True
|
||||
timeleft = time
|
||||
avocados = []
|
||||
running = True
|
||||
while running:
|
||||
|
||||
time_passed = clock.tick(desired_fps)
|
||||
fps = clock.get_fps()
|
||||
if type(bg) is tuple:
|
||||
|
@ -71,24 +75,16 @@ def main():
|
|||
else:
|
||||
screen.blit(pygame.transform.scale(bg,(800,600)),(0,0))
|
||||
|
||||
|
||||
# Let's add the lawyer and have him announce a color
|
||||
fullegast.setColor(color)
|
||||
# Let's add the lawyer
|
||||
fullegast.blitme()
|
||||
|
||||
timeleft -= time_passed / 1000
|
||||
timeleft = round(timeleft, 2)
|
||||
|
||||
if timeleft <= 0:
|
||||
screen_width, screen_height = size
|
||||
screen.blit(game_over, (screen_width/3, screen_height/2))
|
||||
displaytime = 'Timed out!'
|
||||
# Redraw the HUD
|
||||
the_hud.draw_hud(score, displaytime, round(fps, 2))
|
||||
pygame.display.flip()
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
continue
|
||||
else:
|
||||
displaytime = timeleft
|
||||
|
@ -98,10 +94,9 @@ def main():
|
|||
|
||||
# Initialize a number of avocados, depending on the level
|
||||
avocados_in_game = len(avocados)
|
||||
print(avocados_in_game)
|
||||
if avocados_in_game != level:
|
||||
for i in range(avocados_in_game, level):
|
||||
avocolor = colors[random.randint(0, 3)]
|
||||
avocolor = self.chooseRandomColor()
|
||||
avosize = (50, 50) # should we randomize this?
|
||||
a = avocado.Avocado(screen, avocolor, avosize, color, noSound)
|
||||
avocados.append(a)
|
||||
|
@ -110,6 +105,7 @@ def main():
|
|||
# E.g. have been pinned or fallen down
|
||||
avocados[:] = [ x for x in avocados if x.exists() ]
|
||||
for a in avocados:
|
||||
a.updateTargetColor(color)
|
||||
a.move()
|
||||
a.blitme()
|
||||
|
||||
|
@ -121,20 +117,23 @@ def main():
|
|||
hit = avo.isHit(pygame.mouse.get_pos())
|
||||
if hit:
|
||||
score += 100
|
||||
color = self.chooseRandomColor()
|
||||
fullegast.setColor(color)
|
||||
elif hit == False:
|
||||
score -= 50
|
||||
if event.type == MOUSEMOTION:
|
||||
# implement pin who follows mouse here
|
||||
pass
|
||||
|
||||
# Had enough of this?
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
def chooseRandomColor(self):
|
||||
selected = random.randint(0, 3)
|
||||
return self.colors[selected]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
game = TheGame()
|
||||
game.main()
|
||||
|
|
Loading…
Reference in New Issue