diff options
Diffstat (limited to 'MathQuest.py')
-rw-r--r-- | MathQuest.py | 82 |
1 files changed, 44 insertions, 38 deletions
diff --git a/MathQuest.py b/MathQuest.py index 6a78049..7756cb9 100644 --- a/MathQuest.py +++ b/MathQuest.py @@ -1,3 +1,12 @@ +# MathQuest.py +# Author: Tyler Bragdon +# Contributors: Eric Mallon +# +# Description: The initial starting screen for the Math Quest project, giving +# the player options to play through the entire game or select an individual +# level to play from the level select screen. + + import tower, levelone, leveltwo, levelthree, levelfour, levelfive, race, util
import random, os.path
@@ -28,40 +37,40 @@ def run(): clicked = 0
menuLocation = 0 #The variable representing which screen of the main menu the player is on - 0 is the main menu
- mouseRect = pygame.Rect(pygame.mouse.get_pos(),(5,5))
-
- #Code to set up the initial screen (Stores as surface)
- mainButtons = [pygame.Rect(400,300,400,100),pygame.Rect(400,450,400,100),pygame.Rect(400,600,400,100)]
- mainButtonText = ["Start Game","Level Select","Exit"]
-
+ mouseRect = pygame.Rect(pygame.mouse.get_pos(),(5,5)) #A rectangle representing the current mouse position
+ + #load the images used
bgImage = util.load_image('fork.bmp')
- bgButton = util.load_image('mainButton.jpg')
+ bgButton = util.load_image('mainButton.jpg') +
+ #Code to set up the initial screen (Stores as surface)
+ mainButtons = [pygame.Rect(400,300,400,100),pygame.Rect(400,450,400,100),pygame.Rect(400,600,400,100)] #Button locations
+ mainButtonText = ["Start Game","Level Select","Exit"] #Button text
- mainScreen = pygame.Surface((width,height))
+ mainScreen = pygame.Surface((width,height)) #Surface the background/buttons of the main screen are stored
mainScreen.blit(bgImage,(0,0))
titleFont = pygame.font.Font(None, 150)
mainScreen.blit(titleFont.render("Math Quest",1,(5,5,5)),(300,100))
-
+ + #Goes through every button, drawing it to the screen and adding its text
for i in range(len(mainButtons)):
- pygame.draw.rect(mainScreen,[175,0,0],mainButtons[i])
(x,y) = mainButtons[i].topleft
- mainScreen.blit(bgButton,(x,y),(0,0,50,100))
-
+ mainScreen.blit(bgButton,(x,y),(0,0,50,100)) #draws the left portion of the button images
+ + #draws the middle portion of the button images
middle = 50
while middle < (mainButtons[i].width - 50):
mainScreen.blit(bgButton,(x+middle,y),(50,0,50,100))
middle = middle+50
- mainScreen.blit(bgButton,(x+middle,y),(100,0,50,100))
+ mainScreen.blit(bgButton,(x+middle,y),(100,0,50,100)) #draws right portion of button
-
+ # Adds the button text to the surface, with text centered in the button
font = pygame.font.Font(None, 80)
-
displayBox = font.render(mainButtonText[i], 1, (30,30,150))
textSize = font.size(mainButtonText[i])
-
mainScreen.blit(displayBox,(mainButtons[i].topleft[0]+(400-textSize[0])/2,mainButtons[i].topleft[1]+(100-textSize[1])/2))
#Set up the level select screen (Also stores as surface)
@@ -74,6 +83,7 @@ def run(): titleFont = pygame.font.Font(None, 120)
levelSelectScreen.blit(titleFont.render("Level Select",1,(5,5,5)),(335,35))
+ for i in range(len(levelSelectButtons)):
@@ -108,49 +118,49 @@ def run(): #User decides to exit program
if event.type == QUIT:
run = 0 #stop running
-
+ #Whenever the mouse is clicked, clicked is turned to true
if event.type == pygame.MOUSEBUTTONDOWN:
clicked = 1
if clicked == 1:
clicked = 0
- print "Mouse clicked"
if menuLocation == 0: #On the main screen
clickedButton = mouseRect.collidelist(mainButtons)
if clickedButton != -1:
- print "Button %d clicked"%(clickedButton)
- if clickedButton == 0:
+ if clickedButton == 0: #Starts the game from the beginning and plays through all levels
levelone.run()
levelfour.run()
leveltwo.run()
levelthree.run()
tower.run()
- elif clickedButton == 1:
+ elif clickedButton == 1: #Goes to level select screen
menuLocation = 1
screen.blit(levelSelectScreen,(0,0))
- elif clickedButton == 2:
+ elif clickedButton == 2: #Exits program
run = 0
elif menuLocation == 1: #On the level select screen
clickedButton = mouseRect.collidelist(levelSelectButtons)
- if clickedButton != -1:
+ if clickedButton != -1: +
print "Button %d clicked"%(clickedButton)
- if clickedButton == 0:
+ if clickedButton == 0: #Bridge Level
levelone.run()
- if clickedButton == 1:
+ if clickedButton == 1: #Map Level
leveltwo.run()
- if clickedButton == 2:
+ if clickedButton == 2: #Dungeon Level
levelfive.run()
- if clickedButton == 3:
+ if clickedButton == 3: #Watch Level
levelfour.run()
- if clickedButton == 4:
+ if clickedButton == 4: #Race Level
race.run()
- if clickedButton == 5:
+ if clickedButton == 5: #Tower Gate Level
levelthree.run()
- if clickedButton == 6:
+ if clickedButton == 6: #Tower Climbing level
tower.run()
- if clickedButton == 7:
+ if clickedButton == 7: #Boss level (not yet implemented)
pass
- if clickedButton == 8:
+ if clickedButton == 8: #Back button
+ #Sets the menu location to that of the main menu, draws surface menuLocation = 0
screen.blit(mainScreen,(0,0))
pygame.display.flip()
@@ -158,13 +168,9 @@ def run(): clock.tick(40) #limits to 40 FPS
pygame.quit()
-
+ +#Main method simply calls run one
def main():
run()
- # levelone.run()
- # levelfour.run()
- # leveltwo.run()
- # levelthree.run()
- # tower.run()
if __name__ == '__main__': main()
|