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-06 00:24:50 (GMT)
committer Michael Kitson <msk5293@rit.edu>2010-11-06 00:24:50 (GMT)
commit190cc4241170351f3c12feda7ff740fd8c772e64 (patch)
treed58dcced5fe743e906690f31f5667ceb21532d65
parentb24480b125210cd43c6b742ae5f39e3d9918df81 (diff)
Added game code to the gameMain class, now the only code in the file outside of the class calls the ctor followed by loop.
-rw-r--r--dev/pacmath.activity/gameMain.py107
1 files changed, 55 insertions, 52 deletions
diff --git a/dev/pacmath.activity/gameMain.py b/dev/pacmath.activity/gameMain.py
index f35031d..df96ef4 100644
--- a/dev/pacmath.activity/gameMain.py
+++ b/dev/pacmath.activity/gameMain.py
@@ -16,8 +16,6 @@ import pygame
import sys
# GAME VARIABLES
-done = False
-paused = False
MAZE_SIZE = 25
MAZE_DRAW_FRAME = 25
@@ -28,8 +26,26 @@ class gameMain:
"""
# everything for setting up the game
temp = 0
+ pygame.init()
+ pygame.key.set_repeat(10, 50)
+ # make the screen however big the maze (maze needs to 625 by 625) is
+ self.screen = pygame.display.set_mode((900, 700))
+ # if olpcgames.ACTIVITY:
+ # size = olpcgames.ACTIVITY.game_size
+ pygame.display.set_caption('PacMath')
+ self.screen.fill((0,0,0))
+ self.questGen = questionGenerator( 'x', 2, 12 )
- def update(self, event, frame):
+ self.maze = mazeSetup(self.screen, MAZE_SIZE) # create an instance of the
+ # maze->call the constructor
+ self.QandA = question(self.screen, self.questGen.getQuestionSet())
+ self.ghost1 = ghostMovement((self.screen.get_rect().x, self.screen.get_rect().y), 0, self.QandA.questions[0])
+ self.ghost2 = ghostMovement((self.screen.get_rect().x, self.screen.get_rect().y), 1, self.QandA.questions[1])
+ self.ghost3 = ghostMovement((self.screen.get_rect().x, self.screen.get_rect().y), 2, self.QandA.questions[2])
+ self.ghost4 = ghostMovement((self.screen.get_rect().x, self.screen.get_rect().y), 3, self.QandA.questions[3])
+ self.pacman = pacmanMovement((self.screen.get_rect().x, self.screen.get_rect().y))
+
+ def update(self, event):
"""
Updates the maze and sprites given an event
@param event: directional key
@@ -37,11 +53,11 @@ class gameMain:
"""
# anything the needs to be update in the game loop
# such as the players, screen.blit, etc.
- ghostMovement.update(ghost1, screen, MAZE_SIZE, maze)
- ghostMovement.update(ghost2, screen, MAZE_SIZE, maze)
- ghostMovement.update(ghost3, screen, MAZE_SIZE, maze)
- ghostMovement.update(ghost4, screen, MAZE_SIZE, maze)
- pacmanMovement.update(pacman, screen, event, MAZE_SIZE, maze)
+ ghostMovement.update(self.ghost1, self.screen, MAZE_SIZE, self.maze)
+ ghostMovement.update(self.ghost2, self.screen, MAZE_SIZE, self.maze)
+ ghostMovement.update(self.ghost3, self.screen, MAZE_SIZE, self.maze)
+ ghostMovement.update(self.ghost4, self.screen, MAZE_SIZE, self.maze)
+ pacmanMovement.update(self.pacman, self.screen, event, MAZE_SIZE, self.maze)
pygame.display.update()
@@ -49,56 +65,43 @@ class gameMain:
"""
Places the pause overlay over the game screen
"""
- QandA.drawPaused(screen)
+ self.QandA.drawPaused(self.screen)
def unpause(self):
- QandA.drawQuestion(screen)
-
-pygame.init()
-pygame.key.set_repeat(10, 50)
-# make the screen however big the maze (maze needs to 625 by 625) is
-screen = pygame.display.set_mode((900, 700))
-#if olpcgames.ACTIVITY:
-# size = olpcgames.ACTIVITY.game_size
-pygame.display.set_caption('PacMath')
-screen.fill((0,0,0))
-questGen = questionGenerator( 'x', 2, 12 )
-quests = questGen.getQuestionSet()
+ self.QandA.drawQuestion(self.screen)
-# make an instance of this class
-maze = mazeSetup(screen, MAZE_SIZE) #create an instance of the maze->call the constructor
-QandA = question(screen, quests)
-ghost1 = ghostMovement((screen.get_rect().x, screen.get_rect().y), 0, QandA.questions[0])
-ghost2 = ghostMovement((screen.get_rect().x, screen.get_rect().y), 1, QandA.questions[1])
-ghost3 = ghostMovement((screen.get_rect().x, screen.get_rect().y), 2, QandA.questions[2])
-ghost4 = ghostMovement((screen.get_rect().x, screen.get_rect().y), 3, QandA.questions[3])
-pacman = pacmanMovement((screen.get_rect().x, screen.get_rect().y))
-game = gameMain()
+ def loop(self):
+ done = False
+ paused = False
-#for only drawing every MAZE_DRAW_FRAME number of frames
-frame = 0
-
-# GAME LOOP
-while done == False:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- done = True
- 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()
+ while done == False:
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ done = True
+ 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
+ if not paused:
pygame.time.delay(150)
- # slow things down
- if not paused:
- pygame.time.delay(150)
- game.update(event, frame)
+ game.update(event)
# once we exit the game loop we exit the game
+ sys.exit()
+
+############ END GAMEMAIN CLASS, STARTING CODE HERE ###########
+game = gameMain()
+game.loop()
sys.exit()
+
+# GAME LOOP
+