Created avocado module

master
David Raison 2014-08-30 17:59:20 +02:00
parent 3ac4286668
commit aa76ab2299
2 changed files with 35 additions and 2 deletions

24
avocado.py Normal file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
import pygame, random
class Avocado:
def __init__(self, screensize):
screen_width, screen_height = screensize
self.x = random.randint(0,screen_width)
self.y = 0 # change this to start somewhere above the screen
self.w = 100
self.y = 100
def collides(self, click):
"""
Checks whether this object collides with the given position
in click
"""
return True
#if collision then self.destroy()
def destroy(self):
"""destroys this object"""

13
game.py
View File

@ -5,8 +5,8 @@ Avocados and stuff
import os, random
import pygame
import avocado
from pygame.locals import *
from support.colors import *
from interface import hud
@ -28,6 +28,7 @@ def main():
score = 0
time = 15
level = 1
running = True
timeleft = time
@ -49,10 +50,18 @@ def main():
chud = my_hud.draw_hud(score, displaytime, round(fps,2))
screen.blit(chud, (10,10))
# Initialize a number of avocados, depending on the level
avocados = []
for i in range(0, level):
a = avocado.Avocado((screen_width, screen_height))
avocados.append(a)
# Catch events
for event in pygame.event.get():
if event.type == MOUSEBUTTONDOWN:
score += 100
for avo in avocados:
if avo.collides(pygame.mouse.get_pos()):
score += 100
if event.type == pygame.QUIT:
running = False