cleanup avocado

master
Raphaël Vinot 2014-08-30 19:01:48 +02:00
parent b41c4a3180
commit 3e84222003
2 changed files with 9 additions and 8 deletions

View File

@ -3,10 +3,12 @@
import pygame
import random
class Avocado:
def __init__(self, screensize, filename='img/AvoCado_0.png'):
self.screen_width, self.screen_height = screensize
def __init__(self, screen, filename='img/AvoCado_0.png'):
self.screen = screen
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 = 100
@ -15,15 +17,14 @@ class Avocado:
self.image = pygame.transform.scale(self.i, (30, 30))
self.pycard = self.image.get_rect()
self.pycard.x = random.randint(0, self.screen_width)
self.pycard.y = random.randint(20, 70)
self.init_pos()
self.step_x = 10
self.step_y = 10
self.is_falling = True
def reset(self):
def init_pos(self):
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):
"""

View File

@ -76,12 +76,12 @@ def main():
if len(avocados) != level:
avocados = []
for i in range(0, level):
a = avocado.Avocado(size)
a = avocado.Avocado(screen)
avocados.append(a)
for a in avocados:
if not a.move():
a.reset()
a.init_pos()
screen.blit(a.image, a.pycard)
# Catch events