Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/MathQuest.py
blob: 6a78049270f6c653ef612b4dfb27ab4af50d58ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import tower, levelone, leveltwo, levelthree, levelfour, levelfive, race, util

import random, os.path
import util

import pygame
import pygame.font

from pygame.locals import *

def run():
    #Must initialize pygame before doing anything else
    pygame.init()
    random.seed()
    
    display_flags = DOUBLEBUF
    
    #XO laptop is 1200x900 resolution
    width, height = 1200, 900

    if pygame.display.mode_ok((width, height), display_flags ):
        screen = pygame.display.set_mode((width, height), display_flags)
		  
    clock = pygame.time.Clock() 
    run = 1
    pygame.display.set_caption('Math Quest')

    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"]
    
    bgImage = util.load_image('fork.bmp')
    bgButton = util.load_image('mainButton.jpg')
    
    mainScreen = pygame.Surface((width,height))
    mainScreen.blit(bgImage,(0,0))
    
    titleFont = pygame.font.Font(None, 150)  
    mainScreen.blit(titleFont.render("Math Quest",1,(5,5,5)),(300,100))
    
    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))
        
        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))
        
       
        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)
    levelSelectButtons = [pygame.Rect(175,150,400,100),pygame.Rect(625,150,400,100),pygame.Rect(175,300,400,100),pygame.Rect(625,300,400,100),pygame.Rect(175,450,400,100),pygame.Rect(625,450,400,100),pygame.Rect(175,600,400,100),pygame.Rect(625,600,400,100),pygame.Rect(175,750,850,100)]
    levelSelectButtonText = ["Bridge Builder","Map","Dungeon","Watch","Race","Tower Gates","Tower Climber","Boss","Back"]
    
    levelSelectScreen = pygame.Surface((width,height))
    levelSelectScreen.blit(bgImage,(0,0))
    
    titleFont = pygame.font.Font(None, 120)
        
    levelSelectScreen.blit(titleFont.render("Level Select",1,(5,5,5)),(335,35))
    
    for i in range(len(levelSelectButtons)):
    
        pygame.draw.rect(levelSelectScreen,[175,0,0],levelSelectButtons[i])
        
        (x,y) = levelSelectButtons[i].topleft        
        levelSelectScreen.blit(bgButton,(x,y),(0,0,50,100))
        
        middle = 50
        while middle < (levelSelectButtons[i].width - 50):
            levelSelectScreen.blit(bgButton,(x+middle,y),(50,0,50,100))
            middle = middle+50
            
        levelSelectScreen.blit(bgButton,(x+middle,y),(100,0,50,100))
        
        font = pygame.font.Font(None, 80)
        
        displayBox = font.render(levelSelectButtonText[i], 1, (30,30,150))
        textSize = font.size(levelSelectButtonText[i])
    
        levelSelectScreen.blit(displayBox,(levelSelectButtons[i].topleft[0]+(levelSelectButtons[i].width-textSize[0])/2,levelSelectButtons[i].topleft[1]+(100-textSize[1])/2))
    
    screen.blit(mainScreen,(0,0))
    pygame.display.flip()
        
    while run:
    
        mouseRect = pygame.Rect(pygame.mouse.get_pos(),(5,5))  
        
        events = pygame.event.get()
        for event in events: 
            #User decides to exit program
            if event.type == QUIT:              
                run = 0 #stop running
               
            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:
                        levelone.run()
                        levelfour.run()
                        leveltwo.run()
                        levelthree.run()
                        tower.run()
                    elif clickedButton == 1:
                        menuLocation = 1
                        screen.blit(levelSelectScreen,(0,0))
                    elif clickedButton == 2:
                        run = 0
            elif menuLocation == 1:    #On the level select screen
                clickedButton = mouseRect.collidelist(levelSelectButtons)
                if clickedButton != -1:
                    print "Button %d clicked"%(clickedButton)
                    if clickedButton == 0:
                        levelone.run()
                    if clickedButton == 1:
                        leveltwo.run()
                    if clickedButton == 2:
                        levelfive.run()
                    if clickedButton == 3:
                        levelfour.run()
                    if clickedButton == 4:
                        race.run()
                    if clickedButton == 5:
                        levelthree.run()
                    if clickedButton == 6:
                        tower.run()
                    if clickedButton == 7:
                        pass
                    if clickedButton == 8:
                        menuLocation = 0
                        screen.blit(mainScreen,(0,0))
        pygame.display.flip()
        
        clock.tick(40) #limits to 40 FPS
	
    pygame.quit()
    
def main():
    run()
   # levelone.run()
   # levelfour.run()
   # leveltwo.run()
   # levelthree.run()
   # tower.run()
    
if __name__ == '__main__': main()