make sure the pin hit the center of the avocado.
parent
9a6954ac8a
commit
cdc81ffbc2
|
@ -62,9 +62,9 @@ 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
|
self.is_still_falling = False
|
||||||
return True
|
return True, self.rect.center
|
||||||
else:
|
return False, (0, 0)
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def isFalling(self):
|
def isFalling(self):
|
||||||
|
|
3
game.py
3
game.py
|
@ -226,9 +226,10 @@ class TheGame:
|
||||||
|
|
||||||
# Check if any avocados have been hit
|
# Check if any avocados have been hit
|
||||||
for avo in movingAvocados:
|
for avo in movingAvocados:
|
||||||
hit = avo.isHit(mousepos)
|
hit, center = avo.isHit(mousepos)
|
||||||
if hit:
|
if hit:
|
||||||
score += 100
|
score += 100
|
||||||
|
newPin.throwAt(center)
|
||||||
color = self.chooseRandomColor()
|
color = self.chooseRandomColor()
|
||||||
crystalBall.setColor(color)
|
crystalBall.setColor(color)
|
||||||
elif hit == False:
|
elif hit == False:
|
||||||
|
|
|
@ -13,11 +13,12 @@ class Generate:
|
||||||
screen_width, screen_height = screen.get_size()
|
screen_width, screen_height = screen.get_size()
|
||||||
self.pos = (screen_width / 2, screen_height)
|
self.pos = (screen_width / 2, screen_height)
|
||||||
self.image = pygame.image.load(os.path.join('img','pin.png')).convert_alpha()
|
self.image = pygame.image.load(os.path.join('img','pin.png')).convert_alpha()
|
||||||
|
self.size = self.image.get_size()
|
||||||
|
|
||||||
def throwAt(self, target):
|
def throwAt(self, target):
|
||||||
self.inFlight = True
|
self.inFlight = True
|
||||||
self.target = target
|
x, y = target
|
||||||
|
self.target = (x, y - self.size[1])
|
||||||
|
|
||||||
|
|
||||||
def isStuck(self):
|
def isStuck(self):
|
||||||
|
@ -29,7 +30,6 @@ class Generate:
|
||||||
def blitme(self):
|
def blitme(self):
|
||||||
self.screen.blit(self.image, self.pos)
|
self.screen.blit(self.image, self.pos)
|
||||||
|
|
||||||
|
|
||||||
def moveTowardsTarget(self):
|
def moveTowardsTarget(self):
|
||||||
##############################
|
##############################
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue