Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kitson <msk5293@rit.edu>2010-11-04 18:50:25 (GMT)
committer Michael Kitson <msk5293@rit.edu>2010-11-04 18:50:25 (GMT)
commitb24480b125210cd43c6b742ae5f39e3d9918df81 (patch)
tree4d2542bf3989311cb473d24c7f1a684ac18fc8ee
parent091b7667dedc31c3088afe87c824d6cdfa3b6c5e (diff)
Finished adding pause screen, press p to pause the game
-rw-r--r--dev/pacmath.activity/gameMain.py24
-rw-r--r--dev/pacmath.activity/question.py30
2 files changed, 47 insertions, 7 deletions
diff --git a/dev/pacmath.activity/gameMain.py b/dev/pacmath.activity/gameMain.py
index 974f14f..f35031d 100644
--- a/dev/pacmath.activity/gameMain.py
+++ b/dev/pacmath.activity/gameMain.py
@@ -17,6 +17,7 @@ import sys
# GAME VARIABLES
done = False
+paused = False
MAZE_SIZE = 25
MAZE_DRAW_FRAME = 25
@@ -43,6 +44,16 @@ class gameMain:
pacmanMovement.update(pacman, screen, event, MAZE_SIZE, maze)
pygame.display.update()
+
+ def pause(self):
+ """
+ Places the pause overlay over the game screen
+ """
+ QandA.drawPaused(screen)
+
+
+ def unpause(self):
+ QandA.drawQuestion(screen)
pygame.init()
pygame.key.set_repeat(10, 50)
@@ -76,9 +87,18 @@ while done == False:
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
done = True
+ elif event.key == pygame.K_p:
+ if paused:
+ paused = False
+ game.unpause()
+ else:
+ paused = True
+ game.pause()
+ pygame.time.delay(150)
# slow things down
- pygame.time.delay(150)
- game.update(event, frame)
+ if not paused:
+ pygame.time.delay(150)
+ game.update(event, frame)
# once we exit the game loop we exit the game
sys.exit()
diff --git a/dev/pacmath.activity/question.py b/dev/pacmath.activity/question.py
index ac05b0e..7c3b6b0 100644
--- a/dev/pacmath.activity/question.py
+++ b/dev/pacmath.activity/question.py
@@ -23,6 +23,8 @@ class question:
# Size of rectangles
SIZE = (275, 75)
+ QUESTION_COLOR = (94,246,0)
+
# Default
def __init__ (self, screen, quests):
"""
@@ -32,14 +34,18 @@ class question:
"""
# Draw the answers and questions
self.questions = quests
+ self.question = self.questions[random.randint(0,3)][0]
+ self.drawAnswers(screen)
+ self.drawQuestion(screen)
+
+
+ def drawAnswers(self, screen):
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)
- self.drawQuestion(screen, self.questions[random.randint(0,3)][0])
-
-
+
# Draws the answer in a ghost colored rectangle
def drawAnswer(self, screen, answer, choice):
"""
@@ -82,7 +88,7 @@ class question:
screen.blit(g, (pos[0] + 4, pos[1] + 4))
# Draws the question
- def drawQuestion(self, screen, question):
+ def drawQuestion(self, screen):
"""
Draws the question
@param screen: the screen in which we will draw
@@ -92,5 +98,19 @@ class question:
font = pygame.font.Font(None, 72)
# Draws the question under maze
- q = font.render(question, 1, (94,246,0))
+ q = font.render(self.question, 1, self.QUESTION_COLOR)
+ self.clearBottom(screen)
+ screen.blit(q, (0, 640))
+ pygame.display.flip()
+ def drawPaused(self, screen):
+ # Font used
+ font = pygame.font.Font(None, 72)
+
+ q = font.render("Paused", 1, self.QUESTION_COLOR)
+ self.clearBottom(screen)
screen.blit(q, (0, 640))
+ pygame.display.flip()
+ def clearBottom(self, screen):
+ blackBox = pygame.Surface((900,60))
+ blackBox.fill((0,0,0))
+ screen.blit(blackBox, (0,640))