-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_game.py
109 lines (90 loc) · 2.74 KB
/
run_game.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
import pygame
import sys
from src.utilities import *
from src.update import *
from src.room import *
from src.player import *
from src.loader import *
from src.constants import *
from src.room import *
from src.graphics import *
from src.area import *
from src.hud import *
from src.menus import *
import src.globe as globe
pygame.init()
pygame.display.set_caption(WINDOW_CAPTION)
FPS_CLOCK = pygame.time.Clock()
ELAPSED = 10
fps_meter = fps_meter()
#singletons handled here
globe.Loader = Loader()
globe.Loader.LoadAreas(['Default', 'Common'])
globe.State = State()
globe.Updater = Updater()
globe.Area = Area()
globe.Area.loadArea('test')
globe.Camera = Camera()
globe.Hud = Hud()
globe.State.addState('started')
iDown = False
lDown = False
updateToggle = False
fullScreen = False
globe.Hud.displayMenu(TitleScreen())
while True:
#print('NEXT FRAME')
if(ELAPSED > MAX_FRAME_TIME):
ELAPSED = MAX_FRAME_TIME
events = pygame.event.get()
#events = pygame.event.get()
globe.Camera.fillScreen()
globe.Updater.update(ELAPSED)
globe.Updater.entityCollide()
globe.Updater.roomCollide()
globe.Updater.draw()
#handles quit events (clicking x in window)
for event in events:
if(event.type == pygame.QUIT):
print('quit attempt')
pygame.quit()
sys.exit()
break
#debug stuff
if(pygame.key.get_pressed()[pygame.K_o]):
print(Player.pos)
if(pygame.key.get_pressed()[pygame.K_p]):
input()
if(pygame.key.get_pressed()[pygame.K_ESCAPE]):
pygame.quit()
sys.exit()
if(pygame.key.get_pressed()[pygame.K_i]):
if(not(iDown)):
if(globe.State.hasState('paused')):
globe.State.removeState('paused')
else:
globe.State.addState('paused')
iDown = True
else:
iDown = False
if(pygame.key.get_pressed()[pygame.K_l]):
if(not(lDown)):
if(fullScreen):
pygame.display.set_mode((WINDOWWIDTH,WINDOWHEIGHT))
else:
fullScreen = True
flags = pygame.FULLSCREEN
pygame.display.set_mode((WINDOWWIDTH,WINDOWHEIGHT), flags, 32)
lDown = True
else:
lDown = False
fps_meter.updateByMilli(ELAPSED)
pygame.display.set_caption(WINDOW_CAPTION + fps_meter.getFPS())
if(updateToggle):
updateToggle = False
updateRect = pygame.Rect(0,0,int(WINDOWWIDTH/2),int(WINDOWHEIGHT/2))
else:
updateToggle = True
updateRect = pygame.Rect(int(WINDOWWIDTH/2),int(WINDOWHEIGHT/2),int(WINDOWWIDTH/2),int(WINDOWHEIGHT/2))
pygame.display.update(updateRect)
ELAPSED = FPS_CLOCK.tick(FPS_CAP)