Fixed merge conflict
commit
74469356ae
36
avocado.py
36
avocado.py
|
@ -1,15 +1,29 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import pygame, random
|
||||
import pygame
|
||||
import random
|
||||
|
||||
class Avocado:
|
||||
|
||||
def __init__(self, screensize):
|
||||
screen_width, screen_height = screensize
|
||||
self.x = random.randint(0,screen_width)
|
||||
self.y = 0 # change this to start somewhere above the screen
|
||||
def __init__(self, screensize, filename='avocado-01.jpg'):
|
||||
self.screen_width, self.screen_height = screensize
|
||||
self.x = random.randint(0, self.screen_width)
|
||||
self.y = 0 # change this to start somewhere above the screen
|
||||
self.w = 100
|
||||
self.y = 100
|
||||
self.i = pygame.image.load(filename).convert_alpha()
|
||||
self.image = pygame.transform.scale(self.i, (20, 20))
|
||||
self.pycard = self.image.get_rect()
|
||||
|
||||
self.pycard.x = random.randint(0, self.screen_width)
|
||||
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):
|
||||
"""
|
||||
|
@ -22,3 +36,15 @@ class Avocado:
|
|||
def destroy(self):
|
||||
"""destroys this object"""
|
||||
|
||||
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:
|
||||
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
|
||||
|
||||
|
|
21
game.py
21
game.py
|
@ -45,10 +45,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()
|
||||
|
@ -68,14 +69,20 @@ def main():
|
|||
displaytime = timeleft
|
||||
|
||||
# Redraw the HUD
|
||||
chud = my_hud.draw_hud(score, displaytime, round(fps,2))
|
||||
screen.blit(chud, (10,10))
|
||||
chud = my_hud.draw_hud(score, displaytime, round(fps, 2))
|
||||
screen.blit(chud, (10, 10))
|
||||
|
||||
# Initialize a number of avocados, depending on the level
|
||||
avocados = []
|
||||
for i in range(0, level):
|
||||
a = avocado.Avocado(size)
|
||||
avocados.append(a)
|
||||
if len(avocados) != level:
|
||||
avocados = []
|
||||
for i in range(0, level):
|
||||
a = avocado.Avocado(size)
|
||||
avocados.append(a)
|
||||
|
||||
for a in avocados:
|
||||
if not a.move():
|
||||
a.reset()
|
||||
screen.blit(a.image, a.pycard)
|
||||
|
||||
# Catch events
|
||||
for event in pygame.event.get():
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
Loading…
Reference in New Issue