From cdc81ffbc219380dd651078dacf55f0095d32e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Sun, 31 Aug 2014 10:15:28 +0200 Subject: [PATCH 1/2] make sure the pin hit the center of the avocado. --- avocado.py | 6 +++--- game.py | 3 ++- pingenerator.py | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/avocado.py b/avocado.py index 02cf6c6..88e5961 100644 --- a/avocado.py +++ b/avocado.py @@ -62,9 +62,9 @@ class Avocado: if self.color == self.target: self.has_been_pinned = True self.is_still_falling = False - return True - else: - return False + return True, self.rect.center + return False, (0, 0) + def isFalling(self): diff --git a/game.py b/game.py index 9ca2342..c9f57c6 100755 --- a/game.py +++ b/game.py @@ -226,9 +226,10 @@ class TheGame: # Check if any avocados have been hit for avo in movingAvocados: - hit = avo.isHit(mousepos) + hit, center = avo.isHit(mousepos) if hit: score += 100 + newPin.throwAt(center) color = self.chooseRandomColor() crystalBall.setColor(color) elif hit == False: diff --git a/pingenerator.py b/pingenerator.py index 610365d..cf470e9 100644 --- a/pingenerator.py +++ b/pingenerator.py @@ -13,11 +13,12 @@ class Generate: screen_width, screen_height = screen.get_size() self.pos = (screen_width / 2, screen_height) self.image = pygame.image.load(os.path.join('img','pin.png')).convert_alpha() - + self.size = self.image.get_size() def throwAt(self, target): self.inFlight = True - self.target = target + x, y = target + self.target = (x, y - self.size[1]) def isStuck(self): @@ -29,7 +30,6 @@ class Generate: def blitme(self): self.screen.blit(self.image, self.pos) - def moveTowardsTarget(self): ############################## # From f45632aceeab37f3a4c2c1013a75156ef22a56b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Sun, 31 Aug 2014 10:25:37 +0200 Subject: [PATCH 2/2] Fix last commit --- game.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/game.py b/game.py index b77ffdc..6af1237 100755 --- a/game.py +++ b/game.py @@ -95,11 +95,12 @@ class TheGame: def gameOver(self): - screen_width, screen_height = self.screen.get_size + screen_width, screen_height = self.screen.get_size() gameOverImage = pygame.image.load("img/gameOver.png") gameOverText = self.bigFont.render('GAME OVER', 0, YELLOW) gameOverImage.blit(gameOverText, (screen_width/8, screen_height/7)) - self.screen.blit(pygame.transform.scale(gameOverImage, self.size), (0, 0)) + self.screen.blit(pygame.transform.scale(gameOverImage, + self.screen.get_size()), (0, 0)) pygame.display.flip() self.fadeSound() pygame.time.wait(3000) @@ -255,7 +256,7 @@ class TheGame: self.thrownPins.append(newPin) # Check if any avocados have been hit - for avo in movingAvocados: + for avo in self.movingAvocados: hit, center = avo.isHit(mousepos) if hit: score += 100