make the avocados move
parent
26147e1182
commit
7c657961f8
|
@ -16,11 +16,15 @@ class Avocado:
|
||||||
self.pycard = self.image.get_rect()
|
self.pycard = self.image.get_rect()
|
||||||
|
|
||||||
self.pycard.x = random.randint(0, self.screen_width)
|
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_x = 10
|
||||||
self.step_y = 10
|
self.step_y = 10
|
||||||
self.is_falling = True
|
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):
|
def collides(self, click):
|
||||||
"""
|
"""
|
||||||
Checks whether this object collides with the given position
|
Checks whether this object collides with the given position
|
||||||
|
|
24
game.py
24
game.py
|
@ -10,6 +10,7 @@ from pygame.locals import *
|
||||||
from support.colors import *
|
from support.colors import *
|
||||||
from interface import hud
|
from interface import hud
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.display.set_caption('Pin the Avocados!')
|
pygame.display.set_caption('Pin the Avocados!')
|
||||||
|
@ -18,7 +19,7 @@ def main():
|
||||||
# Move this outside the main code?
|
# Move this outside the main code?
|
||||||
screen_width = 800
|
screen_width = 800
|
||||||
screen_height = 600
|
screen_height = 600
|
||||||
screen = pygame.display.set_mode((screen_width,screen_height))
|
screen = pygame.display.set_mode((screen_width, screen_height))
|
||||||
bg = BLACK
|
bg = BLACK
|
||||||
desired_fps = 5
|
desired_fps = 5
|
||||||
|
|
||||||
|
@ -28,10 +29,11 @@ def main():
|
||||||
|
|
||||||
score = 0
|
score = 0
|
||||||
time = 15
|
time = 15
|
||||||
level = 1
|
level = 5
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
timeleft = time
|
timeleft = time
|
||||||
|
avocados = []
|
||||||
while running:
|
while running:
|
||||||
time_passed = clock.tick(desired_fps)
|
time_passed = clock.tick(desired_fps)
|
||||||
fps = clock.get_fps()
|
fps = clock.get_fps()
|
||||||
|
@ -47,19 +49,19 @@ def main():
|
||||||
displaytime = timeleft
|
displaytime = timeleft
|
||||||
|
|
||||||
# Redraw the HUD
|
# Redraw the HUD
|
||||||
chud = my_hud.draw_hud(score, displaytime, round(fps,2))
|
chud = my_hud.draw_hud(score, displaytime, round(fps, 2))
|
||||||
screen.blit(chud, (10,10))
|
screen.blit(chud, (10, 10))
|
||||||
|
|
||||||
# Initialize a number of avocados, depending on the level
|
# Initialize a number of avocados, depending on the level
|
||||||
avocados = []
|
if len(avocados) != level:
|
||||||
for i in range(0, level):
|
avocados = []
|
||||||
a = avocado.Avocado((screen_width, screen_height))
|
for i in range(0, level):
|
||||||
avocados.append(a)
|
a = avocado.Avocado((screen_width, screen_height))
|
||||||
|
avocados.append(a)
|
||||||
|
|
||||||
has_moved = False
|
|
||||||
for a in avocados:
|
for a in avocados:
|
||||||
if a.move():
|
if not a.move():
|
||||||
has_moved = True
|
a.reset()
|
||||||
screen.blit(a.image, a.pycard)
|
screen.blit(a.image, a.pycard)
|
||||||
|
|
||||||
# Catch events
|
# Catch events
|
||||||
|
|
Loading…
Reference in New Issue