From fac9be4d85686463c26b97589c216d1eb64f190e Mon Sep 17 00:00:00 2001 From: Michael Kitson Date: Thu, 11 Nov 2010 16:52:25 +0000 Subject: Every Object now has a clear function and a draw function. So if we draw over it (say, with a game over screen or something) it can be redeawn when we finish. --- diff --git a/dev/pacmath.activity/GhostMovement.py b/dev/pacmath.activity/GhostMovement.py index 1068015..75beefa 100644 --- a/dev/pacmath.activity/GhostMovement.py +++ b/dev/pacmath.activity/GhostMovement.py @@ -116,3 +116,13 @@ class ghostMovement(pygame.sprite.Sprite): # Update ONLY the modified areas of the screen pygame.display.update([self.old, self.rect]) + + def clearSelf(self, screen, mazeObj): + gridX = int(round(self.rect.x/MAZE_SIZE, 0) ) + gridY = int(round(self.rect.y/MAZE_SIZE, 0) ) + mazeObj.drawPoint(screen, gridX, gridY) + pygame.display.update(self.rect) + + def drawSelf(self, screen): + screen.blit(self.image, self.rect) + pygame.display.update(self.rect) diff --git a/dev/pacmath.activity/mazeSetup.py b/dev/pacmath.activity/mazeSetup.py index f8a20ee..60778de 100644 --- a/dev/pacmath.activity/mazeSetup.py +++ b/dev/pacmath.activity/mazeSetup.py @@ -151,3 +151,7 @@ class mazeSetup: return pygame.image.load(file+'.png').convert_alpha() else: return False + + def redrawMaze(self, screen, mazeSize = 25): + self.drawMaze( screen, mazeSize ) + pygame.display.update(0,0,625,625) diff --git a/dev/pacmath.activity/pacmanMovement.py b/dev/pacmath.activity/pacmanMovement.py index 5c2fce3..c229d58 100644 --- a/dev/pacmath.activity/pacmanMovement.py +++ b/dev/pacmath.activity/pacmanMovement.py @@ -100,3 +100,13 @@ class pacmanMovement(pygame.sprite.Sprite): # Update ONLY the modified areas of the screen pygame.display.update([self.old, self.rect]) + + def clearSelf(self, screen, mazeObj): + gridX = int(round(self.rect.x/MAZE_SIZE, 0) ) + gridY = int(round(self.rect.y/MAZE_SIZE, 0) ) + mazeObj.drawPoint(screen, gridX, gridY) + pygame.display.update(self.rect) + + def drawSelf(self, screen): + screen.blit(self.images[self.imageIndex], self.rect) + pygame.display.update(self.rect) diff --git a/dev/pacmath.activity/question.py b/dev/pacmath.activity/question.py index 67eed88..caf20b9 100644 --- a/dev/pacmath.activity/question.py +++ b/dev/pacmath.activity/question.py @@ -21,6 +21,7 @@ class question: C = [(255, 124, 0), (625, 158), (735, 173), "./images/ghost3.png"] D = [(255, 0, 192), (625, 237), (735, 250), "./images/ghost4.png"] + # Size of rectangles SIZE = (275, 75) @@ -47,10 +48,8 @@ class question: Draws all answers in their color coded boxes @param screen: The screen on which to draw """ - self.drawAnswer(screen, self.questions[0][1], 1) - self.drawAnswer(screen, self.questions[1][1], 2) - self.drawAnswer(screen, self.questions[2][1], 3) - self.drawAnswer(screen, self.questions[3][1], 4) + for i in range(4): + self.drawAnswer(screen, self.questions[i][1], i+1) # Draws the answer in a ghost colored rectangle def drawAnswer(self, screen, answer, choice): @@ -87,11 +86,25 @@ class question: # Create and draw rectangle, answer and ghost right of maze ans = font.render(answer, 1, color) - rect = (pos, self.SIZE) + rect = pygame.rect.Rect(pos, self.SIZE) + total = rect + rect.inflate_ip(-3,-3) pygame.draw.rect(screen, color, rect, 3) g = pygame.image.load(ghost).convert_alpha() screen.blit(ans, center) - screen.blit(g, (pos[0] + 4, pos[1] + 4)) + screen.blit(g, (pos[0] + 7, pos[1] + 7)) + pygame.display.update(total) + + def clearAnswers(self, screen): + for i in range(3): + self.clearAnswer( screen, i ) + + def clearAnswer(self, screen, number): + pos = (625, number*B[1][1]) + dim = SIZE + rect = pygame.rect.Rect(pos, dim) + screen.fill((0,0,0), rect) + pygame.display.update(rect) # Draws the question def drawQuestion(self, screen): @@ -105,8 +118,12 @@ class question: # Draws the question under maze q = font.render(self.question, 1, self.QUESTION_COLOR) self.clearBottom(screen) - screen.blit(q, (0, 640)) - pygame.display.flip() + pos = (0,640) + screen.blit(q, pos) + rect = q.get_rect() + rect.x = pos[0] + rect.y = pos[1] + pygame.display.update(rect) def drawPaused(self, screen): """ Writes 'Paused' over where the question is usually printed @@ -117,8 +134,12 @@ class question: q = font.render("Paused", 1, self.QUESTION_COLOR) self.clearBottom(screen) - screen.blit(q, (0, 640)) - pygame.display.flip() + pos = (0,640) + screen.blit(q, pos) + rect = q.get_rect() + rect.x = pos[0] + rect.y = pos[1] + pygame.display.update(rect) def clearBottom(self, screen): """ Draws a black box over the question-holding part of the screen @@ -126,6 +147,7 @@ class question: blackBox = pygame.Surface((600,60)) blackBox.fill((0,0,0)) screen.blit(blackBox, (0,640)) + pygame.display.update(0,640, 600,60) def getAnswerIndex(self): """ -- cgit v0.9.1