make the avocados move

master
Raphaël Vinot 2014-08-30 18:43:19 +02:00
parent 26147e1182
commit 7c657961f8
2 changed files with 18 additions and 12 deletions

View File

@ -16,11 +16,15 @@ class Avocado:
self.pycard = self.image.get_rect()
self.pycard.x = random.randint(0, self.screen_width)
self.pycard.y = random.randint(0, 50)
self.pycard.y = random.randint(20, 70)
self.step_x = 10
self.step_y = 10
self.is_falling = True
def reset(self):
self.pycard.x = random.randint(0, self.screen_width)
self.pycard.y = random.randint(0, 50)
def collides(self, click):
"""
Checks whether this object collides with the given position

10
game.py
View File

@ -10,6 +10,7 @@ from pygame.locals import *
from support.colors import *
from interface import hud
def main():
pygame.init()
pygame.display.set_caption('Pin the Avocados!')
@ -28,10 +29,11 @@ def main():
score = 0
time = 15
level = 1
level = 5
running = True
timeleft = time
avocados = []
while running:
time_passed = clock.tick(desired_fps)
fps = clock.get_fps()
@ -51,15 +53,15 @@ def main():
screen.blit(chud, (10, 10))
# Initialize a number of avocados, depending on the level
if len(avocados) != level:
avocados = []
for i in range(0, level):
a = avocado.Avocado((screen_width, screen_height))
avocados.append(a)
has_moved = False
for a in avocados:
if a.move():
has_moved = True
if not a.move():
a.reset()
screen.blit(a.image, a.pycard)
# Catch events