Merge branch 'master' of github.com:lvl2/avocados
commit
533edaf30a
15
avocado.py
15
avocado.py
|
@ -3,27 +3,28 @@
|
||||||
import pygame
|
import pygame
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
class Avocado:
|
class Avocado:
|
||||||
|
|
||||||
def __init__(self, screensize, filename='avocado-01.jpg'):
|
def __init__(self, screen, filename='img/AvoCado_0.png'):
|
||||||
self.screen_width, self.screen_height = screensize
|
self.screen = screen
|
||||||
|
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
|
||||||
self.y = 100
|
self.y = 100
|
||||||
self.i = pygame.image.load(filename).convert_alpha()
|
self.i = pygame.image.load(filename).convert_alpha()
|
||||||
self.image = pygame.transform.scale(self.i, (20, 20))
|
self.image = pygame.transform.scale(self.i, (30, 30))
|
||||||
self.pycard = self.image.get_rect()
|
self.pycard = self.image.get_rect()
|
||||||
|
|
||||||
self.pycard.x = random.randint(0, self.screen_width)
|
self.init_pos()
|
||||||
self.pycard.y = random.randint(20, 70)
|
|
||||||
self.step_x = 10
|
self.step_x = 10
|
||||||
self.step_y = 10
|
self.step_y = 10
|
||||||
self.is_falling = True
|
self.is_falling = True
|
||||||
|
|
||||||
def reset(self):
|
def init_pos(self):
|
||||||
self.pycard.x = random.randint(0, self.screen_width)
|
self.pycard.x = random.randint(0, self.screen_width)
|
||||||
self.pycard.y = random.randint(0, 50)
|
self.pycard.y = random.randint(20, 70)
|
||||||
|
|
||||||
def collides(self, click):
|
def collides(self, click):
|
||||||
"""
|
"""
|
||||||
|
|
43
game.py
43
game.py
|
@ -5,27 +5,43 @@ Avocados and stuff
|
||||||
|
|
||||||
import os, random
|
import os, random
|
||||||
import pygame
|
import pygame
|
||||||
import avocado
|
import avocado, lawyer
|
||||||
from pygame.locals import *
|
from pygame.locals import *
|
||||||
from support.colors import *
|
from support.colors import *
|
||||||
from interface import hud
|
from interface import hud
|
||||||
|
|
||||||
|
def initialize_screen():
|
||||||
|
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():
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.display.set_caption('Pin the Avocados!')
|
pygame.display.set_caption('Pin the Avocados!')
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
# Move this outside the main code?
|
# initialize_screen() won't work for dualscreen
|
||||||
screen_width = 800
|
#size = initialize_screen()
|
||||||
screen_height = 600
|
size = (800, 600)
|
||||||
screen = pygame.display.set_mode((screen_width, screen_height))
|
|
||||||
bg = BLACK
|
bg = BLACK
|
||||||
desired_fps = 5
|
desired_fps = 60
|
||||||
|
|
||||||
font = pygame.font.Font(None, 40)
|
font = pygame.font.Font(None, 40)
|
||||||
|
|
||||||
|
# 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)
|
||||||
my_hud = hud.Hud((screen_width, screen_height))
|
|
||||||
|
# initialize the game canvas
|
||||||
|
screen = pygame.display.set_mode(size)
|
||||||
|
|
||||||
|
# initialize the HUD class
|
||||||
|
my_hud = hud.Hud(size)
|
||||||
|
|
||||||
|
# initialize our lawyer
|
||||||
|
fullegast = lawyer.Lawyer(screen)
|
||||||
|
|
||||||
score = 0
|
score = 0
|
||||||
time = 15
|
time = 15
|
||||||
|
@ -39,10 +55,14 @@ def main():
|
||||||
fps = clock.get_fps()
|
fps = clock.get_fps()
|
||||||
screen.fill(bg)
|
screen.fill(bg)
|
||||||
|
|
||||||
|
# Let's add the lawyer
|
||||||
|
fullegast.blitme()
|
||||||
|
|
||||||
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!'
|
||||||
else:
|
else:
|
||||||
|
@ -56,20 +76,23 @@ def main():
|
||||||
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((screen_width, screen_height))
|
a = avocado.Avocado(screen)
|
||||||
avocados.append(a)
|
avocados.append(a)
|
||||||
|
|
||||||
for a in avocados:
|
for a in avocados:
|
||||||
if not a.move():
|
if not a.move():
|
||||||
a.reset()
|
a.init_pos()
|
||||||
screen.blit(a.image, a.pycard)
|
screen.blit(a.image, a.pycard)
|
||||||
|
|
||||||
# Catch events
|
# Catch events
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
|
# Collision detection
|
||||||
if event.type == MOUSEBUTTONDOWN:
|
if event.type == MOUSEBUTTONDOWN:
|
||||||
for avo in avocados:
|
for avo in avocados:
|
||||||
if avo.collides(pygame.mouse.get_pos()):
|
if avo.collides(pygame.mouse.get_pos()):
|
||||||
score += 100
|
score += 100
|
||||||
|
|
||||||
|
# Had enough of this?
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
running = False
|
running = False
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
|
@ -10,7 +10,7 @@ class Hud:
|
||||||
def __init__(self, screensize):
|
def __init__(self, screensize):
|
||||||
self.screen_width, self.screen_height = screensize
|
self.screen_width, self.screen_height = screensize
|
||||||
self.font = pygame.font.Font(None, 30)
|
self.font = pygame.font.Font(None, 30)
|
||||||
self.screen = pygame.Surface((self.screen_width, self.screen_height / 6))
|
self.screen = 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.screen.fill(BLACK)
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
A class that represents a lawyer
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os, pygame
|
||||||
|
from support import operations
|
||||||
|
from support.colors import *
|
||||||
|
|
||||||
|
class Lawyer:
|
||||||
|
|
||||||
|
def __init__(self, screen):
|
||||||
|
self.screen = screen
|
||||||
|
screen_width, screen_height = screen.get_size()
|
||||||
|
temp_image = pygame.image.load(os.path.join('img', 'lawyer.png'))
|
||||||
|
# WARNING!! FIXME Absolute sizes FIXME
|
||||||
|
self.image = pygame.transform.scale(temp_image, (200, 400))
|
||||||
|
rect = self.image.get_rect()
|
||||||
|
self.pos = (screen_width - rect.w, screen_height - rect.h)
|
||||||
|
|
||||||
|
def blitme(self):
|
||||||
|
""" Blit this object to the screen """
|
||||||
|
operations.color_surface(self.image, WHITE)
|
||||||
|
self.screen.blit(self.image, self.pos)
|
||||||
|
|
||||||
|
def announce(self):
|
||||||
|
""" Announces the color to pin """
|
Loading…
Reference in New Issue