Added lawyer class

master
David Raison 2014-08-30 18:46:55 +02:00
parent fd952fdf43
commit 97ae892f2d
4 changed files with 53 additions and 9 deletions

40
game.py
View File

@ -5,26 +5,43 @@ Avocados and stuff
import os, random
import pygame
import avocado
import avocado, lawyer
from pygame.locals import *
from support.colors import *
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():
pygame.init()
pygame.display.set_caption('Pin the Avocados!')
clock = pygame.time.Clock()
# Move this outside the main code?
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width,screen_height))
# initialize_screen() won't work for dualscreen
#size = initialize_screen()
size = (800, 600)
bg = BLACK
desired_fps = 60
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)
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
time = 15
@ -37,10 +54,14 @@ def main():
fps = clock.get_fps()
screen.fill(bg)
# 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!'
else:
@ -53,15 +74,18 @@ def main():
# Initialize a number of avocados, depending on the level
avocados = []
for i in range(0, level):
a = avocado.Avocado((screen_width, screen_height))
a = avocado.Avocado(size)
avocados.append(a)
# Catch events
for event in pygame.event.get():
# Collision detection
if event.type == MOUSEBUTTONDOWN:
for avo in avocados:
if avo.collides(pygame.mouse.get_pos()):
score += 100
# Had enough of this?
if event.type == pygame.QUIT:
running = False

BIN
img/lawyer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -10,7 +10,7 @@ class Hud:
def __init__(self, screensize):
self.screen_width, self.screen_height = screensize
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):
self.screen.fill(BLACK)

20
lawyer.py Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
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!! Absolute sizes
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):
operations.color_surface(self.image, WHITE)
self.screen.blit(self.image, self.pos)