From 31386d9f76eb28441abf64d646d6808f13a24f2d Mon Sep 17 00:00:00 2001 From: Michael Kitson Date: Thu, 11 Nov 2010 21:34:30 +0000 Subject: Score no longer hurt from wrong answer, only lives. Level display now works and lives display will change to a number when there is no more room for pacman images --- diff --git a/dev/pacmath.activity/gameMain.py b/dev/pacmath.activity/gameMain.py index c1b3db2..d1b034f 100644 --- a/dev/pacmath.activity/gameMain.py +++ b/dev/pacmath.activity/gameMain.py @@ -38,7 +38,7 @@ class gameMain: self.screen.fill((0,0,0)) self.operation = random.sample('x+-/', 1) self.questGen = questionGenerator( self.operation, 2, 12 ) - self.lives = BASE_LIVES + self.lives = BASE_LIVES self.score = 0 self.level = 1 @@ -55,18 +55,20 @@ class gameMain: self.ghosts = [ self.ghost1, self.ghost2, self.ghost3, self.ghost4 ] self.nextQuestion() - + def nextQuestion(self): if self.QandA.nextQuestion(): self.wrongGhosts = pygame.sprite.Group() self.correctGhosts = pygame.sprite.Group() + for i in range(len(self.ghosts)): if not (i == self.QandA.getAnswerIndex() ): self.wrongGhosts.add( self.ghosts[i] ) else: self.correctGhosts.add( self.ghosts[i] ) else: + self.level += 1 self.resetQuestion() def update(self, event): @@ -104,15 +106,12 @@ class gameMain: def checkCollisions(self): for ghost in pygame.sprite.spritecollide(self.pacman, self.correctGhosts,False): - if self.nextQuestion() == False: - self.resetQuestion() - self.level +=1 - self.QandA.updateLevel(level) + self.nextQuestion() + self.QandA.updateLevel(self.screen, self.level) ghost.eaten() return True for ghost in pygame.sprite.spritecollide(self.pacman, self.wrongGhosts, False): - self.score -= 50 self.lives -= 1 if self.lives < 0: print "GAME OVER" @@ -139,6 +138,7 @@ class gameMain: self.resetQuestion() self.QandA.updateScore(self.screen, self.score) self.QandA.updateLives(self.screen, self.lives) + self.QandA.updateLevel(self.screen, self.level) while done == False: for event in pygame.event.get(): diff --git a/dev/pacmath.activity/question.py b/dev/pacmath.activity/question.py index c492541..5dd01c9 100644 --- a/dev/pacmath.activity/question.py +++ b/dev/pacmath.activity/question.py @@ -45,6 +45,7 @@ class question: self.drawQuestion(screen) self.pacman = pygame.image.load("./images/pacmanr.png").convert_alpha() self.screen = screen + def nextQuestion(self): if(len(self.answered) > 3): return False @@ -177,11 +178,20 @@ class question: @param count: the number of lives we have """ self.clearLives(screen) - offset = 0 - for i in range(count): - offset += 30 + if count < 10: + offset = 0 + for i in range(count): + offset += 30 + screen.blit(self.pacman, (900-offset, 640)) + pygame.display.update(pygame.Rect(900-offset, 640, offset, 30)) + else: + offset = 30 screen.blit(self.pacman, (900-offset, 640)) - pygame.display.update(pygame.Rect(900-offset, 640, offset, 30)) + offset += 5 + text = pygame.font.Font(None, 36).render( str(count), 1, self.QUESTION_COLOR ) + screen.blit( text, (900 - text.get_width() - offset, 640)) + offset += text.get_width() + pygame.display.update(pygame.Rect(900-offset, 640, offset, 30)) def clearLives(self, screen): """ @@ -224,16 +234,16 @@ class question: self.clearLevel(screen) text = pygame.font.Font(None, 36).render( 'Level: ' + str(level), 1, self.QUESTION_COLOR ) - screen.blit(text, (900-text.get_width(), 625)) - pygame.display.update(pygame.Rect(900-text.get_width(), 625, text.get_width(), 30)) + screen.blit(text, (900-text.get_width(), 605)) + pygame.display.update(pygame.Rect(900-text.get_width(), 605, text.get_width(), 30)) def clearLevel(self, screen): """ Draws a black box over the score display so that we may redraw it @param screen: the screen on which to draw """ - blackBox = pygame.Surface((300,30)) + blackBox = pygame.Surface((275,30)) blackBox.fill((0,0,0)) - screen.blit(blackBox, (600,635)) - pygame.display.update(pygame.Rect(600, 670, 300, 30)) + screen.blit(blackBox, (625,605)) + pygame.display.update(pygame.Rect(625, 605, 275, 30)) -- cgit v0.9.1