Brought back Rafi0ts pinned avocados
parent
f98940e307
commit
a2591a1ef6
|
@ -70,14 +70,14 @@ class Avocado:
|
||||||
|
|
||||||
if self.color == self.target:
|
if self.color == self.target:
|
||||||
self.has_been_pinned = True
|
self.has_been_pinned = True
|
||||||
|
self.is_still_falling = False
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def exists(self):
|
def isFalling(self):
|
||||||
return not self.has_been_pinned and self.is_still_falling
|
return self.is_still_falling
|
||||||
# return self.is_still_falling
|
|
||||||
|
|
||||||
|
|
||||||
def isPinned(self):
|
def isPinned(self):
|
||||||
|
|
28
game.py
28
game.py
|
@ -114,6 +114,7 @@ class TheGame:
|
||||||
levelChange = 0
|
levelChange = 0
|
||||||
score = 0
|
score = 0
|
||||||
targetScore = 400
|
targetScore = 400
|
||||||
|
pinnedAvocados = []
|
||||||
|
|
||||||
# initialize the HUD class and the lawyer
|
# initialize the HUD class and the lawyer
|
||||||
the_hud = hud.Hud(self.screen)
|
the_hud = hud.Hud(self.screen)
|
||||||
|
@ -125,7 +126,7 @@ class TheGame:
|
||||||
|
|
||||||
# We could use this list for redrawing only this part
|
# We could use this list for redrawing only this part
|
||||||
# of the screen install of all of it
|
# of the screen install of all of it
|
||||||
avocados = []
|
movingAvocados = []
|
||||||
running = True
|
running = True
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
|
@ -142,10 +143,10 @@ class TheGame:
|
||||||
level += 1
|
level += 1
|
||||||
levelChange = 70
|
levelChange = 70
|
||||||
timeleft = time
|
timeleft = time
|
||||||
avocados = []
|
|
||||||
print('DEBUG :: Score: ' + str(score))
|
print('DEBUG :: Score: ' + str(score))
|
||||||
print('DEBUG :: Level ' + str(level))
|
print('DEBUG :: Level ' + str(level))
|
||||||
self.playLevel(level)
|
self.playLevel(level)
|
||||||
|
pinnedAvocados = []
|
||||||
|
|
||||||
if levelChange > 0:
|
if levelChange > 0:
|
||||||
levelText = self.bigFont.render('Level ' + str(level), 0, WHITE)
|
levelText = self.bigFont.render('Level ' + str(level), 0, WHITE)
|
||||||
|
@ -165,24 +166,27 @@ class TheGame:
|
||||||
# If we're not currently in between levels…
|
# If we're not currently in between levels…
|
||||||
if levelChange == 0:
|
if levelChange == 0:
|
||||||
# Initialize a number of avocados, depending on the level
|
# Initialize a number of avocados, depending on the level
|
||||||
avocados_in_game = len(avocados)
|
avocadosInGame = len(movingAvocados)
|
||||||
avocadosWanted = level * multiplier
|
avocadosWanted = level * multiplier
|
||||||
if avocados_in_game < avocadosWanted:
|
if avocadosInGame < avocadosWanted:
|
||||||
for i in range(avocados_in_game, avocadosWanted):
|
for i in range(avocadosInGame, avocadosWanted):
|
||||||
avocolor = self.chooseRandomColor()
|
avocolor = self.chooseRandomColor()
|
||||||
avosize = (50, 50) # should we randomize this?
|
avosize = (50, 50) # should we randomize this?
|
||||||
a = avocado.Avocado(self.screen, avocolor, avosize, color)
|
a = avocado.Avocado(self.screen, avocolor, avosize, color)
|
||||||
avocados.append(a)
|
movingAvocados.append(a)
|
||||||
|
|
||||||
# Remove avocados from the list if they no longer exist
|
pinnedAvocados += [avo for avo in movingAvocados if avo.isPinned() ]
|
||||||
# E.g. have been pinned or fallen down
|
# Remove avocados from the list of moving avocados if they no longer move
|
||||||
avocados[:] = [ x for x in avocados if x.exists() ]
|
movingAvocados[:] = [ avo for avo in movingAvocados if avo.isFalling() ]
|
||||||
for a in avocados:
|
|
||||||
|
for a in movingAvocados:
|
||||||
a.setTargetColor(color)
|
a.setTargetColor(color)
|
||||||
if not a.isPinned():
|
|
||||||
a.move()
|
a.move()
|
||||||
a.blitme()
|
a.blitme()
|
||||||
|
|
||||||
|
for a in pinnedAvocados:
|
||||||
|
a.blitme()
|
||||||
|
|
||||||
# Catch events
|
# Catch events
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
# Collision detection
|
# Collision detection
|
||||||
|
@ -191,7 +195,7 @@ class TheGame:
|
||||||
# Throw a pin here
|
# Throw a pin here
|
||||||
# pin.throwAt(mousepos)
|
# pin.throwAt(mousepos)
|
||||||
# Yep, above here
|
# Yep, above here
|
||||||
for avo in avocados:
|
for avo in movingAvocados:
|
||||||
hit = avo.isHit(mousepos)
|
hit = avo.isHit(mousepos)
|
||||||
if hit:
|
if hit:
|
||||||
score += 100
|
score += 100
|
||||||
|
|
Loading…
Reference in New Issue