From 13786f52cb0bcb3c44ee390fb2e440ca07882b87 Mon Sep 17 00:00:00 2001 From: David Raison Date: Sun, 31 Aug 2014 10:29:04 +0200 Subject: [PATCH] tiny improvements --- avocado.py | 4 ++-- game.py | 43 ++++++++++++++++++++++--------------------- interface/hud.py | 2 +- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/avocado.py b/avocado.py index 99600f7..787efbb 100644 --- a/avocado.py +++ b/avocado.py @@ -98,9 +98,9 @@ class Avocado: def hasLanded(self): - if self.rect.bottom > self.screen_height or self.rect.top < 0: + if self.rect.top > self.screen_height: self.is_still_falling = False - print('DEBUG :: splash!') + print('DEBUG :: splatch!') return True diff --git a/game.py b/game.py index 0ce394a..0c12aa7 100755 --- a/game.py +++ b/game.py @@ -24,6 +24,13 @@ class TheGame: self.timeout = 30 self.level = 1 self.targetScore = 400 + ############################## + # Never set below 4, else we have a high + # probability of losing the game due to a missing color + # Alternatively, you could edit chooseRandomColor() + # to only work on the first multiplier colors + self.multiplier = 4 + self.desired_fps = 60 self.screen = pygame.display.set_mode((self.WIDTH, self.HEIGHT)) self.colors = [BLUE, GREEN, RED, YELLOW] self.bg = pygame.image.load(os.path.join('img', 'lawyerCrystalBall.png')) @@ -95,7 +102,7 @@ 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)) @@ -131,18 +138,10 @@ class TheGame: def main(self): - desired_fps = 60 - - ############################## - # Never set below 4, else we have a high - # probability of losing the game due to a missing color - # Alternatively, you could edit chooseRandomColor() - # to only work on the first multiplier colors - multiplier = 4 score = 0 # We could use this list for redrawing only this part - # of the screen install of all of it + # of the screen instead of all of it self.resetLevel() # initialize the HUD class and the lawyer @@ -155,19 +154,13 @@ class TheGame: texts = [] container = {'font': self.bigFont, 'screen': self.screen, 'clock': self.clock} - # onetext = itext.Text(container, 'Huhu', 2000) - # texts.append(onetext) running = True while running: - time_passed = self.clock.tick(desired_fps) + time_passed = self.clock.tick(self.desired_fps) fps = self.clock.get_fps() screen_width, screen_height = self.screen.get_size() - # Redraw the background and put our lawyer back on top - self.drawBackground() - crystalBall.blitme() - # Next level? if score >= (self.targetScore * self.level): self.level += 1 @@ -178,7 +171,6 @@ class TheGame: 2000 ) texts.append(levelText) - # self.screen.blit(levelText, (screen_width / 3, screen_height / 2)) self.playLevel(self.level) self.resetLevel() @@ -191,18 +183,21 @@ class TheGame: displaytime = self.timeleft + # Redraw the background and put our lawyer back on top + self.drawBackground() + crystalBall.blitme() + # Check if there's any text that wants to get displayed for text in texts: text.blitme() texts[:] = [text for text in texts if not text.hasExpired() ] - # Redraw the HUD the_hud.draw_hud(score, displaytime, round(fps, 2)) # Initialize a number of avocados, depending on the level avocadosInGame = len(self.movingAvocados) - avocadosWanted = self.level * multiplier + avocadosWanted = self.level * self.multiplier if avocadosInGame < avocadosWanted: probability = int(1.0/(avocadosWanted - avocadosInGame) * 100) @@ -210,7 +205,13 @@ class TheGame: avocolor = self.chooseRandomColor() avosize = (50, 50) # should we randomize this? # Spawn a new avocado - a = avocado.Avocado(self.screen, avocolor, avosize, color, self.level) + a = avocado.Avocado( + self.screen, + avocolor, + avosize, + color, + self.level + ) self.movingAvocados.append(a) # Remove avocados from the list of moving avocados if they no longer move diff --git a/interface/hud.py b/interface/hud.py index 03cc94f..6031e9a 100644 --- a/interface/hud.py +++ b/interface/hud.py @@ -19,7 +19,7 @@ class Hud: self.hud.blit(self.draw_timeleft(timeleft), (self.screen_width / 2, 0)) thefps = self.draw_fps(fps) fps_rect = thefps.get_rect() - self.hud.blit(thefps, (self.screen_width - fps_rect.w, 0)) + self.hud.blit(thefps, (self.screen_width - (fps_rect.w + 5), 0)) self.blitme() def draw_score(self, score):