def update(self): """update method @param self @return None @desc Updates the high score screen. Blits all relevant sprites and positions text. Updates the scores if they change""" highscores = HighScoreMonitor.getHighScores() i = 0 textGroup = [] font = pygame.font.Font(None, 30) #Put all the high scores in a list. #Iterate through the list and output them. #Use a control variable to define which key the highscore is, #and then put it in a different place depending on what #high score position its in #This means all the high-scores appear in the right place and not in one blob for score in reversed(sorted(highscores)): text = font.render(str(score), True,(255,255,255), (0,0,0) )#text to be rendered, anti-aliasing, colour, bg-colour rect = text.get_rect() if i == 0: rect.x = 100 rect.y = 117 if i == 1: rect.x = 100 rect.y = 170 if i == 2: rect.x = 100 rect.y = 230 if i == 3: rect.x = 100 rect.y = 280 if i == 4: rect.x = 100 rect.y = 330 if i == 5: rect.x = 390 rect.y = 117 if i == 6: rect.x = 390 rect.y = 170 if i == 7: rect.x = 390 rect.y = 230 if i == 8: rect.x = 390 rect.y = 280 if i == 9: rect.x = 390 rect.y = 330 textGroup.append({'object':text,'rect':rect}) i += 1 self.screen.blit(self.bg, (0,0)) for text in textGroup: self.screen.blit(text['object'], text['rect'])
def gameOver(screen, score): """gameOver @param screen The screen sprites need to be rendered on @param score int The score the player obtained before dying @return None @desc Stores the relevant values as static properties, load the required background images @exception ResourceException Thrown when one of the images cant be loaded""" GameOver.screen = screen GameOver.score = score # Check if the score the user posted is a new high score. If it is then show a different screen for intuitivity/user-feedback purposes isHighScore = HighScoreMonitor.newHighScore(score) if isHighScore: try: GameOver.bg = pygame.image.load("sprites/gameover_bg_hiscore.png").convert() except: error.ResourceException("sprites/gameover_bg_hiscore.png") else: try: GameOver.bg = pygame.image.load("sprites/gameover_bg.png").convert() except: error.ResourceException("sprites/gameover_bg.png")