Make the avocados clickable
parent
85a79e07af
commit
e2075f33a5
15
avocado.py
15
avocado.py
|
@ -21,31 +21,38 @@ class Avocado:
|
|||
self.init_pos()
|
||||
self.step_x = 10
|
||||
self.step_y = 10
|
||||
self.is_falling = True
|
||||
self.is_destroyed = False
|
||||
|
||||
def init_pos(self):
|
||||
self.pycard.x = random.randint(0, self.screen_width)
|
||||
self.pycard.y = random.randint(20, 70)
|
||||
self.is_destroyed = False
|
||||
|
||||
def collides(self, click):
|
||||
"""
|
||||
Checks whether this object collides with the given position
|
||||
in click
|
||||
"""
|
||||
mousex, mousey = click
|
||||
if self.pycard.left < mousex and self.pycard.right > mousex and \
|
||||
self.pycard.top < mousey and self.pycard.bottom > mousey:
|
||||
self.destroy()
|
||||
return True
|
||||
return False
|
||||
#if collision then self.destroy()
|
||||
|
||||
def destroy(self):
|
||||
"""destroys this object"""
|
||||
self.is_destroyed = True
|
||||
|
||||
def move(self):
|
||||
if self.pycard.right > self.screen_width or self.pycard.left < 0:
|
||||
self.step_x = -self.step_x
|
||||
if self.pycard.bottom > self.screen_height or self.pycard.top < 0:
|
||||
if self.is_destroyed or self.pycard.bottom > self.screen_height \
|
||||
or self.pycard.top < 0:
|
||||
print('platch')
|
||||
return False
|
||||
self.is_falling = False
|
||||
print(self.pycard.x, self.pycard.y)
|
||||
self.pycard.x += self.step_x
|
||||
self.pycard.y += self.step_y
|
||||
return True
|
||||
|
||||
|
|
7
game.py
7
game.py
|
@ -28,7 +28,7 @@ def main():
|
|||
#size = initialize_screen()
|
||||
size = (800, 600)
|
||||
bg = BLACK
|
||||
desired_fps = 60
|
||||
desired_fps = 10
|
||||
font = pygame.font.Font(None, 40)
|
||||
|
||||
# I don't know, should we move this text out of the way?
|
||||
|
@ -66,10 +66,13 @@ def main():
|
|||
timeleft -= time_passed / 1000
|
||||
timeleft = round(timeleft, 2)
|
||||
|
||||
|
||||
if timeleft <= 0:
|
||||
screen_width, screen_height = size
|
||||
screen.blit(game_over, (screen_width/3, screen_height/2))
|
||||
displaytime = 'Timed out!'
|
||||
pygame.display.flip()
|
||||
continue
|
||||
else:
|
||||
displaytime = timeleft
|
||||
|
||||
|
@ -97,7 +100,7 @@ def main():
|
|||
for avo in avocados:
|
||||
if avo.collides(pygame.mouse.get_pos()):
|
||||
score += 100
|
||||
|
||||
avo.init_pos()
|
||||
# Had enough of this?
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
|
|
Loading…
Reference in New Issue