root/src/main.py @ 281

Revision 281, 8.7 KB (checked in by mmorton, 2 years ago)
Line 
1'''
2Created on Mar 24, 2012
3
4@author: TechTrek
5'''
6import window
7from globals import *
8import pygame, os, math
9from image import Image
10from text import Text
11from rectangle import Rectangle
12import background
13import top
14import onScreenButton
15import inGameMenu
16import sys
17import description
18import menuEntry
19import map
20import spinner
21import mainMenu
22import mainMenuButton
23import researchDescription
24import stats
25
26from pygame.locals import *
27
28
29
30def Initialize():
31    """
32        Returns the top object with everything fully initialized.
33       
34        input type: none
35        return type: top
36    """
37    # surface
38    screenSurface = pygame.display.set_mode((SCREEN_W,SCREEN_H),RESIZABLE)
39    screenSurface.fill(BLACK)
40   
41   
42    newTop = top.Top(screenSurface)
43   
44    gameBackground = background.Background((0,0),True,'background.png')
45   
46    ############################################################################################
47   
48    menuBackground = background.Background((0,0),True,'menuBackground.jpg')
49   
50   
51    mainMenuWindow = mainMenu.MainMenu((400,100),True)
52   
53    newGameButton = mainMenuButton.MainMenuButton((450,170+MAIN_SHIFT*0),True,'New Game')
54    newGameButton.addResponse((menuBackground.closeWindow,))
55    newGameButton.addResponse((gameBackground.openWindow,)) 
56    # will also need to set new state and show opening sequence
57   
58    resumeButton = mainMenuButton.MainMenuButton((450,170+MAIN_SHIFT*1),False,'Resume')
59    resumeButton.addResponse((menuBackground.closeWindow,))
60    resumeButton.addResponse((gameBackground.openWindow,)) 
61   
62    loadButton = mainMenuButton.MainMenuButton((450,170+MAIN_SHIFT*2),True,'Load')
63    # will need a response
64   
65    saveButton = mainMenuButton.MainMenuButton((450,170+MAIN_SHIFT*3),False,'Save')
66    # will need a response
67   
68    quitButton = mainMenuButton.MainMenuButton((450,170+MAIN_SHIFT*4),True,'Quit')
69    quitButton.addResponse((pygame.quit,))
70    quitButton.addResponse((sys.exit,))
71   
72       
73   
74    mainMenuWindow.addWindow(newGameButton)
75    mainMenuWindow.addWindow(resumeButton)
76    mainMenuWindow.addWindow(loadButton)
77    mainMenuWindow.addWindow(saveButton)
78    mainMenuWindow.addWindow(quitButton)
79    menuBackground.addWindow(mainMenuWindow)
80   
81   
82    ###########################################################################################################
83   
84       
85    buildPowerDescription = description.Description('power',
86                                                    "This is where the text would go.",
87                                                    pygame.image.load(os.path.abspath(iconDir + "power.png")))
88    buildPowerButton = menuEntry.MenuEntry((40,100+ENTRY_SHIFT*0),False,buildPowerDescription)
89   
90    buildTransportationDescription = description.Description('transportation',
91                                                    "This is where the text would go.",
92                                                    pygame.image.load(os.path.abspath(iconDir + "transportation.png")))
93    buildTransportationButton = menuEntry.MenuEntry((40,100+ENTRY_SHIFT*1),False,buildTransportationDescription)
94   
95    buildMaterialDescription = description.Description('material',
96                                                    "This is where the text would go.",
97                                                    pygame.image.load(os.path.abspath(iconDir + "material.png")))
98    buildMaterialButton = menuEntry.MenuEntry((40,100+ENTRY_SHIFT*2),False,buildMaterialDescription)
99   
100    buildMenu = inGameMenu.InGameMenu((20,20),False,'BUILD MENU','build.png')
101    buildMenu.addWindow(buildPowerButton)
102    buildMenu.addWindow(buildTransportationButton)
103    buildMenu.addWindow(buildMaterialButton)
104   
105    ###########################################################################################################
106   
107    powerDescription = description.Description("POWER", "you will unlock ... ",  pygame.image.load(os.path.abspath(iconDir + 'power.png')))
108    powerResearchDescription = researchDescription.ResearchDescription((550,250),False,powerDescription)
109   
110    researchPowerDescription = description.Description('power',
111                                                    "This is where the text would go.",
112                                                    pygame.image.load(os.path.abspath(iconDir + "power.png")))
113    researchPowerButton = menuEntry.MenuEntry((40,100+ENTRY_SHIFT*0),False,researchPowerDescription)
114    researchPowerButton.addResponse((powerResearchDescription.toggle,))
115    researchPowerButton.addWindow(powerResearchDescription)
116
117
118    transportDescription = description.Description("TRANSPORTATION", "you will unlock ... ",  pygame.image.load(os.path.abspath(iconDir + 'transportation.png')))
119    transportResearchDescription = researchDescription.ResearchDescription((500,300),False,transportDescription)
120   
121    researchTransportationDescription = description.Description('transportation',
122                                                    "This is where the text would go.",
123                                                    pygame.image.load(os.path.abspath(iconDir + "transportation.png")))
124    researchTransportationButton = menuEntry.MenuEntry((40,100+ENTRY_SHIFT*1),False,researchTransportationDescription)
125    researchTransportationButton.addResponse((transportResearchDescription.toggle,))
126    researchTransportationButton.addWindow(transportResearchDescription)
127   
128   
129    materialDescription = description.Description("MATERIAL", "you will unlock ... ",  pygame.image.load(os.path.abspath(iconDir + 'material.png')))
130    materialResearchDescription = researchDescription.ResearchDescription((500,300),False,materialDescription)
131   
132    researchMaterialDescription = description.Description('material',
133                                                    "This is where the text would go.",
134                                                    pygame.image.load(os.path.abspath(iconDir + "material.png")))
135    researchMaterialButton = menuEntry.MenuEntry((40,100+ENTRY_SHIFT*2),False,researchMaterialDescription)
136    researchMaterialButton.addResponse((materialResearchDescription.toggle,))
137    researchMaterialButton.addWindow(materialResearchDescription)
138   
139   
140    researchMenu = inGameMenu.InGameMenu((20,20),False,'RESEARCH MENU','research.png')
141    researchMenu.addWindow(researchPowerButton)
142    researchMenu.addWindow(researchTransportationButton)
143    researchMenu.addWindow(researchMaterialButton)
144   
145    ###########################################################################################################
146
147    researchButton = onScreenButton.OnScreenButton((20 + 169,720), True,'RESEARCH')
148    researchButton.addWindow(researchMenu)   
149    researchButton.addResponse((researchMenu.toggle,))
150    researchButton.addResponse((buildMenu.closeWindow,)) 
151   
152    buildButton = onScreenButton.OnScreenButton((20,720),True,'BUILD')
153    buildButton.addWindow(buildMenu)   
154    buildButton.addResponse((buildMenu.toggle,))
155    buildButton.addResponse((researchMenu.closeWindow,))
156   
157    endTurnButton = onScreenButton.OnScreenButton((20 + 169*2,720), True,'END TURN')
158   
159    undoTurnButton = onScreenButton.OnScreenButton((20 + 169,20), True,'UNDO TURN')
160   
161    menuButton = onScreenButton.OnScreenButton((20,20),True,'MAIN MENU')
162    menuButton.addResponse((gameBackground.closeWindow,))
163    menuButton.addResponse((menuBackground.openWindow,))
164
165    newMap = map.Map((600,20),True)
166   
167    statsWindow = stats.Stats((600, 450),True,newTop.getSpec())
168   
169   
170    ############################################################################################
171    newTop.addWindow(menuBackground)
172    gameBackground.addWindow(menuButton)
173    gameBackground.addWindow(buildButton)
174    gameBackground.addWindow(researchButton)
175    gameBackground.addWindow(undoTurnButton)
176    gameBackground.addWindow(endTurnButton)
177    gameBackground.addWindow(newMap)
178    gameBackground.addWindow(statsWindow)
179   
180    newTop.addWindow(gameBackground)
181   
182    ############################################################################################
183   
184    newTop.event(pygame.event.Event(VIDEORESIZE, {'w':SCREEN_W, 'h':SCREEN_H}))
185    newTop.render(screenSurface)
186    pygame.display.update()
187    return newTop
188
189if __name__ == '__main__':
190    # initialize pygame modules
191    pygame.init()
192    if not pygame.display.get_init():
193        print "Display Error"
194        pygame.quit()
195        sys.exit()
196       
197    # initialize our game   
198    top = Initialize()
199       
200    # run our game!
201    while True:
202        for e in pygame.event.get():
203            top.event(e)
204
205
206
207   
208   
Note: See TracBrowser for help on using the browser.