-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun.py
More file actions
294 lines (271 loc) · 12.9 KB
/
Run.py
File metadata and controls
294 lines (271 loc) · 12.9 KB
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
import pygame
from findPathLee import findPath
import Tile
from Character import Character
from NPC import NPC
import Extra_functions
import Render_functions
import pickle
import Buttons
import Spell
class GameProcess():
def __init__(self, npc, character, phisic_wallmap):
self.turn = -1 # Очередь хода (-1 - это наш персонаж)
self.character = character # Ссылка на игрового персонажа
self.all_npc = npc # Ссылка на всех NPC
self.all_persons = [character] # Все персонажи
self.all_persons.extend(npc)
self.phisic_wallmap = phisic_wallmap
def update(self, dt):
if self.character.stepwise_mod:
if self.turn == -1:
self.character.update(dt, self.all_persons)
else:
try:
self.all_npc[self.turn].update(dt, self.character, map_f, map_w, self.phisic_wallmap, self.all_persons)
print(self.turn, " Закончил - ", self.all_npc[self.turn].finish, " Тревога - ", self.all_npc[self.turn].alarm, " ОД ", self.all_npc[self.turn].action_points, " Путь ", self.all_npc[self.turn].path)
if self.all_npc[self.turn].finish:
self.turn += 1
except:
if self.all_npc[self.turn-1].finish:
self.turn = -1
else:
self.character.update(dt, self.all_persons)
for npc in self.all_npc:
npc.update(dt, self.character, map_f, map_w, self.phisic_wallmap, self.all_persons)
if npc.alarm:
self.on_stepwise_mod()
def on_stepwise_mod(self):
"""
Включить пошаговый режим для всех
"""
self.turn = -1
self.character.stepwise_mod = True
try:
for npc in self.all_npc:
npc.stepwise_mod = True
except:
self.all_npc.stepwise_mod = True
def change_mod(self):
"""
Сменить режим с пошагового на нормальный или обратно
"""
for npc in self.all_npc:
if npc.alarm:
return
self.turn = -1
self.character.change_mod()
try:
for npc in self.all_npc:
npc.change_mod()
except:
self.all_npc.change_mod()
def new_step(self):
"""
Начать новый ход (он начинается с хода противников)
"""
self.turn = 0
self.character.action_points = 15
try:
for npc in self.all_npc:
npc.action_points = 15
npc.finish = False
except:
self.all_npc.action_points = 15
self.all_npc.finish = False
class Interface():
def __init__(self, char, npc, res, map_floor, map_wall):
self.character = char
self.npc_list = npc
self.all_persons = [character] # Все персонажи
self.all_persons.extend(npc)
self.map_f = map_floor
self.map_w = map_wall
self.map_pass = []
for line in self.map_f:
self.map_pass.append(line.copy())
for n in self.npc_list:
self.map_pass[n.cor[1]][n.cor[0]] = 0
self.z_ind = False
self.resolution = res
self.path = None
self.pathmarker = Render_functions.load_image('Pathmarker.png', alpha_cannel="True") # Картинка выбраного пути
self.ap = Render_functions.load_image('ActP_active.png', alpha_cannel="True")
self.wasted_ap = Render_functions.load_image('ActP_wasted.png', alpha_cannel="True")
self.buttons = []
self.stepwise_buttons = []
x = RES_X-170
y = 100
if type(self.character.spells) == tuple:
for spell in self.character.spells:
self.stepwise_buttons.append(Buttons.Button_Flag(Render_functions.load_text(spell.name), self.character.set_wearpon, (x, y), arg=(spell, None)))
y += 15
else:
self.stepwise_buttons.append(Buttons.Button_Flag(Render_functions.load_text(self.character.spells.name), character.set_wearpon, (x, y), arg=(self.character.spells, None)))
def events(self, e):
if self.buttons:
for but in self.buttons:
if but.events(e):
self.z_ind = True
else:
self.z_ind = False
if self.character.stepwise_mod:
for but in self.stepwise_buttons:
if but.events(e):
self.z_ind = True
self.buttons_up(but, self.stepwise_buttons)
elif self.z_ind != True:
self.z_ind = False
if e.type == pygame.MOUSEMOTION:
self.path = findPath(self.map_pass, self.map_w, self.character.cor, (Extra_functions.get_click_tile(e.pos, render_coof, self.map_pass)))
if self.path == -1:
self.path = None
if e.type == pygame.MOUSEBUTTONUP:
if e.button == 1 and not self.z_ind:
chosen_tile = Extra_functions.get_click_tile(e.pos, render_coof, self.map_f)
t = True
for per in self.all_persons:
if chosen_tile == per.cor:
self.character.set_target(per)
t = False
break
if t:
self.character.set_path(findPath(self.map_pass, self.map_w, self.character.cor, chosen_tile))
def buttons_up(self, but, lst):
"""
Получает кнопку, на которую нажали и список с кнопками "отжимает" остальные кнопки
"""
for button in lst:
if button != but and type(but) == Buttons.Button_Flag:
button.stat = False
def render(self, screen, coof):
screen.blit(Render_functions.load_text("Здоровье "+str(self.character.healf)+"|"+str(self.character.max_healf)), (RES_X-110, 5))
screen.blit(Render_functions.load_text("Манна "+str(self.character.manna)+"|"+str(self.character.max_manna)), (RES_X-110, 25))
screen.blit(Render_functions.load_text("Броня "+str(self.character.armor)), (RES_X-110, 45))
if self.buttons:
for but in self.buttons:
but.render(screen)
x = self.resolution[0] - 330
y = self.resolution[1] - 25
for i in range(15):
if i < self.character.action_points:
screen.blit(self.ap, (x, y))
else:
screen.blit(self.wasted_ap, (x, y))
x += 22
x = self.resolution[0] - 375
y = self.resolution[1] - 45
w = self.character.gear["Wearpon"]
if w:
if type(w) == Spell.Spell:
if w.type == "Attacking":
screen.blit(Render_functions.load_image('Fireball.png', alpha_cannel="True"), (x, y))
else:
screen.blit(Render_functions.load_image('Fist.png', alpha_cannel="True"), (x, y))
if self.character.stepwise_mod:
if self.stepwise_buttons:
for but in self.stepwise_buttons:
but.render(screen)
if self.path:
for tile in self.path:
screen.blit(self.pathmarker, (coof[0]+tile[0]*100, coof[1]+tile[1]*100))
for npc in self.npc_list:
if npc.aggression:
cor = npc.get_coords_on_map()
screen.blit(Render_functions.load_text(str(npc.healf), color=(200, 0, 0)), (cor[0]+5, cor[1]+5))
screen.blit(Render_functions.load_text(str(npc.manna), color=(0, 0, 150)), (cor[0]+5, cor[1]+19))
screen.blit(Render_functions.load_text(str(npc.manna), color=(100, 100, 100)), (cor[0]+5, cor[1]+33))
if self.character.dead:
screen.blit(Render_functions.load_text("Вы мертвы", pt=200, color=(220, 0, 0)), (80, RES_Y/2-100))
def set_scene(scene_value):
"""
Уникальная нанофункция, сменяющая сцену. Благодаря моим глубочайшим познаниям в архитектуре языка выглядит так уродливо
"""
scene_value[0][0] = scene_value[1]
def get_phisic_wallmap(map_wall):
phisic_wallmap = []
y = 0
for line in map_w:
x = 0
for tile in line:
z = 0
for dir in tile:
if dir == 1:
if z == 0:
phisic_wallmap.append(((x, y+1), (x+1, y+1)))
elif z == 1:
phisic_wallmap.append(((x, y), (x, y+1)))
elif z == 2:
phisic_wallmap.append(((x, y), (x+1, y)))
elif z == 3:
phisic_wallmap.append(((x+1, y), (x+1, y+1)))
z += 1
x += 1
y += 1
return phisic_wallmap
# Globals
FPS = 60 # ФПС программы
RES_X = 900 # Разрешение по длине
RES_Y = 700 # Разрешение по ширине
TILE_SIZE = 100 # Размер тайла (НЕ РАБОТАЕТ!!!!!)
# Main Actions
file = open('d', 'rb') # Открыть файл с картами
maps = pickle.load(file) # Загрузить карты
map_f, map_w, map_d = maps # Загрузить карты в собственные переменные
file.close() # Закрыть файл с картами
phisic_wallmap = get_phisic_wallmap(map_w)
pygame.init() # PyGame начинает работу
screen = pygame.display.set_mode((RES_X, RES_Y)) # Создаем окно программы
clock = pygame.time.Clock() # Создаем таймер
menu = ["game"] # Меню, которое в данный момент на экране
mainloop = True # Двигатель главного цикла
world_img = pygame.Surface((RES_X, RES_Y)) # Поверхность, на которой отображается весь игровой мир
render_coof = [0, 0]
ch = False
npc_list = [NPC("Test_Enemy", (1, 4), gear=(None, None)), NPC("Test_Enemy_2", (4, 2), gear=(None, None))]
npc_list[0].attack_distance = 2
character = Character("Test Character", (3, 0), skills=(1, 3, 1), spelllist=(Spell.fireball, Spell.improve_aah))
game_process = GameProcess(npc_list, character, phisic_wallmap)
interface = Interface(character, npc_list, (RES_X, RES_Y), map_f, map_w)
interface.buttons.append(Buttons.Button("Пошагово/Реальное время", (0, RES_Y-20), game_process.change_mod))
interface.stepwise_buttons.append(Buttons.Button("Конец хода", (300, RES_Y-20), game_process.new_step))
objects = { # Все доступные объекты
"Floor": {
1: Tile.Floor((0, 0), "B_Tile.png", 1),
2: Tile.Floor((0, 0), "Tile-2.png", 2)
},
"Wall": {
1: Tile.Wall((0, 0), "Wall_1.png", 1)
}
}
while mainloop:
screen.fill((0, 0, 0))
world_img.fill((0, 0, 0))
if menu[0] == "game":
for e in pygame.event.get():
if e.type == pygame.MOUSEMOTION or e.type == pygame.MOUSEBUTTONDOWN or e.type == pygame.MOUSEBUTTONUP:
interface.events(e)
if e.type == pygame.QUIT:
mainloop = False
if e.type == pygame.MOUSEBUTTONDOWN:
if e.button == 1:
pass
if e.button == 2:
ch = True
if e.type == pygame.MOUSEBUTTONUP:
if e.button == 2:
ch = False
if e.type == pygame.MOUSEMOTION:
if ch:
render_coof[0] += e.rel[0]
render_coof[1] += e.rel[1]
game_process.update(clock.get_time())
world_img = Render_functions.scene_render(map_f, map_w, objects, world_img, TILE_SIZE)
for npc in npc_list:
npc.render(world_img)
character.render(world_img)
screen.blit(world_img, render_coof)
interface.render(screen, render_coof)
pygame.display.set_caption("FPS: " + str(clock.get_fps()))
clock.tick(FPS) # Управление ФПС
pygame.display.flip() # Обновляем дисплей