|
@@ -105,7 +105,13 @@ def get_player_mask(mask_surface, bgl):
|
|
|
global _last_light_states
|
|
global _last_light_states
|
|
|
# 收集当前所有光源状态 (x, y, light)
|
|
# 收集当前所有光源状态 (x, y, light)
|
|
|
curr = []
|
|
curr = []
|
|
|
- for p in [current_level.me] + current_level.npcs + list(current_level.obstacle_instances.values()):
|
|
|
|
|
|
|
+ for p in [current_level.me]:
|
|
|
|
|
+ if p.light and (not p.is_hide_sight()):
|
|
|
|
|
+ curr.append((p.x_pos, p.y_pos, p.light))
|
|
|
|
|
+ for p in current_level.npcs:
|
|
|
|
|
+ if p.light and (not p.is_hide_sight()):
|
|
|
|
|
+ curr.append((p.x_pos, p.y_pos, p.light))
|
|
|
|
|
+ for p in current_level.obstacle_instances.values():
|
|
|
if p.light:
|
|
if p.light:
|
|
|
curr.append((p.x_pos, p.y_pos, p.light))
|
|
curr.append((p.x_pos, p.y_pos, p.light))
|
|
|
curr_key = tuple(curr)
|
|
curr_key = tuple(curr)
|
|
@@ -445,10 +451,9 @@ class Level:
|
|
|
if not G.SHOW_INPUT:
|
|
if not G.SHOW_INPUT:
|
|
|
G.SHOW_INPUT = True
|
|
G.SHOW_INPUT = True
|
|
|
self.message_entry = InputEntry() # 聊天输入框
|
|
self.message_entry = InputEntry() # 聊天输入框
|
|
|
- self.ui_instances_top.append(self.message_entry)
|
|
|
|
|
else:
|
|
else:
|
|
|
self.message_entry = InputLevel() # 聊天输入框
|
|
self.message_entry = InputLevel() # 聊天输入框
|
|
|
- self.ui_instances_top.append(self.message_entry)
|
|
|
|
|
|
|
+ self.ui_instances_top.append(self.message_entry)
|
|
|
self.blood_bar = BloodBar(self.me)
|
|
self.blood_bar = BloodBar(self.me)
|
|
|
self.blood_bar.set_name(self.your_name)
|
|
self.blood_bar.set_name(self.your_name)
|
|
|
self.ui_instances_top.append(self.blood_bar)
|
|
self.ui_instances_top.append(self.blood_bar)
|
|
@@ -507,113 +512,116 @@ class Level:
|
|
|
def record_achievement(self):
|
|
def record_achievement(self):
|
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
- def load_district_and_enemies(self):
|
|
|
|
|
- if len(self.npcs) > 0: # npc还没有被杀光
|
|
|
|
|
- return
|
|
|
|
|
- self.me.district_locked = False # 解除玩家区域锁
|
|
|
|
|
- if self.district_idx >= len(self.map_json["districts"]): # 已完成最后一个区域
|
|
|
|
|
- self.district_square = {"x1": 0, "x2": 0, "y1": 0, "y2": 0}
|
|
|
|
|
- self.district_square_grid = {"x1": 0, "x2": 0, "y1": 0, "y2": 0}
|
|
|
|
|
- self.district_all_finished = True
|
|
|
|
|
-
|
|
|
|
|
- if self.check_full_achievement() and not G.HAS_RECORD_FULL:
|
|
|
|
|
- G.HAS_RECORD_FULL = True
|
|
|
|
|
- # 构建保存文件的路径
|
|
|
|
|
- user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
|
|
|
|
|
- qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
|
|
|
|
|
- os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
|
|
|
|
|
- full_achievements_file_path = os.path.join(qqtpve_folder, "full_achievements.json") # 构建full_achievements.json文件路径
|
|
|
|
|
|
|
+ def check_game_achievement(self):
|
|
|
|
|
+ if self.check_full_achievement() and not G.HAS_RECORD_FULL:
|
|
|
|
|
+ G.HAS_RECORD_FULL = True
|
|
|
|
|
+ # 构建保存文件的路径
|
|
|
|
|
+ user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
|
|
|
|
|
+ qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
|
|
|
|
|
+ os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
|
|
|
|
|
+ full_achievements_file_path = os.path.join(qqtpve_folder, "full_achievements.json") # 构建full_achievements.json文件路径
|
|
|
|
|
+ try:
|
|
|
|
|
+ with open(full_achievements_file_path, encoding="utf-8") as file:
|
|
|
|
|
+ encrypted_data = json.load(file)
|
|
|
|
|
+ except:
|
|
|
try:
|
|
try:
|
|
|
- with open(full_achievements_file_path, encoding="utf-8") as file:
|
|
|
|
|
|
|
+ with open(full_achievements_file_path, encoding="utf-8_sig") as file:
|
|
|
encrypted_data = json.load(file)
|
|
encrypted_data = json.load(file)
|
|
|
except:
|
|
except:
|
|
|
- try:
|
|
|
|
|
- with open(full_achievements_file_path, encoding="utf-8_sig") as file:
|
|
|
|
|
- encrypted_data = json.load(file)
|
|
|
|
|
- except:
|
|
|
|
|
- # 如果文件不存在,创建新的空的achievements.json文件
|
|
|
|
|
- encrypted_data = {"STAT": []}
|
|
|
|
|
- with open(full_achievements_file_path, 'w', encoding="utf-8") as file:
|
|
|
|
|
- json.dump(encrypted_data, file, indent=2)
|
|
|
|
|
- if encrypted_data == {}:
|
|
|
|
|
|
|
+ # 如果文件不存在,创建新的空的achievements.json文件
|
|
|
encrypted_data = {"STAT": []}
|
|
encrypted_data = {"STAT": []}
|
|
|
- # 新的数据
|
|
|
|
|
- new_data = {caesar_encrypt("name"): caesar_encrypt(G.MAP_SET_NAME),
|
|
|
|
|
- caesar_encrypt("last_map_name"): caesar_encrypt(G.MAP_NAME),
|
|
|
|
|
- caesar_encrypt("map_order"): int(caesar_encrypt(str(G.CURRENT_LEVEL))),
|
|
|
|
|
- caesar_encrypt("LV"): int(caesar_encrypt(str(self.me.blood))),
|
|
|
|
|
- caesar_encrypt("time"): caesar_encrypt(datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
|
|
|
|
|
- caesar_encrypt("game_time_min"): int(caesar_encrypt(str(self.map_time//60))),
|
|
|
|
|
- caesar_encrypt("game_time_sec"): int(caesar_encrypt(str(self.map_time%60)))}
|
|
|
|
|
- # 添加新的加密数据
|
|
|
|
|
- encrypted_data["STAT"].append(new_data)
|
|
|
|
|
- with open(full_achievements_file_path, 'w') as file:
|
|
|
|
|
- json.dump(encrypted_data, file, indent=2)
|
|
|
|
|
-
|
|
|
|
|
- if self.check_achievement() and G.CURRENT_LEVEL==G.TOTAL_LEVEL and not G.HAS_RECORD:
|
|
|
|
|
- G.HAS_RECORD = True
|
|
|
|
|
- sound_player.playWin("PlayerWin")
|
|
|
|
|
- # 构建保存文件的路径
|
|
|
|
|
- user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
|
|
|
|
|
- qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
|
|
|
|
|
- os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
|
|
|
|
|
- achievements_file_path = os.path.join(qqtpve_folder, "achievements.json") # 构建achievements.json文件路径
|
|
|
|
|
- monster_stats_file_path = os.path.join(qqtpve_folder, "monster_stats.json") # 构建json文件路径
|
|
|
|
|
|
|
+ with open(full_achievements_file_path, 'w', encoding="utf-8") as file:
|
|
|
|
|
+ json.dump(encrypted_data, file, indent=2)
|
|
|
|
|
+ if encrypted_data == {}:
|
|
|
|
|
+ encrypted_data = {"STAT": []}
|
|
|
|
|
+ # 新的数据
|
|
|
|
|
+ new_data = {
|
|
|
|
|
+ caesar_encrypt("name"): caesar_encrypt(G.MAP_SET_NAME),
|
|
|
|
|
+ caesar_encrypt("last_map_name"): caesar_encrypt(G.MAP_NAME),
|
|
|
|
|
+ caesar_encrypt("map_order"): int(caesar_encrypt(str(G.CURRENT_LEVEL))),
|
|
|
|
|
+ caesar_encrypt("LV"): int(caesar_encrypt(str(self.me.blood))),
|
|
|
|
|
+ caesar_encrypt("time"): caesar_encrypt(datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
|
|
|
|
|
+ caesar_encrypt("game_time_min"): int(caesar_encrypt(str(self.map_time//60))),
|
|
|
|
|
+ caesar_encrypt("game_time_sec"): int(caesar_encrypt(str(self.map_time%60)))
|
|
|
|
|
+ }
|
|
|
|
|
+ # 添加新的加密数据
|
|
|
|
|
+ encrypted_data["STAT"].append(new_data)
|
|
|
|
|
+ with open(full_achievements_file_path, 'w') as file:
|
|
|
|
|
+ json.dump(encrypted_data, file, indent=2)
|
|
|
|
|
+
|
|
|
|
|
+ if self.check_achievement() and G.CURRENT_LEVEL == G.TOTAL_LEVEL and not G.HAS_RECORD:
|
|
|
|
|
+ G.HAS_RECORD = True
|
|
|
|
|
+ sound_player.playWin("PlayerWin")
|
|
|
|
|
+ # 构建保存文件的路径
|
|
|
|
|
+ user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
|
|
|
|
|
+ qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
|
|
|
|
|
+ os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
|
|
|
|
|
+ achievements_file_path = os.path.join(qqtpve_folder, "achievements.json") # 构建achievements.json文件路径
|
|
|
|
|
+ monster_stats_file_path = os.path.join(qqtpve_folder, "monster_stats.json") # 构建json文件路径
|
|
|
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ with open(achievements_file_path, encoding="utf-8") as file:
|
|
|
|
|
+ encrypted_data = json.load(file)
|
|
|
|
|
+ except:
|
|
|
try:
|
|
try:
|
|
|
- with open(achievements_file_path, encoding="utf-8") as file:
|
|
|
|
|
|
|
+ with open(achievements_file_path, encoding="utf-8_sig") as file:
|
|
|
encrypted_data = json.load(file)
|
|
encrypted_data = json.load(file)
|
|
|
except:
|
|
except:
|
|
|
- try:
|
|
|
|
|
- with open(achievements_file_path, encoding="utf-8_sig") as file:
|
|
|
|
|
- encrypted_data = json.load(file)
|
|
|
|
|
- except:
|
|
|
|
|
- # 如果文件不存在,创建新的空的achievements.json文件
|
|
|
|
|
- encrypted_data = {"STAT": []}
|
|
|
|
|
- with open(achievements_file_path, 'w', encoding="utf-8") as file:
|
|
|
|
|
- json.dump(encrypted_data, file, indent=2)
|
|
|
|
|
- if encrypted_data == {}:
|
|
|
|
|
|
|
+ # 如果文件不存在,创建新的空的achievements.json文件
|
|
|
encrypted_data = {"STAT": []}
|
|
encrypted_data = {"STAT": []}
|
|
|
- # 新的数据
|
|
|
|
|
- new_data = {caesar_encrypt("name"): caesar_encrypt(G.MAP_SET_NAME),
|
|
|
|
|
- caesar_encrypt("last_map_name"): caesar_encrypt(G.MAP_NAME),
|
|
|
|
|
- caesar_encrypt("LV"): int(caesar_encrypt(str(self.me.blood))),
|
|
|
|
|
- caesar_encrypt("time"): caesar_encrypt(datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
|
|
|
|
|
- caesar_encrypt("game_time_min"): int(caesar_encrypt(str(self.map_time//60))),
|
|
|
|
|
- caesar_encrypt("game_time_sec"): int(caesar_encrypt(str(self.map_time%60))),
|
|
|
|
|
- caesar_encrypt("remain_blood"): int(caesar_encrypt(str(self.me.remain_blood)))}
|
|
|
|
|
- try:
|
|
|
|
|
- # 添加新的加密数据
|
|
|
|
|
- encrypted_data["STAT"].append(new_data)
|
|
|
|
|
- with open(achievements_file_path, 'w') as file:
|
|
|
|
|
|
|
+ with open(achievements_file_path, 'w', encoding="utf-8") as file:
|
|
|
json.dump(encrypted_data, file, indent=2)
|
|
json.dump(encrypted_data, file, indent=2)
|
|
|
- except:
|
|
|
|
|
- pass
|
|
|
|
|
|
|
+ if encrypted_data == {}:
|
|
|
|
|
+ encrypted_data = {"STAT": []}
|
|
|
|
|
+ # 新的数据
|
|
|
|
|
+ new_data = {caesar_encrypt("name"): caesar_encrypt(G.MAP_SET_NAME),
|
|
|
|
|
+ caesar_encrypt("last_map_name"): caesar_encrypt(G.MAP_NAME),
|
|
|
|
|
+ caesar_encrypt("LV"): int(caesar_encrypt(str(self.me.blood))),
|
|
|
|
|
+ caesar_encrypt("time"): caesar_encrypt(datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
|
|
|
|
|
+ caesar_encrypt("game_time_min"): int(caesar_encrypt(str(self.map_time//60))),
|
|
|
|
|
+ caesar_encrypt("game_time_sec"): int(caesar_encrypt(str(self.map_time%60))),
|
|
|
|
|
+ caesar_encrypt("remain_blood"): int(caesar_encrypt(str(self.me.remain_blood)))}
|
|
|
|
|
+ try:
|
|
|
|
|
+ # 添加新的加密数据
|
|
|
|
|
+ encrypted_data["STAT"].append(new_data)
|
|
|
|
|
+ with open(achievements_file_path, 'w') as file:
|
|
|
|
|
+ json.dump(encrypted_data, file, indent=2)
|
|
|
|
|
+ except:
|
|
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ with open(monster_stats_file_path, encoding="utf-8") as file:
|
|
|
|
|
+ self.encrypted_data_m = json.load(file)
|
|
|
|
|
+ except:
|
|
|
try:
|
|
try:
|
|
|
- with open(monster_stats_file_path, encoding="utf-8") as file:
|
|
|
|
|
|
|
+ with open(monster_stats_file_path, encoding="utf-8_sig") as file:
|
|
|
self.encrypted_data_m = json.load(file)
|
|
self.encrypted_data_m = json.load(file)
|
|
|
except:
|
|
except:
|
|
|
- try:
|
|
|
|
|
- with open(monster_stats_file_path, encoding="utf-8_sig") as file:
|
|
|
|
|
- self.encrypted_data_m = json.load(file)
|
|
|
|
|
- except:
|
|
|
|
|
- # 如果文件不存在,创建新的空的json文件
|
|
|
|
|
- self.encrypted_data_m = {"STAT": []}
|
|
|
|
|
- with open(monster_stats_file_path, 'w', encoding="utf-8") as file:
|
|
|
|
|
- json.dump(self.encrypted_data_m, file, indent=2)
|
|
|
|
|
- if self.encrypted_data_m == {}:
|
|
|
|
|
|
|
+ # 如果文件不存在,创建新的空的json文件
|
|
|
self.encrypted_data_m = {"STAT": []}
|
|
self.encrypted_data_m = {"STAT": []}
|
|
|
-
|
|
|
|
|
- try:
|
|
|
|
|
- for data in G.MONSTER_RECORD_LIST:
|
|
|
|
|
- self.encrypted_data_m["STAT"].append(data)
|
|
|
|
|
- with open(monster_stats_file_path, 'w') as file:
|
|
|
|
|
|
|
+ with open(monster_stats_file_path, 'w', encoding="utf-8") as file:
|
|
|
json.dump(self.encrypted_data_m, file, indent=2)
|
|
json.dump(self.encrypted_data_m, file, indent=2)
|
|
|
- G.MONSTER_RECORD_LIST = []
|
|
|
|
|
- except:
|
|
|
|
|
- G.MONSTER_RECORD_LIST = []
|
|
|
|
|
|
|
+ if self.encrypted_data_m == {}:
|
|
|
|
|
+ self.encrypted_data_m = {"STAT": []}
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ for data in G.MONSTER_RECORD_LIST:
|
|
|
|
|
+ self.encrypted_data_m["STAT"].append(data)
|
|
|
|
|
+ with open(monster_stats_file_path, 'w') as file:
|
|
|
|
|
+ json.dump(self.encrypted_data_m, file, indent=2)
|
|
|
|
|
+ G.MONSTER_RECORD_LIST = []
|
|
|
|
|
+ except:
|
|
|
|
|
+ G.MONSTER_RECORD_LIST = []
|
|
|
|
|
|
|
|
|
|
+ def load_district_and_enemies(self):
|
|
|
|
|
+ if len(self.npcs) > 0: # npc还没有被杀光
|
|
|
|
|
+ return
|
|
|
|
|
+ self.me.district_locked = False # 解除玩家区域锁
|
|
|
|
|
+ if self.district_idx >= len(self.map_json["districts"]): # 已完成最后一个区域
|
|
|
|
|
+ self.district_square = {"x1": 0, "x2": 0, "y1": 0, "y2": 0}
|
|
|
|
|
+ self.district_square_grid = {"x1": 0, "x2": 0, "y1": 0, "y2": 0}
|
|
|
|
|
+ self.district_all_finished = True
|
|
|
|
|
+ self.check_game_achievement()
|
|
|
return
|
|
return
|
|
|
self.district_idx += 1
|
|
self.district_idx += 1
|
|
|
a_district = self.map_json["districts"][self.district_idx - 1]
|
|
a_district = self.map_json["districts"][self.district_idx - 1]
|
|
@@ -634,7 +642,11 @@ class Level:
|
|
|
self.ghosts.remove(g)
|
|
self.ghosts.remove(g)
|
|
|
for n in a_district["npcs"]:
|
|
for n in a_district["npcs"]:
|
|
|
# 载入新区域的npc
|
|
# 载入新区域的npc
|
|
|
- self.npcs.append(Npc(n["name"], (n["x"], n["y"])))
|
|
|
|
|
|
|
+ patrol = n.get("patrol", None)
|
|
|
|
|
+ if patrol is not None:
|
|
|
|
|
+ self.npcs.append(Npc(n["name"], (n["x"], n["y"]), patrol_path=patrol))
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.npcs.append(Npc(n["name"], (n["x"], n["y"])))
|
|
|
for district in self.map_json["districts"][self.district_idx-1:]:
|
|
for district in self.map_json["districts"][self.district_idx-1:]:
|
|
|
x1, y1, x2, y2 = district["square"]["x1"], district["square"]["y1"], district["square"]["x2"], district["square"]["y2"]
|
|
x1, y1, x2, y2 = district["square"]["x1"], district["square"]["y1"], district["square"]["x2"], district["square"]["y2"]
|
|
|
for point in self.poison_dic.keys():
|
|
for point in self.poison_dic.keys():
|
|
@@ -650,7 +662,6 @@ class Level:
|
|
|
del self.poison_dic[point]
|
|
del self.poison_dic[point]
|
|
|
|
|
|
|
|
def update(self, screen: pygame.Surface):
|
|
def update(self, screen: pygame.Surface):
|
|
|
-
|
|
|
|
|
# a = pygame.time.get_ticks()
|
|
# a = pygame.time.get_ticks()
|
|
|
self.current_time = pygame.time.get_ticks()
|
|
self.current_time = pygame.time.get_ticks()
|
|
|
|
|
|
|
@@ -926,7 +937,7 @@ class Level:
|
|
|
self.scroll_y_pos = scroll_y_old - MAX_DIST
|
|
self.scroll_y_pos = scroll_y_old - MAX_DIST
|
|
|
self.obstacle_instances_need_to_update = True
|
|
self.obstacle_instances_need_to_update = True
|
|
|
# 限制滚动范围
|
|
# 限制滚动范围
|
|
|
- if self.scroll_x_pos> self.scroll_x_pos_max:
|
|
|
|
|
|
|
+ if self.scroll_x_pos > self.scroll_x_pos_max:
|
|
|
self.scroll_x_pos = self.scroll_x_pos_max
|
|
self.scroll_x_pos = self.scroll_x_pos_max
|
|
|
if self.scroll_y_pos > self.scroll_y_pos_max:
|
|
if self.scroll_y_pos > self.scroll_y_pos_max:
|
|
|
self.scroll_y_pos = self.scroll_y_pos_max
|
|
self.scroll_y_pos = self.scroll_y_pos_max
|