55import ImageData
66pygame .init ()
77import DisplayInfo
8- import CharacterData
8+ # import CharacterData
99import Map
1010import TextBox
1111import Creature
2121
2222class GameLoop :
2323 def __init__ (self ):
24- self .timer = pygame .time .Clock ()
25- self .player = PlayerData .PlayerData ("Rena" )
24+ self .timer = GlobalData .timer
2625 self .team = TeamData .TeamData ()
2726 self .maps = dict ()
27+ self .display = GlobalData .display
28+ self .textureManager = GlobalData .textureManager
29+ pygame .font .init ()
30+ self .font = pygame .font .Font (None , 24 )
2831
2932
3033
3134 def initDisplay (self ):
32- GlobalData .display .createScreen ()
35+ self .display .createScreen ()
3336 GlobalData .displayInitilized = 1
3437
3538
@@ -47,8 +50,8 @@ def mainloop(self):
4750 Map .loadTileSet ("Interior_Cave1.png" , 30 , 16 )
4851 self .map = Map .Map ("Exterior_Town1" , "Exterior_Town1-6" , 30 , 30 )
4952 self .maps ["Exterior_Town1" ] = [self .map ]
50- timer = pygame .time .get_ticks ()
51- timeOffset = 0.00
53+ # timer = pygame.time.get_ticks()
54+ # timeOffset = 0.00
5255
5356
5457 while not GlobalData .quitFlag :
@@ -66,14 +69,14 @@ def mainloop(self):
6669
6770
6871 def printFPS (self ):
69- pygame . font . init ()
70- self . font = pygame . font .Font ( None , 24 )
71- GlobalData .display .getScreen ().blit (self .font .render (str (self .timer . get_fps () ), 0 , (255 ,255 ,255 )), (24 ,24 ))
72- GlobalData .display .getScreen ().blit (self .font .render ("X :" + str (self .map .getXoff ()/ 24 ), 0 , (255 ,255 ,255 )), (24 ,48 ))
73- GlobalData .display .getScreen ().blit (self .font .render ("Y :" + str (self .map .getYoff () / 24 ), 0 , (255 ,255 ,255 )), (24 ,72 ))
74- GlobalData .display .getScreen ().blit (self .font .render ("PrevX :" + str (self .map .prevXoff / 24 - 1 ), 0 , (255 ,255 ,255 )), (24 ,96 ))
75- GlobalData .display .getScreen ().blit (self .font .render ("PrevY :" + str (self .map .prevYoff / 24 - 1 ), 0 , (255 ,255 ,255 )), (24 ,120 ))
76- GlobalData .display .getScreen ().blit (self .font .render ("Monsters :" + str (self .map .hasMonsters ), 0 , (255 ,255 ,255 )), (24 ,144 ))
72+ if GlobalData . debugMode :
73+ self . display . getScreen (). blit ( self . font .render ( str ( self . timer . get_fps ()), 0 , ( 255 , 255 , 255 )), ( 24 , 24 ) )
74+ self .display .getScreen ().blit (self .font .render ("X:" + str (self .map . getXoff () / 24 ), 0 , (255 ,255 ,255 )), (24 ,48 ))
75+ self .display .getScreen ().blit (self .font .render ("Y :" + str (self .map .getYoff ()/ 24 ), 0 , (255 ,255 ,255 )), (24 ,72 ))
76+ self .display .getScreen ().blit (self .font .render ("PrevX :" + str (self .map .prevXoff / 24 - 1 ), 0 , (255 ,255 ,255 )), (24 ,96 ))
77+ self .display .getScreen ().blit (self .font .render ("PrevY :" + str (self .map .prevYoff / 24 - 1 ), 0 , (255 ,255 ,255 )), (24 ,120 ))
78+ self .display .getScreen ().blit (self .font .render ("Monsters :" + str (self .map .hasMonsters ), 0 , (255 ,255 ,255 )), (24 ,144 ))
79+ self .display .getScreen ().blit (self .font .render ("Freq :" + str (self .map .freq ), 0 , (255 ,255 ,255 )), (24 ,168 ))
7780
7881 def flipScreenBuffer (self ):
7982 pygame .display .flip ()
@@ -130,45 +133,69 @@ def playerInput(self, event):
130133 self .map .setXYoff (self .map .getXoff (), self .map .getYoff () - 6 )
131134 self .mods = pygame .key .get_mods ()
132135 if event .key == K_RETURN and (self .mods == 4160 or self .mods == 20480 or self .mods == 256 or self .mods == 512 ):
133- if GlobalData .display .isFullscreen == 0 :
134- GlobalData .display .isFullscreen = 1
135- GlobalData .display .createScreen ()
136+ if self .display .isFullscreen == 0 :
137+ self .display .isFullscreen = 1
138+ self .display .createScreen ()
136139 else :
137- GlobalData .display .isFullscreen = 0
138- GlobalData .display .createScreen ()
140+ self .display .isFullscreen = 0
141+ self .display .createScreen ()
139142 elif event .key == K_RETURN :
140143 #print len(self.map.allTiles[4][4].contents)
141144 if self .player .facing is 4 and self .map .currentPiece .array [13 ][9 ].text != "" :
142145 TextBox .QuickBox ( 48 , 48 , self .map .currentPiece .array [13 ][9 ].text )
143146 if len (self .map .currentPiece .array [13 ][9 ].contents ) != 0 :
147+ #print self.map.currentPiece.array[13][9].contents
144148 self .map .drawMap ()
145- self .player .display ()
149+ self .player .displayOnMap ()
146150 self .gotItem ( 48 , 48 , self .map .currentPiece .array [13 ][9 ])
147151 elif self .player .facing is 8 and self .map .currentPiece .array [12 ][10 ].text != "" :
148152 TextBox .QuickBox ( 48 , 48 , self .map .currentPiece .array [12 ][10 ].text )
149153 if len (self .map .currentPiece .array [12 ][10 ].contents ) != 0 :
154+ #print self.map.currentPiece.array[12][10].contents
150155 self .map .drawMap ()
151- self .player .display ()
156+ self .player .displayOnMap ()
152157 self .gotItem ( 48 , 48 , self .map .currentPiece .array [12 ][10 ])
153158 elif self .player .facing is 12 and self .map .currentPiece .array [11 ][9 ].text != "" :
154159 TextBox .QuickBox ( 48 , 48 , self .map .currentPiece .array [11 ][9 ].text )
155160 if len (self .map .currentPiece .array [11 ][9 ].contents ) != 0 :
161+ #print self.map.currentPiece.array[11][9].contents
156162 self .map .drawMap ()
157- self .player .display ()
163+ self .player .displayOnMap ()
158164 self .gotItem ( 48 , 48 , self .map .currentPiece .array [11 ][9 ])
159165 elif self .player .facing is 0 and self .map .currentPiece .array [12 ][8 ].text != "" :
160166 TextBox .QuickBox ( 48 , 48 , self .map .currentPiece .array [12 ][8 ].text )
161167 if len (self .map .currentPiece .array [12 ][8 ].contents ) != 0 :
168+ #print self.map.currentPiece.array[12][8].contents
162169 self .map .drawMap ()
163- self .player .display ()
170+ self .player .displayOnMap ()
164171 self .gotItem ( 48 , 48 , self .map .currentPiece .array [12 ][8 ])
165172 elif event .key == 105 :
166173 self .startMenu ()
167-
174+
175+ elif event .key == 282 :
176+ if GlobalData .debugMode :
177+ if self .map .hasMonsters is True :
178+ self .map .hasMonsters = False
179+ elif GlobalData .mapsData [self .map .name ][2 ] == True :
180+ self .map .hasMonsters = True
181+
182+ elif event .key == 96 :
183+ if GlobalData .debugMode :
184+ GlobalData .debugMode = False
185+ else :
186+ GlobalData .debugMode = True
187+ elif event .key == 45 :
188+ if GlobalData .debugMode :
189+ if self .map .freq > 1 :
190+ self .map .freq -= 1
191+ elif event .key == 61 :
192+ if GlobalData .debugMode :
193+ self .map .freq += 1
194+
168195 if event .key > 272 and event .key < 277 :
169196 self .map .drawMap ()
170197 self .player .setFacing (self .player .facing + 1 )
171- self .player .display ()
198+ self .player .displayOnMap ()
172199 self .printFPS ()
173200 self .flipScreenBuffer ()
174201 pygame .time .delay (50 )
@@ -177,10 +204,9 @@ def battle(self):
177204 self .instance = Battle .Battle (self .map , self .team )
178205 self .newSkins = self .instance .battleMain ()
179206 if self .newSkins is not None :
180- for x in self .newSkins :
207+ for x in range ( len ( self .newSkins )) :
181208 self .team .team [x ].currentSkin = self .newSkins [x ]
182- if self .player .name is x :
183- self .player .currentSkin = self .newSkins [x ]
209+
184210
185211 def portal (self ):
186212 self .list = self .map .currentPiece .array [12 ][9 ].portal .split (';' )
@@ -196,22 +222,25 @@ def portal(self):
196222 self .map .startPieceOffsetX = self .xPiece
197223 self .map .startPieceOffsetY = self .yPiece
198224 self .map .startPieceName = self .startPiece
199- #GlobalData .display.getScreen().fill((0,0,0))
225+ #self .display.getScreen().fill((0,0,0))
200226 for x in range (- 1 ,26 ):
201227 for y in range (- 1 ,20 ):
202228 self .map .currentPiece .array [x ][y ] = self .map .allTiles [- self .map .Xoff / 24 + x + self .map .startPieceOffsetX ][- self .map .Yoff / 24 + y + self .map .startPieceOffsetY ]
203229 #print str(self.map.currentPiece)
204230
205231 def initPlayer (self ):
206232 PlayerData .loadPlayerGraphics ("rena" , "nightgown" )
207- self .player .currentSkin = "rena_nightgown"
208- self .team .add ("Rena" , CharacterData .CharacterData ("Rena" ))
209- self .team .team ["Rena" ].currentSkin = "rena_nightgown"
233+ PlayerData .loadPlayerGraphics ("miles" , "coat" )
234+ self .team .add (PlayerData .PlayerData ("Rena" ))
235+ self .team .team [0 ].currentSkin = "rena_nightgown"
236+ self .team .add (PlayerData .PlayerData ("Miles" ))
237+ self .team .team [1 ].currentSkin = "miles_coat"
238+ self .player = self .team .team [0 ]
210239 self .player .setPosition (288 , 192 )
211- self .player .display ()
240+ self .player .displayOnMap ()
212241
213242 def drawWorld (self ):
214-
243+ self . player . currentSkin = self . team . team [ 0 ]. currentSkin
215244 #print self.map.objectManager.collisionRects
216245 if (self .map .getXoff () % 24 ) is not 0 :
217246 if self .player .facing > 3 and self .player .facing < 7 :
@@ -226,7 +255,7 @@ def drawWorld(self):
226255 if self .map .currentPiece .array [12 ][9 ].portal != "" :
227256 self .portal ()
228257 if self .map .hasMonsters == True :
229- random . seed ()
258+
230259 self .chance = random .randint (0 ,self .map .freq )
231260 #print self.chance
232261 if self .chance == 0 :
@@ -244,7 +273,7 @@ def drawWorld(self):
244273 if self .map .currentPiece .array [12 ][9 ].portal != "" :
245274 self .portal ()
246275 if self .map .hasMonsters == True :
247- random . seed ()
276+
248277 self .chance = random .randint (0 ,self .map .freq )
249278 #print self.chance
250279 if self .chance == 0 :
@@ -263,7 +292,7 @@ def drawWorld(self):
263292 if self .map .currentPiece .array [12 ][9 ].portal != "" :
264293 self .portal ()
265294 if self .map .hasMonsters == True :
266- random . seed ()
295+
267296 self .chance = random .randint (0 ,self .map .freq )
268297 #print self.chance
269298 if self .chance == 0 :
@@ -281,24 +310,25 @@ def drawWorld(self):
281310 if self .map .currentPiece .array [12 ][9 ].portal != "" :
282311 self .portal ()
283312 if self .map .hasMonsters == True :
284- random . seed ()
313+
285314 self .chance = random .randint (0 ,self .map .freq )
286315 #print self.chance
287316 if self .chance == 0 :
288317 self .battle ()
289318
290319
291320 self .map .drawMap ()
292- self .player .display ()
321+ self .player .displayOnMap ()
293322
294323
295324 def gotItem (self , x , y , mapTile ):
296325 for z in mapTile .contents :
297- self .team .shit [ z . name ] = z
326+ self .team .addShit ( z )
298327 self .box = TextBox .TextBox (x , y , "You receieved " + z .name + "." )
299- mapTile .contents .remove (z )
300328 self .open = True
301329 while self .open :
330+ self .map .drawMap ()
331+ self .player .displayOnMap ()
302332 self .box .draw ()
303333 pygame .display .flip ()
304334 for e in pygame .event .get ():
@@ -308,6 +338,8 @@ def gotItem(self, x, y, mapTile):
308338 elif e .type == KEYDOWN :
309339 if e .key == K_RETURN :
310340 self .open = False
341+ mapTile .contents = []
342+
311343
312344
313345 def startMenu (self ):
0 commit comments