level.py 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. import json
  2. import math
  3. from json import JSONDecodeError
  4. import numpy as np
  5. import pygame
  6. import os
  7. import ast
  8. import time
  9. from collections import defaultdict
  10. from client_local.const import game as G
  11. from client_local.frame import floor
  12. from client_local.frame import obstacle
  13. from client_local.music import music_loader
  14. from client_local.sound import sound_player
  15. from client_local.sprite import obstacle_instance as oi
  16. from client_local.sprite.flame_instance import FlameState as FS
  17. from client_local.sprite.hero import Hero
  18. from client_local.sprite.pet import Pet
  19. from client_local.sprite.item_instance import ItemState as IS
  20. from client_local.sprite.bomb_instance import BombInstance
  21. from client_local.effect.effect_instance import ReadyGo, DistrictAlarm, EnvironmentEffect, EffectState
  22. from client_local.sprite.npc import Npc
  23. from client_local.ui.game.blood_bar import BloodBar
  24. from client_local.ui.game.dlg_pveFunc import DlgPveFunc
  25. from client_local.ui.game.game_top import GameTop
  26. from client_local.ui.game.misc_510 import Misc510
  27. from client_local.ui.game.player_icon import PlayerIcon
  28. from client_local.ui.game.score_board import ScoreBoard, Timer
  29. from client_local.ui.game.status_bar import StatusBar
  30. from client_local.ui.game.message_input import InputEntry, InputLevel
  31. from client_local.file_loader.fileLoader import load_json, load_png
  32. from client_local.skill.skill import WinEffect
  33. from client_local.skill.level_skill import Level3x3RandomThunder, DebuffPoisonGrid
  34. from datetime import datetime
  35. current_level = None
  36. level_font = pygame.font.Font("res/font/simsun.ttc", 16)
  37. Y_SCALE_FACTOR = 1 # 用于地震效果,画面会按比例以中间为基准进行上下偏移实现压缩效果
  38. max_alpha = 255 # 最大透明度
  39. circleMasks = {}
  40. MASK_STEP = 20
  41. lightBoltMasks = {}
  42. for i in range(1, 10):
  43. # 在蒙版上画出三个指定坐标及其周围100像素范围的圆形(透明度衰减)
  44. circle_radius = i*MASK_STEP
  45. circleMask = pygame.Surface((circle_radius*2, circle_radius*2), pygame.SRCALPHA)
  46. circleMask.fill((0, 0, 0, 0))
  47. for r in range(circle_radius):
  48. R = circle_radius-r
  49. alpha = max_alpha - int((max_alpha / circle_radius) * R)
  50. pygame.draw.circle(circleMask, (alpha, alpha, alpha, alpha), (circle_radius, circle_radius), R)
  51. circleMasks[i] = circleMask
  52. def get_player_coordinates():
  53. players = current_level.game.players
  54. coords = []
  55. for player in players:
  56. coords.append((player.x_pos,player.y_pos))
  57. return coords
  58. def get_light_npc_coordinates():
  59. coords = []
  60. for npc in current_level.npcs:
  61. coords.append((npc.x_pos, npc.y_pos))
  62. return coords
  63. _last_light_states = None
  64. # def get_player_mask(mask_surface, bgl):
  65. # """
  66. # 只在光源状态变化时才重绘遮罩;否则直接返回上次绘制结果。
  67. # """
  68. # global _last_light_states
  69. # # 收集当前所有光源状态 (x, y, light)
  70. # curr = []
  71. # for p in [current_level.me] + current_level.npcs + list(current_level.obstacle_instances.values()):
  72. # if p.light:
  73. # curr.append((p.x_pos, p.y_pos, p.light))
  74. # curr_key = tuple(curr)
  75. # # 如果没变化,直接复用
  76. # if curr_key == _last_light_states:
  77. # return mask_surface
  78. # # 状态变化:重绘
  79. # _last_light_states = curr_key
  80. # bgl = max(0, min(bgl, 255))
  81. # fill = mask_surface.fill
  82. # blit = mask_surface.blit
  83. # masks = circleMasks
  84. # fill((bgl, bgl, bgl, 0))
  85. # for x, y, light in curr:
  86. # # 叠加亮度
  87. # cm = masks[light]
  88. # r = light * MASK_STEP
  89. # blit(cm, (x - r, y - r - 15),
  90. # special_flags=pygame.BLEND_RGBA_ADD)
  91. # return mask_surface
  92. def get_player_mask(mask_surface, bgl):
  93. global _last_light_states
  94. # 收集当前所有光源状态 (x, y, light)
  95. curr = []
  96. for p in [current_level.me]:
  97. if p.light and (not p.is_hide_sight()):
  98. curr.append((p.x_pos, p.y_pos, p.light))
  99. for p in current_level.npcs:
  100. if p.light and (not p.is_hide_sight()):
  101. curr.append((p.x_pos, p.y_pos, p.light))
  102. for p in current_level.obstacle_instances.values():
  103. if p.light:
  104. curr.append((p.x_pos, p.y_pos, p.light))
  105. curr_key = tuple(curr)
  106. if curr_key == _last_light_states:
  107. return mask_surface
  108. _last_light_states = curr_key
  109. bgl = max(0, min(bgl, 255))
  110. fill = mask_surface.fill
  111. blit = mask_surface.blit
  112. masks = circleMasks
  113. # 先把整表清空为 bgl 灰底
  114. fill((bgl, bgl, bgl, 0))
  115. # ---- 新增:计算屏幕视口,并在后面用 inflate 方式做相交测试 ----
  116. from client_local.const import game as G
  117. # world-space 下的视口矩形
  118. view_rect = pygame.Rect(
  119. current_level.scroll_x_pos,
  120. current_level.scroll_y_pos,
  121. G.MAIN_AREA_X_POS,
  122. G.MAIN_AREA_Y_POS
  123. )
  124. # ---------------------------------------------------------
  125. view_x, view_y = current_level.scroll_x_pos, current_level.scroll_y_pos
  126. for x, y, light in curr:
  127. r = light * MASK_STEP
  128. sx = x - view_x - r # ← 世界 → 屏幕
  129. sy = y - view_y - r - 15
  130. cm = masks[light]
  131. # 膨胀法:把视口向外各扩 r(水平方向)和 (r+15)(垂直方向)
  132. if not view_rect.inflate(2*r, 2*(r+15)).collidepoint(x, y):
  133. continue
  134. # 叠加亮度
  135. mask_surface.blit(cm, (sx, sy), special_flags=pygame.BLEND_RGBA_ADD)
  136. return mask_surface
  137. def special_colour_mask(mask_surface, rgb):
  138. r = min(max(rgb[0], 0), 255)
  139. g = min(max(rgb[1], 0), 255)
  140. b = min(max(rgb[2], 0), 255)
  141. mask_surface.fill((r, g, b, 0)) # 初始
  142. for player in [current_level.me] + current_level.npcs + list(current_level.obstacle_instances.values()):
  143. x, y = player.x_pos, player.y_pos
  144. if player.light == 0:
  145. continue
  146. circleMask = circleMasks[player.light]
  147. circle_radius = player.light*MASK_STEP
  148. # 叠加亮度
  149. mask_surface.blit(circleMask, (x-circle_radius, y-circle_radius-15),special_flags=pygame.BLEND_RGBA_ADD) # 15是补偿值(大概是角色中心)
  150. return mask_surface
  151. def get_y(elem):
  152. return elem.get_y()
  153. def caesar_encrypt(text, k=3):
  154. encrypted_text = ""
  155. for char in text:
  156. if char.isalpha():
  157. # 处理字母
  158. if char.isupper():
  159. encrypted_char = chr((ord(char) - ord('A') + k) % 26 + ord('A'))
  160. else:
  161. encrypted_char = chr((ord(char) - ord('a') + k) % 26 + ord('a'))
  162. elif char.isdigit():
  163. # 处理数字
  164. encrypted_char = str((int(char) + k) % 10)
  165. else:
  166. # 其他字符保持不变
  167. encrypted_char = char
  168. encrypted_text += encrypted_char
  169. return encrypted_text
  170. class MainArea(pygame.Surface):
  171. def __init__(self, size, flags=0):
  172. super().__init__(size, flags)
  173. def blit(self, source, dest, area=None, special_flags=0):
  174. relative_y = dest[1] - current_level.scroll_y_pos - G.MAIN_AREA_Y_POS//2
  175. scale_bias_value = relative_y * (1 - Y_SCALE_FACTOR)
  176. dest = (dest[0], int(dest[1] - scale_bias_value))
  177. super().blit(source, dest, area, special_flags)
  178. class Level:
  179. def __init__(self, your_name: str, map_name: str, me: Hero, music_volume, accumulation_time, game=None):
  180. from client_local.control import Control
  181. self.game: Control = game
  182. global current_level
  183. current_level = self
  184. self.times_num = 0 # 秒计数器,每秒累加
  185. self.frames_num = 0 # 帧计数器,每秒清空
  186. self.frame_rate_text_font = level_font
  187. self.me = me
  188. self.pets = []
  189. self.your_name = your_name
  190. self.map_name = map_name
  191. self.map_json = None
  192. self.map_x = None # 关卡横向格子数
  193. self.map_y = None # 关卡纵向格子数
  194. self.map_x_pos = None # 关卡最大x坐标
  195. self.map_y_pos = None # 关卡最大y坐标
  196. self.map_grids = None # 关卡全部的点坐标集合
  197. self.scroll_x_pos = None # 卷轴滚动x像素
  198. self.scroll_y_pos = None # 卷轴滚动y像素
  199. self.scroll_x_pos_max = None # 卷轴最大滚动x像素
  200. self.scroll_y_pos_max = None # 卷轴最大滚动y像素
  201. self.map_title = None # 关卡中文名称
  202. self.map_time = 0 # 关卡总时长
  203. self.level_time = 0
  204. self.map_init_time = None # 关卡加载时刻
  205. self.map_remaining_time = None # 关卡剩余时间
  206. self.map_music = None # 关卡背景音乐
  207. self.map_ambience = None # 背景音效
  208. self.map_music_volume = music_volume # 关卡背景音乐音量大小
  209. self.finish_at = None # 地图过关点(x, y)
  210. self.earth_quake_init_tick = 0 # 地震初始化tick
  211. self.earth_quake_left_times = 0 # 地震剩余次数
  212. self.earth_quake_strength = 0 # 地震强度
  213. self.earth_quake_times = 0 # 地震次数
  214. self.earth_quake_decrease = True # 地震强度是否递减
  215. self.current_time = pygame.time.get_ticks()
  216. self.floor_image = None # 游戏主区域的地板背景
  217. self.flame_instances = None # FlameInstance对象列表
  218. self.item_instances = None # (x, y) --> ItemInstance对象
  219. self.obstacle_instances = None # (x, y) --> ObstacleInstance对象
  220. self.obstacle_instances_update = None # 屏幕范围内的ObstacleInstance对象列表
  221. self.obstacle_instances_need_to_update = True # 需要更新列表
  222. self.bomb_instances = None # BombInstance对象列表
  223. self.ui_instances_bot = None # 位于main_area下的UIInstance对象列表
  224. self.ui_instances_top = None # 位于main_area上的UIInstance对象列![](C:/Users/dell/AppData/Local/Temp/previewfile_2896918733.gif)表
  225. self.block = None # 三维NumPy对象,阻挡玩家
  226. self.block_flame = None # 三维NumPy对象,阻挡糖跑
  227. self.slide_orientation = dict() # (x, y) --> (m, n) m网格传送带方向 0无 1右 2上 3左 4下 n速度
  228. self.grid_damage_blood = dict() # 网格伤害血量
  229. self.grid_damage_time = defaultdict(None) # 网格伤害时刻 只有糖泡爆炸时才会增加
  230. self.grid_damage_multiples = dict() # 伤害次数(倍数)
  231. # self.grid_damage_orientations = dict() # 网格伤害方向
  232. self.grid_damage_orientations = defaultdict(set)
  233. self.path_map = dict() # 缓存怪物追踪路径
  234. self.grid_damage_frame = False # 用于判断糖泡伤害瞬间与玩家位置是否重合 只有爆炸帧才是True
  235. self.accumulation_time = accumulation_time # 网格伤害延迟时间
  236. self.main_area = None # 游戏主区域
  237. self.main_area_offset = None # 游戏主区域相对左上角的偏移
  238. self.skill_instances = list() # 交予level托管的skill_instances,例如陷阱,不随npc死亡而消失
  239. self.effects_behind = list() # 关卡底层技能特效
  240. self.effects_front = list() # 关卡顶层技能特效
  241. self.effects_screen = list() # 屏幕级的技能特效 不随卷轴移动
  242. self.left_black = None # 屏幕右侧黑条
  243. self.grid_bomb_time_at = dict() # 糖泡伤害时刻
  244. self.level_variables = dict()
  245. self.blood_bar = None
  246. self.status_bar = None
  247. self.score_board = None
  248. self.time_board = None
  249. self.npcs = list() # 存活npc列表
  250. self.ghosts = list() # 存活僵尸列表
  251. self.recal_npc_paths = True # 重新计算Npc路径的标志位 仅当玩家进入区域、糖泡施放与爆炸、玩家网格位置发生变化、障碍被摧毁时置为True
  252. self.recal_ghost_paths = True # 重新计算Ghost路径的标志位 仅当玩家移动
  253. self.display_name_card = False # 显示npc姓名牌
  254. self.display_npc_blood = False # 显示npc姓名牌
  255. self.district_idx = 0 # 当前区域 从1开始
  256. self.district_square = None # 当前区域 左上右下点像素坐标
  257. self.district_square_grid = None # 当前区域 左上右下点坐标
  258. self.district_alarming = False # 当前正在显示警戒
  259. self.district_all_finished = False # 已完成全部区域的标志
  260. self.finish_flag = False # 当前map结束的标志位
  261. self.district_json = None
  262. self.read_district_json = False
  263. self.custom_finish_flag = False
  264. self.custom_next_map = None
  265. self.portal = dict()
  266. self.portal_set = []
  267. self.has_achievemeny_check = False
  268. self.special_music_volume = 1 # 若需放大音乐
  269. self.load_map_json() # 加载地图
  270. self.load_ui() # 加载ui界面
  271. self.load_floor() # 加载地板
  272. self.load_obstacle() # 加载障碍
  273. self.load_music() # 加载音乐
  274. self.mask_surface = pygame.Surface((self.map_x_pos, self.map_y_pos), pygame.SRCALPHA).convert_alpha()
  275. self.haunt_Mode = False
  276. self.bg_light = 0
  277. self.underwater = False
  278. self.rgb_light = [0, 0, 0]
  279. self.special_rgb = False
  280. self.boss_blood_bar_dic = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0} # boss血条显示
  281. self.dark_trap = set() # debuff毒陷阱集合
  282. self.small_dark_trap = set() # debuff毒陷阱集合
  283. self.poison_dic = dict() # 改良版毒陷阱字典
  284. ReadyGo(self.effects_screen)
  285. self.map_json = load_json("game/map/" + self.map_name + ".json")
  286. if "environment_effect" in self.map_json["basic"].keys():
  287. G.ENVIRONMENT_EFFECT = self.map_json["basic"]["environment_effect"]
  288. else:
  289. G.ENVIRONMENT_EFFECT = []
  290. if len(G.ENVIRONMENT_EFFECT) > 0:
  291. for en in G.ENVIRONMENT_EFFECT:
  292. EnvironmentEffect(self.effects_screen, en)
  293. if "haunted" in self.map_json["basic"].keys():
  294. self.haunt_Mode = self.map_json["basic"]['haunted']
  295. if "bg_light" in self.map_json["basic"].keys():
  296. self.bg_light = self.map_json["basic"]["bg_light"]
  297. if "underwater" in self.map_json["basic"].keys():
  298. self.underwater = self.map_json["basic"]["underwater"]
  299. G.UNDERWATER = self.underwater
  300. else:
  301. G.UNDERWATER = False
  302. if "water_damping" in self.map_json["basic"].keys():
  303. G.WATER_DAMPING = self.map_json["basic"]["water_damping"]
  304. else:
  305. G.WATER_DAMPING = 200
  306. if "rgb_light" in self.map_json["basic"].keys():
  307. self.rgb_light = self.map_json["basic"]["rgb_light"]
  308. self.special_rgb = True
  309. if G.PET is not None:
  310. self.pets.append(Pet(G.PET, (self.me.x, self.me.y), owner=self.me, num=1))
  311. if "level_skill" in self.map_json["basic"].keys():
  312. for skills in self.map_json["basic"]["level_skill"]:
  313. skill_name, skill_params, skill_init, skill_interval = skills[0], skills[1], skills[2], skills[3]
  314. if skill_name == "Level3x3RandomThunder":
  315. Level3x3RandomThunder(self.me, self.npcs, skill_params+[skill_init, skill_interval], self.skill_instances)
  316. # 紫色毒陷阱判断
  317. DebuffPoisonGrid(self.me, self.npcs, self.skill_instances)
  318. def set_level_variables(self, name, value):
  319. self.level_variables[name] = value
  320. def get_level_variables(self, name, default_value):
  321. return self.level_variables.get(name, default_value)
  322. def load_map_json(self):
  323. # 加载关卡json文件
  324. map_json = load_json("game/map/" + self.map_name + ".json")
  325. self.map_json = map_json
  326. if not self.read_district_json:
  327. self.read_district_json = True
  328. self.district_json = self.map_json["districts"]
  329. self.me.set_xy(map_json["basic"]["begin"][0], map_json["basic"]["begin"][1])
  330. if len(self.pets) > 0:
  331. for pet in self.pets:
  332. pet.set_xy(map_json["basic"]["begin"][0], map_json["basic"]["begin"][1])
  333. # 地图大小-像素
  334. self.map_x = int(map_json["basic"]["width"])
  335. self.map_y = int(map_json["basic"]["height"])
  336. G.CURRENT_MAP_HEIGHT = int(map_json["basic"]["height"])
  337. G.CURRENT_MAP_WIDTH = int(map_json["basic"]["width"])
  338. self.map_x_pos = self.map_x * G.GAME_SQUARE - 1
  339. self.map_y_pos = self.map_y * G.GAME_SQUARE - 1
  340. self.map_grids = set()
  341. for x in range(self.map_x):
  342. for y in range(self.map_y):
  343. self.map_grids.add((x, y))
  344. self.scroll_x_pos = map_json["basic"]["scroll"][0] * G.GAME_SQUARE
  345. self.scroll_y_pos = map_json["basic"]["scroll"][1] * G.GAME_SQUARE
  346. self.scroll_x_pos_max = max(0, self.map_x_pos - G.MAIN_AREA_X * G.GAME_SQUARE)
  347. self.scroll_y_pos_max = max(0, self.map_y_pos - G.MAIN_AREA_Y * G.GAME_SQUARE)
  348. self.map_init_time = pygame.time.get_ticks()
  349. self.map_music = map_json["basic"]["music"]
  350. self.flame_instances = list()
  351. self.item_instances = dict()
  352. self.obstacle_instances = dict()
  353. self.obstacle_instances_update = list()
  354. self.bomb_instances = list()
  355. self.ui_instances_bot = list()
  356. self.ui_instances_top = list()
  357. self.block = np.zeros((2, self.map_x + 1, self.map_y + 1), dtype=np.int64)
  358. self.block_flame = np.zeros((2, self.map_x + 1, self.map_y + 1), dtype=np.int64)
  359. # 生成网格伤害二元组映射
  360. for x in range(self.map_x):
  361. for y in range(self.map_y):
  362. self.grid_damage_blood[(x, y)] = 0
  363. self.grid_damage_time[(x, y)] = 0
  364. self.grid_damage_multiples[(x, y)] = 0
  365. # self.grid_damage_orientations[(x, y)] = set()
  366. self.grid_bomb_time_at[(x, y)] = 0
  367. self.district_square_grid = {"x1": 0, "x2": 0, "y1": 0, "y2": 0}
  368. self.district_square = {"x1": 0, "x2": 0, "y1": 0, "y2": 0}
  369. if "finish" in self.map_json["basic"].keys():
  370. self.finish_at = (self.map_json["basic"]["finish"][0], self.map_json["basic"]["finish"][1])
  371. self.main_area = MainArea((self.map_x_pos, self.map_y_pos)).convert()
  372. self.left_black = pygame.Surface((1, 600))
  373. if "haunted" in self.map_json["basic"].keys():
  374. self.haunt_Mode = self.map_json["basic"]['haunted']
  375. if "bg_light" in self.map_json["basic"].keys():
  376. self.bg_light = self.map_json["basic"]["bg_light"]
  377. if "underwater" in self.map_json["basic"].keys():
  378. self.underwater = self.map_json["basic"]["underwater"]
  379. G.UNDERWATER = self.underwater
  380. else:
  381. G.UNDERWATER = False
  382. if "water_damping" in self.map_json["basic"].keys():
  383. G.WATER_DAMPING = self.map_json["basic"]["water_damping"]
  384. else:
  385. G.WATER_DAMPING = 200
  386. if "rgb_light" in self.map_json["basic"].keys():
  387. self.rgb_light = self.map_json["basic"]["rgb_light"]
  388. self.special_rgb = True
  389. if "ambience" in self.map_json["basic"].keys():
  390. self.map_ambience = self.map_json["basic"]["ambience"]
  391. else:
  392. self.map_ambience = None
  393. if "music_volume" in self.map_json["basic"].keys():
  394. self.special_music_volume = self.map_json["basic"]["music_volume"]
  395. if "portal" in self.map_json["basic"].keys():
  396. self.portal = self.map_json["basic"]["portal"]
  397. for key in self.portal.keys():
  398. self.portal_set.append([ast.literal_eval(key), self.portal[key]["type"], self.portal[key]["target"]])
  399. else:
  400. self.portal = {}
  401. self.portal_set = []
  402. G.CURRENT_LEVEL += 1
  403. G.KILLED_NPC = 0
  404. G.MAP_NAME = self.map_name
  405. G.HAS_RECORD = False
  406. G.TOTAL_NPC = 0
  407. for dis in self.map_json["districts"]:
  408. G.TOTAL_NPC += len(dis["npcs"])
  409. if self.me.blood <= 4500 and self.me.standard_damage <= 3500+G.SPECIAL_DAMAGE and self.me.standard_defense <= G.SPECIAL_DEFENSE and self.me.standard_power <= 3+G.SPECIAL_POWER and self.me.standard_speed <= 0.234 and G.ITEM == 0:
  410. G.CHEAT = False
  411. else:
  412. G.CHEAT = True
  413. def load_ui(self):
  414. self.ui_instances_bot.append(GameTop())
  415. self.status_bar = StatusBar()
  416. self.status_bar.set_prop_imgs(self.me)
  417. if self.map_x < 16:
  418. self.score_board = ScoreBoard()
  419. self.score_board.set_time(300)
  420. self.ui_instances_bot.append(self.score_board)
  421. else:
  422. self.ui_instances_top.append(DlgPveFunc())
  423. if G.SHOW_TIME:
  424. self.time_board = Timer()
  425. self.time_board.set_time(300)
  426. self.ui_instances_top.append(self.time_board)
  427. self.ui_instances_top.append(self.status_bar)
  428. self.ui_instances_top.append(Misc510())
  429. self.ui_instances_top.append(PlayerIcon(self.me.icon_img))
  430. if not G.SHOW_INPUT:
  431. G.SHOW_INPUT = True
  432. self.message_entry = InputEntry() # 聊天输入框
  433. else:
  434. self.message_entry = InputLevel() # 聊天输入框
  435. self.ui_instances_top.append(self.message_entry)
  436. self.blood_bar = BloodBar(self.me)
  437. self.blood_bar.set_name(self.your_name)
  438. self.ui_instances_top.append(self.blood_bar)
  439. def earth_quake_effect(self, strength=0.1, times=3, duration_per_time=200, decrease=True):
  440. '''屏幕震动效果,强度表示移动像素数量,times表示震动次数,duration_per_time表示每次震动持续时间'''
  441. self.earth_quake_strength = strength
  442. self.earth_quake_times = times
  443. self.earth_quake_duration_per_time = duration_per_time
  444. self.earth_quake_time = pygame.time.get_ticks()
  445. self.earth_quake_decrease = decrease
  446. def run_earth_quake_effect(self, screen: pygame.Surface = None):
  447. '''运行屏幕震动效果'''
  448. global Y_SCALE_FACTOR
  449. if self.earth_quake_strength <= 0 or self.earth_quake_times <= 0:
  450. Y_SCALE_FACTOR = 1
  451. return
  452. now = pygame.time.get_ticks()
  453. if now - self.earth_quake_time >= self.earth_quake_duration_per_time:
  454. self.earth_quake_times -= 1
  455. self.earth_quake_time = now
  456. if self.earth_quake_decrease:
  457. self.earth_quake_strength = self.earth_quake_strength * 0.5
  458. if self.earth_quake_times <= 0:
  459. self.earth_quake_strength = 0
  460. return
  461. # 计算偏移量(抛物线计算当前高度)
  462. t = (now - self.earth_quake_time) / self.earth_quake_duration_per_time
  463. Y_SCALE_FACTOR = 1 - self.earth_quake_strength * t * (1 - t)
  464. MAX_BIAS = G.MAIN_AREA_Y_POS * (1-Y_SCALE_FACTOR)//2
  465. screen.fill((0, 0, 0, 0), rect=(0, 21, G.MAIN_AREA_X_POS, MAX_BIAS))
  466. def load_floor(self):
  467. # 加载地板floor
  468. self.floor_image = pygame.Surface((self.map_x_pos, self.map_y_pos), flags=pygame.HWSURFACE)
  469. # 块区域加载
  470. for f in self.map_json["floors"]:
  471. for square in f["squares"]:
  472. for x in range(square["x1"], square["x2"] + 1):
  473. for y in range(square["y1"], square["y2"] + 1):
  474. img = floor.get_floor(f["type"], f["name"])
  475. self.floor_image.blit(img, (x * G.GAME_SQUARE, y * G.GAME_SQUARE))
  476. # 单个加载
  477. for f in self.map_json["floor"]:
  478. img = floor.get_floor(f["type"], f["name"])
  479. for point in f["points"]:
  480. self.floor_image.blit(img, (point["x"] * G.GAME_SQUARE, point["y"] * G.GAME_SQUARE))
  481. def load_obstacle(self):
  482. # 加载障碍obstacle_instance
  483. # 块区域加载
  484. for o in self.map_json["obstacles"]:
  485. obs, obs_json = obstacle.get_obstacle(o["type"], o["name"])
  486. for square in o["squares"]:
  487. for x in range(square["x1"], square["x2"] + 1):
  488. for y in range(square["y1"], square["y2"] + 1):
  489. oi.ObstacleInstance(x, y, self.obstacle_instances, obs, obs_json)
  490. # 单个加载
  491. for o in self.map_json["obstacle"]:
  492. obs, obs_json = obstacle.get_obstacle(o["type"], o["name"])
  493. for point in o["points"]:
  494. oi.ObstacleInstance(point["x"], point["y"], self.obstacle_instances, obs, obs_json)
  495. def load_music(self):
  496. music_loader.play(self.map_music, self.map_music_volume * self.special_music_volume)
  497. if self.map_ambience is not None:
  498. music_loader.play_ambience(self.map_ambience, self.map_music_volume * self.special_music_volume)
  499. else:
  500. music_loader.stop_ambience()
  501. def check_achievement(self):
  502. if self.me.blood <= 4500 and self.me.standard_damage <= 3500+G.SPECIAL_DAMAGE and self.me.standard_power <= 3+G.SPECIAL_POWER and self.me.defense <= G.SPECIAL_DEFENSE and self.me.standard_speed <= 0.234*G.SPECIAL_SPEED and G.ITEM == 0:
  503. return True
  504. else:
  505. return False
  506. def check_full_achievement(self):
  507. if not G.HAS_GOLDEN and 4500 >= self.me.blood == self.me.remain_blood and self.me.standard_damage <= 3500+G.SPECIAL_DAMAGE and self.me.standard_power <= 3+G.SPECIAL_POWER and self.me.defense <= G.SPECIAL_DEFENSE and self.me.standard_speed <= 0.234*G.SPECIAL_SPEED and G.ITEM == 0:
  508. return True
  509. else:
  510. return False
  511. def record_achievement(self):
  512. pass
  513. def check_game_achievement(self):
  514. if self.check_full_achievement() and not G.HAS_RECORD_FULL:
  515. G.HAS_RECORD_FULL = True
  516. # 构建保存文件的路径
  517. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  518. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  519. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  520. full_achievements_file_path = os.path.join(qqtpve_folder, "full_achievements.json") # 构建full_achievements.json文件路径
  521. try:
  522. with open(full_achievements_file_path, encoding="utf-8") as file:
  523. encrypted_data = json.load(file)
  524. except:
  525. try:
  526. with open(full_achievements_file_path, encoding="utf-8_sig") as file:
  527. encrypted_data = json.load(file)
  528. except:
  529. # 如果文件不存在,创建新的空的achievements.json文件
  530. encrypted_data = {"STAT": []}
  531. with open(full_achievements_file_path, 'w', encoding="utf-8") as file:
  532. json.dump(encrypted_data, file, indent=2)
  533. if encrypted_data == {}:
  534. encrypted_data = {"STAT": []}
  535. # 新的数据
  536. new_data = {
  537. caesar_encrypt("name"): caesar_encrypt(G.MAP_SET_NAME),
  538. caesar_encrypt("last_map_name"): caesar_encrypt(G.MAP_NAME),
  539. caesar_encrypt("map_order"): int(caesar_encrypt(str(G.CURRENT_LEVEL))),
  540. caesar_encrypt("LV"): int(caesar_encrypt(str(self.me.blood))),
  541. caesar_encrypt("time"): caesar_encrypt(datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
  542. caesar_encrypt("game_time_min"): int(caesar_encrypt(str(self.map_time//60))),
  543. caesar_encrypt("game_time_sec"): int(caesar_encrypt(str(self.map_time%60)))
  544. }
  545. # 添加新的加密数据
  546. encrypted_data["STAT"].append(new_data)
  547. with open(full_achievements_file_path, 'w') as file:
  548. json.dump(encrypted_data, file, indent=2)
  549. if self.check_achievement() and G.CURRENT_LEVEL == G.TOTAL_LEVEL and not G.HAS_RECORD:
  550. G.HAS_RECORD = True
  551. sound_player.playWin("PlayerWin")
  552. WinEffect(self.me, self.me, "big", self.skill_instances)
  553. # 构建保存文件的路径
  554. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  555. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  556. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  557. achievements_file_path = os.path.join(qqtpve_folder, "achievements.json") # 构建achievements.json文件路径
  558. monster_stats_file_path = os.path.join(qqtpve_folder, "monster_stats.json") # 构建json文件路径
  559. try:
  560. with open(achievements_file_path, encoding="utf-8") as file:
  561. encrypted_data = json.load(file)
  562. except:
  563. try:
  564. with open(achievements_file_path, encoding="utf-8_sig") as file:
  565. encrypted_data = json.load(file)
  566. except:
  567. # 如果文件不存在,创建新的空的achievements.json文件
  568. encrypted_data = {"STAT": []}
  569. with open(achievements_file_path, 'w', encoding="utf-8") as file:
  570. json.dump(encrypted_data, file, indent=2)
  571. if encrypted_data == {}:
  572. encrypted_data = {"STAT": []}
  573. # 新的数据
  574. new_data = {caesar_encrypt("name"): caesar_encrypt(G.MAP_SET_NAME),
  575. caesar_encrypt("last_map_name"): caesar_encrypt(G.MAP_NAME),
  576. caesar_encrypt("LV"): int(caesar_encrypt(str(self.me.blood))),
  577. caesar_encrypt("time"): caesar_encrypt(datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
  578. caesar_encrypt("game_time_min"): int(caesar_encrypt(str(self.map_time//60))),
  579. caesar_encrypt("game_time_sec"): int(caesar_encrypt(str(self.map_time%60))),
  580. caesar_encrypt("remain_blood"): int(caesar_encrypt(str(self.me.remain_blood)))}
  581. try:
  582. # 添加新的加密数据
  583. encrypted_data["STAT"].append(new_data)
  584. with open(achievements_file_path, 'w') as file:
  585. json.dump(encrypted_data, file, indent=2)
  586. except:
  587. pass
  588. try:
  589. with open(monster_stats_file_path, encoding="utf-8") as file:
  590. self.encrypted_data_m = json.load(file)
  591. except:
  592. try:
  593. with open(monster_stats_file_path, encoding="utf-8_sig") as file:
  594. self.encrypted_data_m = json.load(file)
  595. except:
  596. # 如果文件不存在,创建新的空的json文件
  597. self.encrypted_data_m = {"STAT": []}
  598. with open(monster_stats_file_path, 'w', encoding="utf-8") as file:
  599. json.dump(self.encrypted_data_m, file, indent=2)
  600. if self.encrypted_data_m == {}:
  601. self.encrypted_data_m = {"STAT": []}
  602. try:
  603. for data in G.MONSTER_RECORD_LIST:
  604. self.encrypted_data_m["STAT"].append(data)
  605. with open(monster_stats_file_path, 'w') as file:
  606. json.dump(self.encrypted_data_m, file, indent=2)
  607. G.MONSTER_RECORD_LIST = []
  608. except:
  609. G.MONSTER_RECORD_LIST = []
  610. else:
  611. if G.CURRENT_LEVEL == G.TOTAL_LEVEL:
  612. WinEffect(self.me, self.me, "normal", self.skill_instances)
  613. def load_district_and_enemies(self):
  614. if len(self.npcs) > 0: # npc还没有被杀光
  615. return
  616. self.me.district_locked = False # 解除玩家区域锁
  617. if self.district_idx >= len(self.map_json["districts"]): # 已完成最后一个区域
  618. self.district_square = {"x1": 0, "x2": 0, "y1": 0, "y2": 0}
  619. self.district_square_grid = {"x1": 0, "x2": 0, "y1": 0, "y2": 0}
  620. self.district_all_finished = True
  621. if not self.has_achievemeny_check:
  622. self.has_achievemeny_check = True
  623. self.check_game_achievement()
  624. return
  625. self.district_idx += 1
  626. a_district = self.map_json["districts"][self.district_idx - 1]
  627. valid_poison_set = set()
  628. self.district_square = a_district["square"].copy()
  629. self.district_square_grid["x1"] = self.district_square["x1"]
  630. self.district_square_grid["x2"] = self.district_square["x2"]
  631. self.district_square_grid["y1"] = self.district_square["y1"]
  632. self.district_square_grid["y2"] = self.district_square["y2"]
  633. # 将district_square的四个点转化为像素坐标
  634. self.district_square["x1"] = self.district_square["x1"] * G.GAME_SQUARE + G.HALF_GAME_SQUARE
  635. self.district_square["x2"] = self.district_square["x2"] * G.GAME_SQUARE + G.HALF_GAME_SQUARE
  636. self.district_square["y1"] = self.district_square["y1"] * G.GAME_SQUARE + G.HALF_GAME_SQUARE
  637. self.district_square["y2"] = self.district_square["y2"] * G.GAME_SQUARE + G.HALF_GAME_SQUARE
  638. for g in self.ghosts:
  639. # 加载新区域时删除旧区域的幽灵,以及新加载出来的幽灵
  640. if g.time == 0:
  641. self.ghosts.remove(g)
  642. for n in a_district["npcs"]:
  643. # 载入新区域的npc
  644. patrol = n.get("patrol", None)
  645. if patrol is not None:
  646. self.npcs.append(Npc(n["name"], (n["x"], n["y"]), patrol_path=patrol))
  647. else:
  648. self.npcs.append(Npc(n["name"], (n["x"], n["y"])))
  649. for district in self.map_json["districts"][self.district_idx-1:]:
  650. x1, y1, x2, y2 = district["square"]["x1"], district["square"]["y1"], district["square"]["x2"], district["square"]["y2"]
  651. for point in self.poison_dic.keys():
  652. if x1 <= point[0] <= x2 and y1 <= point[1] <= y2:
  653. valid_poison_set.add(point)
  654. G.HAS_RECORD_FULL = False
  655. G.HAS_GOLDEN = False
  656. # 清除冗余紫陷阱
  657. old_keys = [ky for ky in self.poison_dic.keys()]
  658. for point in old_keys:
  659. if point not in valid_poison_set:
  660. self.poison_dic[point][4].state = EffectState.DEAD
  661. del self.poison_dic[point]
  662. def update(self, screen: pygame.Surface):
  663. # a = pygame.time.get_ticks()
  664. self.current_time = pygame.time.get_ticks()
  665. self.run_earth_quake_effect(screen) # 运行屏幕震动效果
  666. # 刷新帧率
  667. self.display_frame_rate(self.current_time, screen)
  668. # 刷新剩余时间
  669. if self.score_board is not None:
  670. map_remaining_time = math.ceil(
  671. (self.map_time * 1000) // 1000) + 1
  672. self.score_board.set_time(map_remaining_time)
  673. if self.time_board is not None:
  674. map_remaining_time = math.ceil(
  675. (self.level_time * 1000) // 1000)
  676. self.time_board.set_time(map_remaining_time)
  677. # 刷新区域
  678. if self.current_time - self.map_init_time > 3000:
  679. self.load_district_and_enemies()
  680. # 恢复帧爆炸位
  681. self.grid_damage_frame -= 1
  682. # 刷新糖泡
  683. for b in self.bomb_instances:
  684. b.update()
  685. # 刷新npc
  686. for n in self.npcs:
  687. if n.remain_blood <= 0:
  688. self.npcs.remove(n)
  689. else:
  690. n.update()
  691. self.recal_npc_paths = False
  692. # 刷新宠物
  693. if len(self.pets) > 0:
  694. for pet in self.pets:
  695. pet.update()
  696. # 刷新ghost
  697. for g in self.ghosts:
  698. if g.remain_time <= 0:
  699. self.ghosts.remove(g)
  700. else:
  701. g.update()
  702. self.recal_ghost_paths = False
  703. # 刷新人物
  704. self.me.update()
  705. # 检测过关
  706. self.pass_map()
  707. # 检测传送门
  708. self.portal_map()
  709. # 刷新糖浆
  710. for f in self.flame_instances:
  711. if f.state == FS.DEAD:
  712. self.flame_instances.remove(f)
  713. else:
  714. f.update()
  715. # 刷新item
  716. for key in list(self.item_instances.keys()):
  717. i = self.item_instances[key]
  718. if i.state == IS.DEAD:
  719. self.item_instances.pop(key)
  720. else:
  721. i.update()
  722. # 刷新障碍
  723. if self.obstacle_instances_need_to_update:
  724. self.update_obstacles_update_list()
  725. for o in self.obstacle_instances_update:
  726. o.update()
  727. # 刷新技能
  728. for s in self.skill_instances:
  729. s.update()
  730. # 刷新特效
  731. for e in self.effects_behind:
  732. e.update()
  733. for e in self.effects_front:
  734. e.update()
  735. for e in self.effects_screen:
  736. e.update()
  737. # 刷新ui
  738. for u in self.ui_instances_top:
  739. u.update()
  740. for u in self.ui_instances_bot:
  741. u.update()
  742. if Y_SCALE_FACTOR != 1:
  743. MAX_BIAS = G.MAIN_AREA_Y_POS * (1-Y_SCALE_FACTOR)//2
  744. # 上下MAX_BIAS区域填充(0,0,0,0)
  745. self.main_area.fill((255, 255, 255, 0), (self.scroll_x_pos, self.scroll_y_pos + 21, G.MAIN_AREA_X_POS, MAX_BIAS))
  746. # 显示地板
  747. self.main_area.blit(
  748. self.floor_image,
  749. (self.scroll_x_pos, self.scroll_y_pos),
  750. (self.scroll_x_pos, self.scroll_y_pos, G.MAIN_AREA_X_POS, G.MAIN_AREA_Y_POS)
  751. )
  752. # 显示底层特效
  753. for e in self.effects_behind:
  754. e.draw(self.main_area)
  755. # 显示人物和障碍
  756. if len(self.pets) > 0:
  757. draw_seq = self.pets + \
  758. [self.me] + \
  759. self.npcs + \
  760. self.ghosts + \
  761. self.bomb_instances + \
  762. self.obstacle_instances_update + \
  763. self.flame_instances + \
  764. list(self.item_instances.values())
  765. else:
  766. draw_seq = [self.me] + \
  767. self.npcs + \
  768. self.ghosts + \
  769. self.bomb_instances + \
  770. self.obstacle_instances_update + \
  771. self.flame_instances + \
  772. list(self.item_instances.values())
  773. draw_seq.sort(key=get_y)
  774. for d in draw_seq:
  775. d.draw(self.main_area)
  776. if self.special_rgb:
  777. self.mask_surface = special_colour_mask(self.mask_surface, self.rgb_light)
  778. self.main_area.blit(self.mask_surface, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
  779. if self.haunt_Mode:
  780. # 只在 get_player_mask 检测到状态变化时才重绘 mask_surface
  781. get_player_mask(self.mask_surface, self.bg_light)
  782. view_rect = pygame.Rect(
  783. self.scroll_x_pos,
  784. self.scroll_y_pos,
  785. G.MAIN_AREA_X_POS,
  786. G.MAIN_AREA_Y_POS
  787. ).clip(self.main_area.get_rect())
  788. # 取 main_area 的子 Surface(不拷贝像素,O(1))
  789. sub_main = self.main_area.subsurface(view_rect)
  790. # 将 mask_surface 乘进子 Surface,而不是整张 main_area
  791. sub_main.blit(self.mask_surface, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
  792. # 显示顶层特效
  793. for e in self.effects_front:
  794. e.draw(self.main_area)
  795. # 显示下ui
  796. for u in self.ui_instances_bot:
  797. u.draw(screen)
  798. # 显示主区域
  799. screen.blit(self.main_area, (0, 21), (self.scroll_x_pos - 1, self.scroll_y_pos, G.MAIN_AREA_X_POS, G.MAIN_AREA_Y_POS))
  800. # 显示上ui
  801. for u in self.ui_instances_top:
  802. u.draw(screen)
  803. # 显示屏幕特效
  804. for e in self.effects_screen:
  805. try:
  806. e.draw(screen)
  807. except Exception as e:
  808. print(e)
  809. # 左侧黑条
  810. screen.blit(self.left_black, (0, 0))
  811. # 重置糖泡爆炸音效位
  812. BombInstance.sound_played = False
  813. # 重置糖泡爆炸方向记录
  814. self.grid_damage_orientations.clear()
  815. # print(pygame.time.get_ticks() - a)
  816. def update_obstacles_update_list(self):
  817. self.obstacle_instances_need_to_update = False
  818. self.obstacle_instances_update.clear()
  819. for x in range(int(self.scroll_x_pos / G.GAME_SQUARE), int((self.scroll_x_pos + G.MAIN_AREA_X_POS) / G.GAME_SQUARE) + 1):
  820. for y in range(int(self.scroll_y_pos / G.GAME_SQUARE), int((self.scroll_y_pos + G.MAIN_AREA_Y_POS) / G.GAME_SQUARE) + 1):
  821. if (x, y) in self.obstacle_instances.keys():
  822. an_obstacle = self.obstacle_instances[(x, y)]
  823. self.obstacle_instances_update.append(an_obstacle)
  824. def display_frame_rate(self, current_time, screen):
  825. self.frames_num += 1
  826. current_time_div_1000 = current_time // 1000
  827. if current_time_div_1000 > self.times_num:
  828. self.times_num = current_time_div_1000
  829. G.TIME = self.times_num
  830. self.map_time = self.times_num - G.LASTMAPTIME
  831. self.level_time = self.times_num - G.LAST_LEVEL_TIME
  832. if G.DISPLAY_FRAME_RATE:
  833. if G.SHOW_STAT:
  834. # img = self.frame_rate_text_font.render("{:04d}, 游戏时长 - {:03d}:{:02d}, 关卡:{:02d}/{:02d}, 杀敌:{:03d}/{:03d}, v={:}".format(self.frames_num, self.map_time//60, self.map_time%60, G.CURRENT_LEVEL, G.TOTAL_LEVEL, G.KILLED_NPC, G.TOTAL_NPC, self.me.speed), False, (255, 255, 255), (0, 0, 0))
  835. img = self.frame_rate_text_font.render("{:04d}, 游戏时长 - {:03d}:{:02d}, 关卡:{:02d}/{:02d}, 杀敌:{:03d}/{:03d}".format(self.frames_num, self.map_time//60, self.map_time%60, G.CURRENT_LEVEL, G.TOTAL_LEVEL, G.KILLED_NPC, G.TOTAL_NPC), False, (255, 255, 255), (0, 0, 0))
  836. else:
  837. img = self.frame_rate_text_font.render("{:04d}, 游戏时长 - {:03d}:{:02d}".format(self.frames_num, self.map_time//60, self.map_time%60), False, (255, 255, 255), (0, 0, 0))
  838. screen.blit(img, (100, 0))
  839. self.frames_num = 0
  840. def pass_map(self):
  841. # 尝试置finish_flag为True
  842. if self.district_all_finished and self.finish_at is not None:
  843. if self.me.x == self.finish_at[0] and self.me.y == self.finish_at[1]:
  844. self.finish_flag = True
  845. G.LAST_LEVEL_TIME = self.times_num
  846. # 传送门,参数格式: {"[x1,y1]":{"type": "level", "target": [x2,y2]}, "[x3,y3]":{"type": "map", "target": 3}, "[x4,y4]":{"type": "map_set", "target": "Mo1"}}
  847. def portal_map(self):
  848. if len(self.portal_set) != 0:
  849. for point in self.portal_set:
  850. if self.me.x == point[0][0] and self.me.y == point[0][1]:
  851. port_type, target = point[1], point[2]
  852. sound_player.play("X08_01")
  853. # 地图内闪现
  854. if port_type == "level":
  855. self.me.set_xy(target[0], target[1])
  856. self.scroll_map()
  857. # 跳到当前第几关
  858. elif port_type == "map":
  859. target = max(1, int(target))
  860. G.CURRENT_LEVEL = target - 1
  861. self.game.map_set_at = target - 2
  862. self.finish_flag = True
  863. G.LAST_LEVEL_TIME = self.times_num
  864. # 在后面插入一关
  865. elif port_type == "insert":
  866. map_name = target
  867. hero_name = self.game.cfg_json["your_hero"]
  868. character_color = self.game.cfg_json["your_character_color"]
  869. self.game.set_level(self.your_name, map_name, hero_name, character_color, is_reset=False)
  870. G.LAST_LEVEL_TIME = self.times_num
  871. G.CURRENT_LEVEL -= 1
  872. else:
  873. self.game.reset(target) # 换大地图
  874. def scroll_map(self):
  875. # 滚动地图
  876. MAX_DIST = 20 # 单次最大滚动距离
  877. scroll_x_old = self.scroll_x_pos
  878. scroll_y_old = self.scroll_y_pos
  879. if self.me.x_pos > self.scroll_x_pos + G.R_SCROLL:
  880. # 向右滚动
  881. self.scroll_x_pos = max(0, min(self.me.x_pos - G.R_SCROLL, self.scroll_x_pos_max))
  882. elif self.me.x_pos < self.scroll_x_pos + G.L_SCROLL:
  883. # 向左滚动
  884. self.scroll_x_pos = max(0, min(self.me.x_pos - G.L_SCROLL, self.scroll_x_pos_max))
  885. if self.me.y_pos > self.scroll_y_pos + G.D_SCROLL:
  886. # 向下滚动
  887. self.scroll_y_pos = max(0, min(self.me.y_pos - G.D_SCROLL, self.scroll_y_pos_max))
  888. elif self.me.y_pos < self.scroll_y_pos + G.U_SCROLL:
  889. # 向上滚动
  890. self.scroll_y_pos = max(0, min(self.me.y_pos - G.U_SCROLL, self.scroll_y_pos_max))
  891. if self.current_time - self.map_init_time > 3000:
  892. # 限制滚动速度
  893. if self.scroll_x_pos - scroll_x_old > MAX_DIST:
  894. self.scroll_x_pos = scroll_x_old + MAX_DIST
  895. self.obstacle_instances_need_to_update = True
  896. if self.scroll_x_pos - scroll_x_old < -MAX_DIST:
  897. self.scroll_x_pos = scroll_x_old - MAX_DIST
  898. self.obstacle_instances_need_to_update = True
  899. if self.scroll_y_pos - scroll_y_old > MAX_DIST:
  900. self.scroll_y_pos = scroll_y_old + MAX_DIST
  901. self.obstacle_instances_need_to_update = True
  902. if self.scroll_y_pos - scroll_y_old < -MAX_DIST:
  903. self.scroll_y_pos = scroll_y_old - MAX_DIST
  904. self.obstacle_instances_need_to_update = True
  905. # 限制滚动范围
  906. if self.scroll_x_pos > self.scroll_x_pos_max:
  907. self.scroll_x_pos = self.scroll_x_pos_max
  908. if self.scroll_y_pos > self.scroll_y_pos_max:
  909. self.scroll_y_pos = self.scroll_y_pos_max
  910. '''
  911. def scroll_map(self):
  912. # 滚动地图
  913. if self.me.x_pos > self.scroll_x_pos + G.R_SCROLL:
  914. # 向右滚动
  915. self.scroll_x_pos = max(0, min(self.me.x_pos - G.R_SCROLL, self.scroll_x_pos_max))
  916. elif self.me.x_pos < self.scroll_x_pos + G.L_SCROLL:
  917. # 向左滚动
  918. self.scroll_x_pos = max(0, min(self.me.x_pos - G.L_SCROLL, self.scroll_x_pos_max))
  919. if self.me.y_pos > self.scroll_y_pos + G.D_SCROLL:
  920. # 向下滚动
  921. self.scroll_y_pos = max(0, min(self.me.y_pos - G.D_SCROLL, self.scroll_y_pos_max))
  922. elif self.me.y_pos < self.scroll_y_pos + G.U_SCROLL:
  923. # 向上滚动
  924. self.scroll_y_pos = max(0, min(self.me.y_pos - G.U_SCROLL, self.scroll_y_pos_max))
  925. '''
  926. def alarm_district(self):
  927. # 显示当前区域的警戒
  928. if self.district_alarming:
  929. return
  930. DistrictAlarm(self.effects_behind)
  931. def get_bomb_instance(self, x, y):
  932. # 获取(x, y)处的所有糖泡list
  933. bs = list()
  934. for b in self.bomb_instances:
  935. if b.x == x and b.y == y and not b.throwing:
  936. bs.append(b)
  937. return bs
  938. def get_an_npc(self, name, point):
  939. return Npc(name, point)