diff --git a/avocado.py b/avocado.py index edebdb2..6262365 100644 --- a/avocado.py +++ b/avocado.py @@ -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): """ diff --git a/game.py b/game.py index 84064f0..0cd5ace 100755 --- a/game.py +++ b/game.py @@ -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