pin the avocado
parent
97b59f5218
commit
b7c34c429f
13
avocado.py
13
avocado.py
|
@ -73,14 +73,15 @@ class Avocado:
|
||||||
|
|
||||||
|
|
||||||
def move(self):
|
def move(self):
|
||||||
if self.rect.right > self.screen_width or self.rect.left < 0:
|
if not self.has_been_pinned:
|
||||||
self.vx = -self.vy
|
if self.rect.right > self.screen_width or self.rect.left < 0:
|
||||||
|
self.vx = -self.vy
|
||||||
|
|
||||||
if self.hasLanded():
|
if self.hasLanded():
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
||||||
self.rect.x += self.vx
|
self.rect.x += self.vx
|
||||||
self.rect.y += self.vy
|
self.rect.y += self.vy
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
8
game.py
8
game.py
|
@ -17,6 +17,7 @@ class TheGame:
|
||||||
""" foo """
|
""" foo """
|
||||||
self.colors = [BLUE, GREEN, RED, YELLOW]
|
self.colors = [BLUE, GREEN, RED, YELLOW]
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
self.pinned = []
|
||||||
try:
|
try:
|
||||||
pygame.mixer.init()
|
pygame.mixer.init()
|
||||||
pygame.mixer.music.set_volume(0.5)
|
pygame.mixer.music.set_volume(0.5)
|
||||||
|
@ -74,6 +75,8 @@ class TheGame:
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
pygame.time.wait(3000)
|
pygame.time.wait(3000)
|
||||||
|
|
||||||
|
def keepPinned(self, avocado):
|
||||||
|
self.pinned.append(avocado)
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
@ -125,6 +128,7 @@ class TheGame:
|
||||||
levelChange = 35
|
levelChange = 35
|
||||||
timeleft = time
|
timeleft = time
|
||||||
avocados = []
|
avocados = []
|
||||||
|
self.pinned = []
|
||||||
print('DEBUG :: Level ' + str(level))
|
print('DEBUG :: Level ' + str(level))
|
||||||
game.playLevel(level)
|
game.playLevel(level)
|
||||||
|
|
||||||
|
@ -163,11 +167,15 @@ class TheGame:
|
||||||
|
|
||||||
# Remove avocados from the list if they no longer exist
|
# Remove avocados from the list if they no longer exist
|
||||||
# E.g. have been pinned or fallen down
|
# E.g. have been pinned or fallen down
|
||||||
|
self.pinned += [avo for avo in avocados if avo.has_been_pinned]
|
||||||
avocados[:] = [ x for x in avocados if x.exists() ]
|
avocados[:] = [ x for x in avocados if x.exists() ]
|
||||||
for a in avocados:
|
for a in avocados:
|
||||||
a.setTargetColor(color)
|
a.setTargetColor(color)
|
||||||
a.move()
|
a.move()
|
||||||
a.blitme()
|
a.blitme()
|
||||||
|
for a in self.pinned:
|
||||||
|
a.blitme()
|
||||||
|
|
||||||
|
|
||||||
# Catch events
|
# Catch events
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
|
|
Loading…
Reference in New Issue