-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
592 lines (582 loc) · 25.4 KB
/
main.py
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
name = __name__ == "__main__"
if name:
print("Importing modules")
import pygame,client,time,screenLib,math,os,sys,render,importlib,traceback,mapGenerator,ctypes
ControllerMoveRate = 0.1 #Times a second to move pointer when controller button is held
class ControllerBase:
def __init__(self): #Make a fake controller
self.cont = None
self.init()
def init(self):
self.__hold = {} #Used to track controller holding
self.__change = {"Up":False,"Dw":False,"L":False,"R":False,"BD":False,"ND":False,"QO":False,"S":False,"B":False,"E":False,"MU":False}
self.keyName = {} #Used for command hints
self.keyName["menuUp"] = "Up arrow"
self.keyName["menuDown"] = "Down arrow"
self.keyName["menuLeft"] = "Left arrow"
self.keyName["menuRight"] = "Right arrow"
self.keyName["bfDrone"] = "Left trigger"
self.keyName["nxDrone"] = "Right trigger"
self.keyName["qOpen"] = "Quick open"
self.keyName["select"] = "Select"
self.keyName["back"] = "Back"
self.keyName["scem"] = "Scematic view"
self.keyName["mov"] = "Left trackball"
self.keyName["aim"] = "Right trackball"
self.keyName["menu"] = "Start"
if not self.cont is None:
self.cont.init()
for a in self.__change:
self.__hold[a] = -1
def __holding(self,key):
if self.__hold[key]!=-1 and self.__change[key]: #Holding and key is down
if time.time()>self.__hold[key]:
self.__hold[key] = time.time()+ControllerMoveRate
return True
elif self.__hold[key]!=-1: #Still holding
self.__hold[key] = -1
if self.__change[key] and self.__hold[key]==-1:
self.__hold[key] = time.time()+0.4
return False
def getMovement(self,inMenu=False):
return [0,0]
def getAim(self,inMenu=False):
return [0,0]
def vibrate(self,duration,perc): #Vibrate the controller
pass
def loop(self):
pass
def getMenuUp(self):
return False
def getMenuDown(self):
return False
def getMenuLeft(self):
return False
def getMenuRight(self):
return False
def beforeDrone(self):
return False
def nextDrone(self):
return False
def quickOpen(self):
return False
def select(self):
return False
def back(self):
return False
def enterScematicView(self):
return False
def getMenu(self):
return False
def getMenuUpChange(self):
if self.__change["Up"]!=self.getMenuUp():
self.__change["Up"] = self.getMenuUp()
return True
return self.__holding("Up")
def getMenuDownChange(self):
if self.__change["Dw"]!=self.getMenuDown():
self.__change["Dw"] = self.getMenuDown()
return True
return self.__holding("Dw")
def getMenuLeftChange(self):
if self.__change["L"]!=self.getMenuLeft():
self.__change["L"] = self.getMenuLeft()
return True
return self.__holding("L")
def getMenuRightChange(self):
if self.__change["R"]!=self.getMenuRight():
self.__change["R"] = self.getMenuRight()
return True
return self.__holding("R")
def beforeDroneChange(self):
if self.__change["BD"]!=self.beforeDrone():
self.__change["BD"] = self.beforeDrone()
return True
return self.__holding("BD")
def nextDroneChange(self):
if self.__change["ND"]!=self.nextDrone():
self.__change["ND"] = self.nextDrone()
return True
return self.__holding("ND")
def quickOpenChange(self):
if self.__change["QO"]!=self.quickOpen():
self.__change["QO"] = self.quickOpen()
return True
return self.__holding("QO")
def selectChange(self):
if self.__change["S"]!=self.select():
self.__change["S"] = self.select()
return True
return self.__holding("S")
def backChange(self):
if self.__change["B"]!=self.back():
self.__change["B"] = self.back()
return True
return self.__holding("B")
def enterScematicViewChange(self):
if self.__change["E"]!=self.enterScematicView():
self.__change["E"] = self.enterScematicView()
return True
return self.__holding("E")
def getMenuChange(self):
if self.__change["MU"]!=self.getMenu():
self.__change["MU"] = self.getMenu()
return True
return self.__holding("MU")
class XINPUT_VIBRATION(ctypes.Structure):
_fields_ = [("wLeftMotorSpeed", ctypes.c_ushort),
("wRightMotorSpeed", ctypes.c_ushort)]
class XBoxController(ControllerBase):
def __init__(self,cont):
self.cont = cont
self.init()
####### This is not my code but will setup vibration #######
xinput = ctypes.windll.xinput1_1
self.__XInputSetState = xinput.XInputSetState
self.__XInputSetState.argtypes = [ctypes.c_uint, ctypes.POINTER(XINPUT_VIBRATION)]
self.__XInputSetState.restype = ctypes.c_uint
#Source = https://stackoverflow.com/questions/20499946/xbox-360-vibrate-rumble
self.__vibStart = -1
self.keyName["qOpen"] = "Y"
self.keyName["select"] = "A"
self.keyName["back"] = "B"
self.keyName["scem"] = "X"
def vibrate(self,duration,perc): #Vibrate the controller
vibration = XINPUT_VIBRATION(int(65535*perc), int(32768*perc))
self.__XInputSetState(0, ctypes.byref(vibration))
self.__vibStart = time.time()+duration
def loop(self):
if time.time()>self.__vibStart and self.__vibStart!=-1:
self.vibrate(0,0)
self.__vibStart = -1
def test(self): #Test if controller has all its buttons
return self.cont.get_numbuttons()==10 and self.cont.get_numhats()==1 and self.cont.get_numaxes()==5
def getMenu(self): #Get the menu access button
return self.cont.get_button(7)
def getMovement(self,inMenu=False):
return [self.cont.get_axis(0),self.cont.get_axis(1)]
def getAim(self,inMenu=False):
#Either return a list for x and y or a rotation movement
return [self.cont.get_axis(4),self.cont.get_axis(3)]
def getMenuUp(self):
x,y = self.cont.get_hat(0)
return y>0.5 and abs(x)<0.5
def getMenuDown(self):
x,y = self.cont.get_hat(0)
return y<-0.5 and abs(x)<0.5
def getMenuLeft(self):
x,y = self.cont.get_hat(0)
return x<-0.5 and abs(y)<0.5
def getMenuRight(self):
x,y = self.cont.get_hat(0)
return x>0.5 and abs(y)<0.5
def beforeDrone(self):
return self.cont.get_axis(2)>0.5
def nextDrone(self):
return self.cont.get_axis(2)<-0.5
def quickOpen(self):
return self.cont.get_button(3)
def select(self):
return self.cont.get_button(0)
def back(self):
return self.cont.get_button(1)
def enterScematicView(self):
return self.cont.get_button(2)
class N64Controller(ControllerBase):
def __init__(self,cont):
self.cont = cont
self.init()
self.keyName["qOpen"] = "A"
self.keyName["select"] = "X"
self.keyName["back"] = "B"
self.keyName["scem"] = "Y"
self.keyName["mov"] = "Arrow keys"
self.keyName["aim"] = "Arrow keys"
def test(self):
return self.cont.get_numbuttons()==10 and self.cont.get_numaxes()==2
def getMovement(self,inMenu=False):
if inMenu:
return 0
else:
return self.cont.get_axis(1)
def getAim(self,inMenu=False):
if inMenu:
return 0
else:
return self.cont.get_axis(0)
def getMenu(self):
return self.cont.get_button(9)
def getMenuUp(self):
return self.cont.get_axis(1)<-0.5
def getMenuDown(self):
return self.cont.get_axis(1)>0.5
def getMenuLeft(self):
return self.cont.get_axis(0)<-0.5
def getMenuRight(self):
return self.cont.get_axis(0)>0.5
def beforeDrone(self):
return self.cont.get_button(4)
def nextDrone(self):
return self.cont.get_button(5)
def quickOpen(self):
return self.cont.get_button(3)
def select(self):
return self.cont.get_button(0)
def back(self):
return self.cont.get_button(2)
def enterScematicView(self):
return self.cont.get_button(1)
class PS3Controller(ControllerBase):
def __init__(self,cont):
self.cont = cont
self.init()
self.keyName["qOpen"] = "Triangle"
self.keyName["select"] = "X"
self.keyName["back"] = "O"
self.keyName["scem"] = "Square"
def test(self):
return self.cont.get_numbuttons()==15 and self.cont.get_numhats()==1 and self.cont.get_numaxes()==4
def getMovement(self,inMenu=False):
return [self.cont.get_axis(0),self.cont.get_axis(1)]
def getAim(self,inMenu=False):
return [self.cont.get_axis(2),self.cont.get_axis(3)]
def getMenu(self):
return self.cont.get_button(11)
def getMenuUp(self):
x,y = self.cont.get_hat(0)
return y>0.5
def getMenuDown(self):
x,y = self.cont.get_hat(0)
return y<-0.5
def getMenuLeft(self):
x,y = self.cont.get_hat(0)
return x<-0.5
def getMenuRight(self):
x,y = self.cont.get_hat(0)
return x>0.5
def beforeDrone(self):
return self.cont.get_button(6) or self.cont.get_button(8)
def nextDrone(self):
return self.cont.get_button(7) or self.cont.get_button(9)
def quickOpen(self):
return self.cont.get_button(4)
def select(self):
return self.cont.get_button(0)
def back(self):
return self.cont.get_button(1)
def enterScematicView(self):
return self.cont.get_button(3)
CONTROLLERS = {}
CONTROLLERS["Controller (XBOX 360 For Windows)"] = XBoxController
CONTROLLERS["usb gamepad "] = N64Controller
CONTROLLERS["HJD-X"] = PS3Controller
def reloadControllers(LINK):
pygame.joystick.init()
conts = pygame.joystick.get_count()
LINK["controller"] = None
if conts!=0:
controllers = []
for i in range(conts): #Find a compatable controller
controller = pygame.joystick.Joystick(i)
if controller.get_name() in CONTROLLERS:
controllers.append( [controller.get_name(),pygame.joystick.Joystick(i)])
else: #Unknown controller, test its keys to find if it matches any preset controllers
for a in CONTROLLERS:
test = CONTROLLERS[a](controller)
if test.test():
controllers.append( [a,controller] )
print("Unknown controller controller assigned to "+a+" button layout")
break
else:
print("Unknown controller connected",controller.get_name())
if len(controllers)!=0:
LINK["controller"] = CONTROLLERS[controllers[0][0]](controllers[0][1])
if len(controllers)!=1: #More than 1 controller plugged in
LINK["controller2"] = CONTROLLERS[controllers[1][0]](controllers[1][1])
if name: #Is the main thread
print("Loading pygame")
pygame.init()
print("Building varaibles")
FPS = 60 #Default FPS
RESLUTION = [1200,700]
def ERROR(*info): #This function is called whenever an unexspected error occures. It is mainly so it can be displayed on the screen without the game crashing
print("Err: ",info) #Tempory
traceback.print_exc()
if LINK["DEV"]: #If in development mode then exit the game
pygame.quit()
sys.exit(1)
def ADDLOG(mes): #Used to show logs (used for console)
#print(mes)
pass #Tempory because of a windows 10 bug with printing
def loadScreen(name,*args): #Loads a screen
global currentScreen
if name in LINK["screens"]: #Screen exists
ADDLOG("Loading screen - "+name)
currentScreen = LINK["screens"][name].Main(LINK,*args)
ADDLOG("Loaded!")
LINK["currentScreen"] = currentScreen
else:
ERROR("Attempt to load a screen that doesen't exist '"+name+"'")
LINK = {} #This is a global variable for allowing controll over the whole program through one variable. Every class in this program should have a link to this!
LINK["errorDisplay"] = ERROR #Used to show errors
LINK["reslution"] = RESLUTION #Reslution of the game
LINK["befRes"] = None #Before reslution
LINK["DEV"] = False #Development mode, this will stop the game when errors occur.
LINK["loadScreen"] = loadScreen #Used so other scripts can load the map
LINK["render"] = render #Used so other scripts can use its tools for rendering
LINK["screenLib"] = screenLib #Used as a GUI tool for the map designer
LINK["log"] = ADDLOG #Used to log infomation (not seen in game unless developer console is turned on)
LINK["DEVDIS"] = False #Development display
LINK["showFPS"] = False #If the FPS counter should be shown
LINK["NPCignorePlayer"] = False #Used for development
LINK["floorScrap"] = True #Enable/disable floor scrap
LINK["particles"] = True #Enable/disable particle effects
LINK["showRooms"] = False #Used by survayor upgade to show rooms and doors
LINK["popView"] = False #Cause rooms to pop into view (reduced CPU load but ajasent rooms arn't rendered)
LINK["splitScreen"] = False #Is the game running in split screen?
LINK["menuFade"] = True #Menu effects
LINK["client"] = client
LINK["hintDone"] = [] #List of hints that are shown
pygame.joystick.init()
LINK["controller"] = None
LINK["controller2"] = None #Player 2 (if two controllers are plugged in)
reloadControllers(LINK)
main = pygame.display.set_mode(RESLUTION,pygame.RESIZABLE)
pygame.display.set_caption("REMOTE")
clock = pygame.time.Clock()
currentScreen = None #The currently open screen
LINK["currentScreen"] = currentScreen
LINK["main"] = main #Main pygame window
#Fonts
LINK["font24"] = pygame.font.Font("comandFont.ttf",24)
LINK["font16"] = pygame.font.Font("comandFont.ttf",16)
LINK["font42"] = pygame.font.Font("comandFont.ttf",42)
LINK["font64"] = pygame.font.Font("comandFont.ttf",64)
LINK["font128"] = pygame.font.Font("comandFont.ttf",128)
#Controlls (can be changed)
LINK["controll"] = {} #Used to let controlls for the game be changable
LINK["controll"]["up"] = pygame.K_UP #Up arrow key
LINK["controll"]["down"] = pygame.K_DOWN #Down arrow key
LINK["controll"]["left"] = pygame.K_LEFT #Left arrow key
LINK["controll"]["right"] = pygame.K_RIGHT #Right arrow key
LINK["controll"]["escape"] = pygame.K_ESCAPE #Escaping key for closing menus
LINK["controll"]["resetScroll"] = pygame.K_BACKSPACE #Reset scroll position in map editor key
LINK["mesh"] = {} #Used for fast entity discovery
LINK["upgradeIDCount"] = 0 #ID count for upgrades
LINK["scrapCollected"] = 0 #Amount of scrap colected
LINK["fuelCollected"] = 0 #Amount of fuel colected
LINK["shipData"] = {"fuel":5,"scrap":50,"shipUpgs":[],"maxShipUpgs":2,"reserveUpgs":[],"reserveMax":8,"invent":[],
"beforeMap":-1,"mapSaves":[],"maxScore":0,"reserve":[],"maxDrones":4,"maxReserve":2,"maxInvent":70,"doneMaps":[],"name":"Your ship","mxScrap":50} #Data about the players ship
#Reference:
#'fuel' - Amount of fuel inside the ship
#'scrap' - Amount of scrap insdie the ship
#'shupUpgs' - List of ship upgrades
#'maxShipUpgs' - Maximum number of ship upgrades allowed on the ship when docked.
#'reserveUpgs' - Reserve ship upgrades
#'reserveMax' - Maximum reserve upgrades allowed on the ship
#'invent' - Upgrade inventory (not on the drones)
#'beforeMap' - Index of the previously loaded map (stops the same map being played twise)
#'mapSaves' - Stores info about previously generated maps
#'maxScore' - Overall score added up each map
#'reserve' - Drones in reserve
#'maxDrones' - Maximum number of drones the ship can take on a mission
#'maxReserve' - Maximum number of reserve drones
#'doneMaps' - List of maps that have been completed
LINK["allPower"] = False #Enable global power, a cheat for development
LINK["absoluteDoorSync"] = False #Send packets randomly to make doors in SYNC perfectly (bigger the map the more packets)
LINK["simpleModels"] = False #Enable/disable simple models
LINK["hints"] = False #Enable game hints or not
LINK["threading"] = False #Enable/disable cleint-side socket threading
LINK["backgroundStatic"] = False #Enable/disable background static
LINK["viewDistort"] = True #Drone view distortion
LINK["names"] = [] #Drone names
with open("droneNames.txt","r") as file:
for a in file:
if a!="":
LINK["names"].append(a.strip())
LINK["shipNames"] = [] #Ship names
with open("shipNames.txt","r") as file:
for a in file:
if a!="":
LINK["shipNames"].append(a.strip())
LINK["backToMapEdit"] = "" #Play testing is over, go back to map editor
LINK["simpleMovement"] = False #Simplified movement
LINK["commandSelect"] = True #Command selecting window
LINK["IPADD"] = "" #IP address
LINK["serverObj"] = None #This will be set up when the game is running as a server and a client
LINK["multi"] = 0 #Is the game currently multiplayer, -1 = Map editor, 0 = Single player, 1 = Client, 2 = Server
print("Loading content")
#Load all content from the folders...
#Screens
files = os.listdir("screens")
LINK["screens"] = {}
for a in files:
if a[-3:]==".py":
LINK["screens"][a[:-3]] = importlib.import_module("screens."+a[:-3])
#Entities
files = os.listdir("entities")
LINK["ents"] = {}
for a in files:
if a[-3:]==".py":
LINK["ents"][a[:-3]] = importlib.import_module("entities."+a[:-3])
#Content
files = os.listdir("content")
LINK["content"] = {} #Images
LINK["models"] = {} #3D models
for a in files:
if a[-4:]==".png":
LINK["content"][a[:-4]] = pygame.image.load("content/"+a)
elif a[-4:]==".obj":
LINK["models"][a[:-4]] = render.openModel("content/"+a)
LINK["cont"] = {} #This is used for storing "content" in LINK but is resized every frame.
pygame.display.set_icon(LINK["content"]["gameIcon"])
#Maps
LINK["maps"] = os.listdir("maps")
#Upgrades
files = os.listdir("upgrades")
LINK["upgrade"] = {} #Drone upgrades
LINK["shipUp"] = {} #Ship upgrades
for a in files:
if a[-3:]==".py":
itm = importlib.import_module("upgrades."+a[:-3])
if a=="base.py":
LINK["upgrade"][a[:-3]] = itm
elif itm.Main(LINK).droneUpgrade:
LINK["upgrade"][a[:-3]] = itm
else:
LINK["shipUp"][a[:-3]] = itm
class NULLENT(LINK["ents"]["base"].Main): #Null entity for keeping the game running when an entity doesen't exist
def __init__(self,x,y,LINK,ID):
self.init(x,y,LINK)
self.ID = ID
self.settings = {}
self.pos = [x,y]
self.size = [50,50]
self.LINK = LINK
self.HINT = True
def editMove(*args):
pass
def SaveFile(self):
return []
def loop(self,lag):
pass
def rightInit(self,surf):
self.__surface = pygame.Surface((50,50))
self.__lastRenderPos = [0,0]
def rightLoop(self,mouse,kBuf):
pass
def rightUnload(self):
self.__surface = None
self.__lastRenderPos = None
def rightRender(self):
pass
def sRender(self,x,y,scale,surf=None,edit=False):
self.renderHint(surf,"Null entity, please remove.",[x,y])
LINK["null"] = NULLENT
print("Initilazing drones")
LINK["drones"] = [] #Drone list of the players drones
for i in range(0,3):
LINK["drones"].append(LINK["ents"]["drone"].Main(i*60,0,LINK,-2-i,i+1))
LINK["drones"][0].settings["upgrades"][0] = ["motion",0,-1]
LINK["drones"][0].settings["upgrades"][1] = ["gather",0,-1]
LINK["drones"][1].settings["upgrades"][0] = ["generator",0,-1]
LINK["drones"][2].settings["upgrades"][0] = ["interface",0,-1]
LINK["drones"][2].settings["upgrades"][1] = ["tow",0,-1]
LINK["drones"][0].loadUpgrades()
LINK["drones"][1].loadUpgrades()
LINK["drones"][2].loadUpgrades()
LINK["shipEnt"] = LINK["ents"]["ship"].Main(0,0,LINK,-1)
LINK["shipEnt"].settings["upgrades"][0] = ["remote power",0,-1]
LINK["shipEnt"].loadUpgrades()
if LINK["multi"]==1: #Client (tempory)
CLI = client.Client("127.0.0.1",3746,LINK["threading"])
LINK["cli"] = CLI
fakeController = ControllerBase()
loadScreen("mainMenu") #Load the main game screen
#currentScreen.open("level2.map")
print("Going into event loop")
run = True
ESC = None #Escape menu
lastTime = time.time()-0.1
while run:
lag = (time.time()-lastTime)*30
if lag>6: #Limit to how slow the game can skip
lag = 6
lastTime = time.time()
KeyEvent = [] #A list of key events to send to all users
if not LINK["controller"] is None:
if LINK["controller"].getMenuChange():
if LINK["controller"].getMenu():
pygame.event.post(pygame.event.Event(pygame.KEYDOWN,{"key":pygame.K_ESCAPE}))
else:
pygame.event.post(pygame.event.Event(pygame.KEYUP,{"key":pygame.K_ESCAPE}))
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN or event.type == pygame.KEYUP or event.type==pygame.QUIT:
KeyEvent.append(event)
if event.type == pygame.KEYDOWN and ESC is None and not type(currentScreen)==LINK["screens"]["mainMenu"].Main:
if event.key == pygame.K_ESCAPE:
NO = False
if type(currentScreen)==LINK["screens"]["game"].Main:
if len(currentScreen.force)!=0:
NO = True
if not NO:
ESC = LINK["screens"]["escape"].Main(LINK)
if event.type == 6: #Mouse wheel
KeyEvent.append(event)
if event.type==pygame.VIDEORESIZE:
if LINK["splitScreen"]:
LINK["reslution"] = [event.dict['size'][0],int(event.dict['size'][1]/2)]
else:
LINK["reslution"] = list(event.dict['size'])
LINK["main"] = pygame.display.set_mode(event.dict['size'],pygame.RESIZABLE) #Remake the pygame window
if not currentScreen is None:
currentScreen.resized()
mouseRaw = pygame.mouse.get_pressed()
mouse = [mouseRaw[0]]+list(pygame.mouse.get_pos())+[mouseRaw[1],mouseRaw[2]]
if LINK["multi"]==1:
try:
LINK["cli"].loop()
except:
if LINK["DEV"]:
raise
ERROR("Error when running client loop",sys.exc_info())
if not LINK["serverObj"] is None:
LINK["serverObj"].value = int(time.time()+2)
if not currentScreen is None:
try:
if ESC is None:
currentScreen.loop(mouse,KeyEvent,lag)
else:
HOLD,LINK["controller"] = LINK["controller"],fakeController
currentScreen.loop(mouse,[],lag)
LINK["controller"] = HOLD
ESC.loop(mouse,KeyEvent,lag)
if ESC.exit:
ESC = None
except:
if LINK["DEV"]:
raise
ERROR("Error inside screen event loop",sys.exc_info())
if not LINK["controller"] is None:
LINK["controller"].loop()
if not LINK["controller2"] is None:
LINK["controller2"].loop()
main.fill((0,0,0))
if not currentScreen is None:
try:
currentScreen.render(main)
except:
if LINK["DEV"]:
raise
ERROR("Error when rendering screen",sys.exc_info())
if not ESC is None:
ESC.render(main)
if LINK["showFPS"]:
main.blit(LINK["font24"].render("FPS: "+str(int(30/lag)),16,(255,255,255)),[0,0])
pygame.display.flip()
clock.tick(FPS)
pygame.quit()
if LINK["multi"]==1:
LINK["cli"].close()