-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_cycle.pyw
209 lines (177 loc) · 5.8 KB
/
game_cycle.pyw
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
import pygame, sys, random
from pygame.locals import *
from graphical_elements import *
import game_variables as data
import game_engine
clock = pygame.time.Clock()
RUNNING = True
scroll_y = 0
txtl = {
air : 'Air',
battery : 'Battery',
brick : 'Brick',
heat: 'Heater',
lava : 'Lava',
sand : 'Sand',
steam : 'Steam',
water : 'Water',
wire : 'Wire',
heatingHeat : 'Powered Heater',
poweredWire : 'Powered Wire',
condenser : 'Condenser',
poweredCondenser : 'Powered Condenser',
border : 'Border',
switch : 'Switch',
waterDetector: 'Water Detector',
steamDetector: 'Steam Detector',
inverter: "Inverter",
jumper: "Jumper",
pjumper: "Powered Jumper",
ljumper: "Long Jumper",
pljumper: "Powered Long Jumper",
lightoff: "Light",
lighton: "Light On",
}
seq ={
0: 0,
1: 1,
2: 8,
3: 14,
4: 17,
5: 18,
6: 20,
7: 22,
8: 11,
9: 3,
10: 2,
11: 10,
12: 4,
13: 7,
14: 5,
15: 6,
16: 16,
17: 15,
18: 9,
19: 19,
20: 12,
21: 21,
22: 13,
23: 23
}
def Exit():
global RUNNING
RUNNING = False
class Option:
hovered = False
def __init__(self, text, pos):
self.text = text
self.pos = pos
self.set_rect()
self.draw()
def draw(self):
self.set_rend()
DISPLAY.blit(self.rend, self.rect)
def set_rend(self):
self.rend = txtFont.render(self.text, True, self.get_color())
def get_color(self):
if self.hovered:
return (0, 255, 0)
else:
return (0, 0, 255)
def set_rect(self):
self.set_rend()
self.rect = self.rend.get_rect()
self.rect.topleft = self.pos
def work(self):
global scroll_y
if self.text =="Clear":
game_engine.clearMap()
elif self.text =="Load":
game_engine.loadMap(seq[scroll_y])
elif self.text == "Save":
game_engine.saveMap(seq[scroll_y])
elif self.text =="Exit":
Exit()
options = [Option("Clear", (20, Y*Square+40)), Option("Load", (320, Y*Square+40)),
Option("Save", (520, Y*Square+40)), Option("Exit", (720, Y*Square+40))]
def gameStart():
global RUNNING
paused = True
clickdown = False
global scroll_y
blokelis = 0
FPS = 20
pygame.init()
iserasing = False
i = -1
while RUNNING:
i = -1
for event in pygame.event.get():
if event.type == QUIT:
RUNNING = False
event.type
elif event.type == pygame.KEYDOWN:
clickdown = False
if event.key == pygame.K_SPACE:
paused = not paused
elif event.key == pygame.K_1:
FPS = 1
elif event.key == pygame.K_2:
FPS = 3
elif event.key == pygame.K_3:
FPS = 10
elif event.key == pygame.K_4:
FPS = 20
elif event.key == pygame.K_5:
FPS = 40
elif event.type == pygame.MOUSEBUTTONDOWN and event.button in [4,5,1]:
for optione in options:
if optione.rect.collidepoint(pygame.mouse.get_pos()):
optione.work()
if event.button == 4:
if scroll_y <23 :
scroll_y = max(scroll_y +1, 0)
elif event.button == 5:
if scroll_y >0 :
scroll_y = min(scroll_y -1, 23)
else : clickdown = True
elif event.type == pygame.MOUSEBUTTONUP and event.button ==1:
clickdown = False
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 3:
iserasing = True
clickdown = False
elif event.type == pygame.MOUSEBUTTONUP and event.button == 3:
iserasing = False
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 2:
tip = game_engine.returnblock([event.pos[0]//Square,event.pos[1]//Square])
for k, v in seq.items():
if tip == v or isinstance(v, list) and tip in v:
scroll_y = k
DISPLAY.fill((0,0,0))
if paused:
game_engine.updateMap()
if iserasing and event.pos[1]<Square*Y:
try:
game_engine.changeblock([event.pos[0]//Square,event.pos[1]//Square],0)
except Exception:
pass
if clickdown and event.pos[1]<Square*Y:
try:
game_engine.changeblock([event.pos[0]//Square,event.pos[1]//Square],seq[scroll_y])
except Exception:
pass
for x in range(X):
for y in range(Y):
i = i+1
DISPLAY.blit(pictures[game_engine.cmap[i]],(x*Square,y*Square))
invText = txtFont.render(str(txtl[seq[scroll_y]]),True,(200,200,200),(0,0,0))
DISPLAY.blit(invText,(X*Square-345,Y*Square))
DISPLAY.blit(pictures[seq[scroll_y]],(20,Y*Square+10))
for option in options:
if option.rect.collidepoint(pygame.mouse.get_pos()):
option.hovered = True
else:
option.hovered = False
option.draw()
pygame.display.update()
clock.tick(FPS)