Fixed merge conflict
commit
74469356ae
36
avocado.py
36
avocado.py
|
@ -1,15 +1,29 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import pygame, random
|
import pygame
|
||||||
|
import random
|
||||||
|
|
||||||
class Avocado:
|
class Avocado:
|
||||||
|
|
||||||
def __init__(self, screensize):
|
def __init__(self, screensize, filename='avocado-01.jpg'):
|
||||||
screen_width, screen_height = screensize
|
self.screen_width, self.screen_height = screensize
|
||||||
self.x = random.randint(0,screen_width)
|
self.x = random.randint(0, self.screen_width)
|
||||||
self.y = 0 # change this to start somewhere above the screen
|
self.y = 0 # change this to start somewhere above the screen
|
||||||
self.w = 100
|
self.w = 100
|
||||||
self.y = 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):
|
def collides(self, click):
|
||||||
"""
|
"""
|
||||||
|
@ -22,3 +36,15 @@ class Avocado:
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
"""destroys this object"""
|
"""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
|
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()
|
||||||
|
@ -68,14 +69,20 @@ 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(size)
|
for i in range(0, level):
|
||||||
avocados.append(a)
|
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
|
# Catch events
|
||||||
for event in pygame.event.get():
|
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