Added colored pane
parent
b41c4a3180
commit
42652e0a34
|
@ -5,8 +5,9 @@ import random
|
||||||
|
|
||||||
class Avocado:
|
class Avocado:
|
||||||
|
|
||||||
def __init__(self, screensize, filename='img/AvoCado_0.png'):
|
def __init__(self, screen, color, filename='img/AvoCado_0.png'):
|
||||||
self.screen_width, self.screen_height = screensize
|
print('New avocado is ' + ','.join(str(color)))
|
||||||
|
self.screen_width, self.screen_height = screen.get_size()
|
||||||
self.x = random.randint(0, self.screen_width)
|
self.x = random.randint(0, self.screen_width)
|
||||||
self.y = 0 # change this to start somewhere above the screen
|
self.y = 0 # change this to start somewhere above the screen
|
||||||
self.w = 100
|
self.w = 100
|
||||||
|
@ -43,7 +44,6 @@ class Avocado:
|
||||||
print('platch')
|
print('platch')
|
||||||
return False
|
return False
|
||||||
self.is_falling = False
|
self.is_falling = False
|
||||||
print(self.pycard.x, self.pycard.y)
|
|
||||||
self.pycard.x += self.step_x
|
self.pycard.x += self.step_x
|
||||||
self.pycard.y += self.step_y
|
self.pycard.y += self.step_y
|
||||||
return True
|
return True
|
||||||
|
|
22
game.py
22
game.py
|
@ -21,7 +21,7 @@ def initialize_screen():
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.display.set_caption('Pin the Avocados!')
|
pygame.display.set_caption('Pin Avo, the Cado!')
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
# initialize_screen() won't work for dualscreen
|
# initialize_screen() won't work for dualscreen
|
||||||
|
@ -37,11 +37,14 @@ def main():
|
||||||
# initialize the game canvas
|
# initialize the game canvas
|
||||||
screen = pygame.display.set_mode(size)
|
screen = pygame.display.set_mode(size)
|
||||||
|
|
||||||
# initialize the HUD class
|
# initialize the HUD class and the lawyer
|
||||||
my_hud = hud.Hud(size)
|
the_hud = hud.Hud(screen)
|
||||||
|
|
||||||
# initialize our lawyer
|
|
||||||
fullegast = lawyer.Lawyer(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]
|
||||||
|
|
||||||
score = 0
|
score = 0
|
||||||
time = 15
|
time = 15
|
||||||
|
@ -55,7 +58,8 @@ def main():
|
||||||
fps = clock.get_fps()
|
fps = clock.get_fps()
|
||||||
screen.fill(bg)
|
screen.fill(bg)
|
||||||
|
|
||||||
# Let's add the lawyer
|
# Let's add the lawyer and have him announce a color
|
||||||
|
fullegast.setColor(color)
|
||||||
fullegast.blitme()
|
fullegast.blitme()
|
||||||
|
|
||||||
timeleft -= time_passed / 1000
|
timeleft -= time_passed / 1000
|
||||||
|
@ -69,14 +73,14 @@ def main():
|
||||||
displaytime = timeleft
|
displaytime = timeleft
|
||||||
|
|
||||||
# Redraw the HUD
|
# Redraw the HUD
|
||||||
chud = my_hud.draw_hud(score, displaytime, round(fps, 2))
|
the_hud.draw_hud(score, displaytime, round(fps, 2))
|
||||||
screen.blit(chud, (10, 10))
|
|
||||||
|
|
||||||
# Initialize a number of avocados, depending on the level
|
# Initialize a number of avocados, depending on the level
|
||||||
if len(avocados) != level:
|
if len(avocados) != level:
|
||||||
avocados = []
|
avocados = []
|
||||||
for i in range(0, level):
|
for i in range(0, level):
|
||||||
a = avocado.Avocado(size)
|
color = colors[random.randint(0,3)]
|
||||||
|
a = avocado.Avocado(screen, color)
|
||||||
avocados.append(a)
|
avocados.append(a)
|
||||||
|
|
||||||
for a in avocados:
|
for a in avocados:
|
||||||
|
|
|
@ -7,19 +7,20 @@ from support import operations
|
||||||
|
|
||||||
class Hud:
|
class Hud:
|
||||||
|
|
||||||
def __init__(self, screensize):
|
def __init__(self, screen):
|
||||||
self.screen_width, self.screen_height = screensize
|
self.screen = screen
|
||||||
|
self.screen_width, self.screen_height = screen.get_size()
|
||||||
self.font = pygame.font.Font(None, 30)
|
self.font = pygame.font.Font(None, 30)
|
||||||
self.screen = pygame.Surface((self.screen_width, self.screen_height / 8))
|
self.hud = pygame.Surface((self.screen_width, self.screen_height / 8))
|
||||||
|
|
||||||
def draw_hud(self, score, timeleft, fps):
|
def draw_hud(self, score, timeleft, fps):
|
||||||
self.screen.fill(BLACK)
|
self.hud.fill(BLACK)
|
||||||
self.screen.blit(self.draw_score(score), (0, 0))
|
self.hud.blit(self.draw_score(score), (0, 0))
|
||||||
self.screen.blit(self.draw_timeleft(timeleft), (self.screen_width / 2, 0))
|
self.hud.blit(self.draw_timeleft(timeleft), (self.screen_width / 2, 0))
|
||||||
thefps = self.draw_fps(fps)
|
thefps = self.draw_fps(fps)
|
||||||
fps_rect = thefps.get_rect()
|
fps_rect = thefps.get_rect()
|
||||||
self.screen.blit(thefps, (self.screen_width - fps_rect.w, 0))
|
self.hud.blit(thefps, (self.screen_width - fps_rect.w, 0))
|
||||||
return self.screen
|
self.blitme()
|
||||||
|
|
||||||
def draw_score(self, score):
|
def draw_score(self, score):
|
||||||
score = self.font.render('Score: ' + str(score), 0, WHITE)
|
score = self.font.render('Score: ' + str(score), 0, WHITE)
|
||||||
|
@ -38,3 +39,6 @@ class Hud:
|
||||||
|
|
||||||
def draw_fps(self, fps):
|
def draw_fps(self, fps):
|
||||||
return self.font.render('fps: ' + str(fps), 10, RED)
|
return self.font.render('fps: ' + str(fps), 10, RED)
|
||||||
|
|
||||||
|
def blitme(self):
|
||||||
|
self.screen.blit(self.hud, (10, 10))
|
||||||
|
|
19
lawyer.py
19
lawyer.py
|
@ -14,14 +14,23 @@ class Lawyer:
|
||||||
screen_width, screen_height = screen.get_size()
|
screen_width, screen_height = screen.get_size()
|
||||||
temp_image = pygame.image.load(os.path.join('img', 'lawyer.png'))
|
temp_image = pygame.image.load(os.path.join('img', 'lawyer.png'))
|
||||||
# WARNING!! FIXME Absolute sizes FIXME
|
# WARNING!! FIXME Absolute sizes FIXME
|
||||||
self.image = pygame.transform.scale(temp_image, (200, 400))
|
self.image = pygame.transform.scale(temp_image, (220, 400))
|
||||||
rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.pos = (screen_width - rect.w, screen_height - rect.h)
|
self.pos = (screen_width - self.rect.w, screen_height - self.rect.h)
|
||||||
|
|
||||||
def blitme(self):
|
def blitme(self):
|
||||||
""" Blit this object to the screen """
|
""" Blit this object to the screen """
|
||||||
operations.color_surface(self.image, WHITE)
|
operations.color_surface(self.image, WHITE)
|
||||||
|
self.image.blit(self.pane, (self.rect.left, self.rect.bottom / 2))
|
||||||
self.screen.blit(self.image, self.pos)
|
self.screen.blit(self.image, self.pos)
|
||||||
|
|
||||||
def announce(self):
|
def setColor(self, color):
|
||||||
""" Announces the color to pin """
|
""" Announces the color to pin by drawing a rectangle
|
||||||
|
and filling it with a color """
|
||||||
|
self.pane = pygame.Surface((200, 100))
|
||||||
|
self.pane.fill(color)
|
||||||
|
|
||||||
|
# Add this to self.image?!
|
||||||
|
|
||||||
|
# using surface.fill is faster because it can be hw accel
|
||||||
|
#pygame.draw.rect(Surface, color, Rect, width=0)
|
||||||
|
|
Loading…
Reference in New Issue