1
2 """ Pong3d gamelogic module.
3 This define the root of what will run as a whole game, with the aid of other modules. Check the help for some insight of this project.
4
5 Gameplay: press SPACEBAR to launch the ball, move the mouse (recommended) or use the WASD or the arrow keys or even the joystick to move the pad. A game is won by the player who wins 2 sets more than his foe. Each set is won by the player who wons 3 rallies but gotta win 2 rallies more than his foe in case of tie score.
6
7 @author: fabius
8 @copyright: fabius@2010
9 @license: GCTA give credit to (the) authors
10 @version: 0.1
11 @date: 2010-09
12 @contact: astelix (U{panda3d forums<http://www.panda3d.org/forums/profile.php?mode=viewprofile&u=752>})
13 @status: eternal WIP
14 @todo:
15 - spiega gameplay (ENG)
16 @newfield credits: Credits
17 @credits:
18 - 8BITMUSIC credits:
19 - U{a few years later<http://www.8bitpeoples.com/discography/by/minusbaby>}
20 - U{same thing<http://www.8bitpeoples.com/discography/by/8gb>}
21 - U{chiprape<http://www.8bitpeoples.com/discography/by/stu>}
22
23 G{classtree myGame}
24 """
25
26 import sys
27 from pandac.PandaModules import WindowProperties
28 from gamelogic01 import gameLogic01
29 from pandac.PandaModules import loadPrcFileData
30 import scorer
31 loadPrcFileData("", """win-size 800 600
32 win-origin 0 0
33 model-path $MAIN_DIR/data/models/
34 sync-video 0
35 #show-frame-rate-meter #t
36 """
37 )
38
39
41 """
42 Pong game logic derived from simple gemelogic base class.
43 This is the main class, subclassed off his parent base L{gamelogic01} to have a custom game. Other classes are involved to manage menus, inputs, scores and such, and you can find all this stuff in the following files:
44 L{gameLogic01.py<gamelogic01>}, L{scorer.py<scorer>}, L{dgstuff.py<dgstuff>}, L{easyinput.py<easyinput>},
45 """
46 GS_OPPONENTS=['human','cpu']
47 GS_MODES=['3d','3dg']
48 SCOREFILE='pong3d.sco'
52
53
54 - def postgameover(self, score=None):
55 """ manages what happens as the game ends """
56 self.dbgprint("Score report after gameover:\n%r"%score)
57 if score['opponent'] == 'cpu':
58 sc=scorer.scorer(filename=self.SCOREFILE)
59 sc.putscore(self.playername, score['value'])
60 self.abortgame()
61 return None
62
63
65 """ handler called by menu_options_video """
66 reso=['800x600','1024x768']
67 def _setresolution(res, fullscreen=False):
68 wp = WindowProperties()
69 wp.setSize(int(res[0]), int(res[1]))
70 wp.setFullscreen(fullscreen)
71 base.win.requestProperties(wp)
72 if index <> None: _setresolution(reso[index].split('x'))
73
79
81 self.dbgprint(">>>SETTING GAME MODE %s" % self.GS_MODES[index])
82 self.gamesettings['mode']=self.GS_MODES[index]
83 self.menu_options_mode['selected']=index
84 self.pop_menu()
85
87 if v.strip():
88 self.playername=v
89 self.gamesettings['playernames'][1]=self.playername
90
92 self.splashfile='data/textures/splashpong.png'
93 self.titledata={'scorefile': self.SCOREFILE, 'scoredigits': 6,
94 'title': '** TOP 10 SCORES **', 'titlescale': .09,
95 'scale':(1.5, 1.1), 'itemsvisible':10, 'margin': (.1,.15),
96 'texture':'data/models/textures/menu_pong.png',
97 'textfont': loader.loadFont("data/fonts/slkscre.ttf"),
98 'itemswidth': (.9, .4), 'itemsscale':.07,
99 'head': [
100 { 'label': 'Player', 'color':(1,1,1,1), 'textscale':.09},
101 { 'label': 'Score', 'color':(1,1,1,1), 'textscale':.09},
102 ],
103 }
104
105 def menumerge(a, intob):
106 r=intob.copy()
107 r.update(a)
108 return r
109
110 menucommon={'scale':(1.1, .6), 'titlescale':.1, 'pos':(0,0),
111 'texture':'data/models/textures/menu_pong.png',
112 'titlecolor': (1,1,1,1), 'itemscolor': (1,1,1,1), 'itemsscale': .08,
113 'highlightcolor':(0,0,0,1),
114 'textfont': loader.loadFont("data/fonts/slkscre.ttf"),
115 }
116
117 menu={'title': 'Video Options',
118 'callback': self.setvideo,
119 'items': [
120 {'label': '800x600'}, {'label': '1024x768'},
121 {'label': 'back', 'callback': self.pop_menu},
122 ],
123 'exit': self.pop_menu,
124 }
125 self.menu_options_video=menumerge(menu, menucommon)
126
127
128 menu={'title': 'Choose Opponent', 'scale':(1.2, .5),
129 'selected': self.GS_OPPONENTS.index(self.gamesettings['opponent']),
130 'callback': self.setopponent,
131 'items': [
132 {'label': 'Human'},
133 {'label': 'CPU'},
134 {'label': 'back', 'callback': self.pop_menu},
135 ],
136 'exit': self.pop_menu,
137 }
138 self.menu_options_opponent=menumerge(menu, menucommon)
139
140 menu={'title': 'Game Mode', 'scale':(1.2, .5),
141 'selected': self.GS_MODES.index(self.gamesettings['mode']),
142 'callback': self.setgamemode,
143 'items': [
144 {'label': '3D'},
145 {'label': '3D googles'},
146 {'label': 'back', 'callback': self.pop_menu},
147 ],
148 'exit': self.pop_menu,
149 }
150 self.menu_options_mode=menumerge(menu, menucommon)
151
152 menu={'title': 'Options',
153 'items': [
154 {'label': 'video',
155 'callback': lambda foo=None: self.push_menu(self.menu_options_video),
156 },
157 {'label': 'opponent',
158 'callback': lambda foo=None:
159 self.push_menu(self.menu_options_opponent),
160 },
161 {'label': 'game mode',
162 'callback': lambda foo=None:
163 self.push_menu(self.menu_options_mode),
164 },
165 {'label': 'back', 'callback': self.pop_menu},
166 ],
167 'exit': self.pop_menu,
168 }
169 self.menu_options=menumerge(menu, menucommon)
170
171 menu={'title': 'Sure to quit?', 'selected':1,
172 'items': [
173 {'label': 'Yes', 'callback': sys.exit},
174 {'label': 'No', 'callback': self.pop_menu},
175 ],
176 'exit': self.pop_menu,
177 }
178 self.menu_quitgame=menumerge(menu, menucommon)
179
180 def menu_name():
181
182 menu={
183 'align': 'center',
184 'title': 'Put Your Name', 'scale': (1.2,.6), 'margin':(.07, .05),
185 'titlecolor': (1,1,1,1),
186 'initialtext': self.playername, 'inputscale': .07, 'inputwidth': 25,
187 'inputcolor':(0,0,0,1), 'callback': lambda v: self._setplayername(v),
188 'exit': self.pop_menu, 'autoexit': True,
189 }
190 return menumerge(menu, menucommon)
191
192 menu={'title': 'MAIN MENU',
193 'items': [
194 {'label': 'Options',
195 'callback': lambda foo=None: self.push_menu(self.menu_options),
196 },
197 {'label': 'Player Name',
198 'callback': lambda foo=None: self.push_entry(menu_name()),
199 },
200 {'label': 'Exit Game',
201 'callback': lambda foo=None: self.push_menu(self.menu_quitgame),
202 },
203 {'label': 'Back', 'callback': self.pop_menu,},
204 ],
205 'exit': self.pop_menu,
206 }
207 self.menu_main=menumerge(menu, menucommon)
208
209 menu={'title': 'Stop playing?', 'selected': 1, 'scale':(1.2, .5),
210 'items': [
211 {'label': 'Yess', 'callback': self.abortgame, },
212 {'label': 'Nope', 'callback': self.pop_menu, },
213 ],
214 'exit': self.pop_menu,
215 }
216 self.menu_stopgame=menumerge(menu, menucommon)
217
218
219
220 if __name__ == "__main__":
221 from pong3dgpl import gameplay
222 game=myGame(gameplay)
223 run()
224