root/src/main.py @ 285

Revision 285, 9.7 KB (checked in by mmorton, 2 years ago)

build menus working in full, build button broken

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