|
|
@@ -30,12 +30,14 @@ from client_local.ui.game.score_board import ScoreBoard, Timer
|
|
|
from client_local.ui.game.status_bar import StatusBar
|
|
|
from client_local.ui.game.message_input import InputEntry, InputLevel
|
|
|
from client_local.file_loader.fileLoader import load_json, load_png
|
|
|
+from client_local.skill.skill import WinEffect
|
|
|
from client_local.skill.level_skill import Level3x3RandomThunder, DebuffPoisonGrid
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
current_level = None
|
|
|
level_font = pygame.font.Font("res/font/simsun.ttc", 16)
|
|
|
+Y_SCALE_FACTOR = 1 # 用于地震效果,画面会按比例以中间为基准进行上下偏移实现压缩效果
|
|
|
|
|
|
max_alpha = 255 # 最大透明度
|
|
|
circleMasks = {}
|
|
|
@@ -187,6 +189,17 @@ def caesar_encrypt(text, k=3):
|
|
|
return encrypted_text
|
|
|
|
|
|
|
|
|
+class MainArea(pygame.Surface):
|
|
|
+ def __init__(self, size, flags=0):
|
|
|
+ super().__init__(size, flags)
|
|
|
+
|
|
|
+ def blit(self, source, dest, area=None, special_flags=0):
|
|
|
+ relative_y = dest[1] - current_level.scroll_y_pos - G.MAIN_AREA_Y_POS//2
|
|
|
+ scale_bias_value = relative_y * (1 - Y_SCALE_FACTOR)
|
|
|
+ dest = (dest[0], int(dest[1] - scale_bias_value))
|
|
|
+ super().blit(source, dest, area, special_flags)
|
|
|
+
|
|
|
+
|
|
|
class Level:
|
|
|
|
|
|
def __init__(self, your_name: str, map_name: str, me: Hero, music_volume, accumulation_time, game=None):
|
|
|
@@ -222,6 +235,12 @@ class Level:
|
|
|
self.map_music_volume = music_volume # 关卡背景音乐音量大小
|
|
|
self.finish_at = None # 地图过关点(x, y)
|
|
|
|
|
|
+ self.earth_quake_init_tick = 0 # 地震初始化tick
|
|
|
+ self.earth_quake_left_times = 0 # 地震剩余次数
|
|
|
+ self.earth_quake_strength = 0 # 地震强度
|
|
|
+ self.earth_quake_times = 0 # 地震次数
|
|
|
+ self.earth_quake_decrease = True # 地震强度是否递减
|
|
|
+
|
|
|
self.current_time = pygame.time.get_ticks()
|
|
|
self.floor_image = None # 游戏主区域的地板背景
|
|
|
self.flame_instances = None # FlameInstance对象列表
|
|
|
@@ -236,7 +255,7 @@ class Level:
|
|
|
self.block_flame = None # 三维NumPy对象,阻挡糖跑
|
|
|
self.slide_orientation = dict() # (x, y) --> (m, n) m网格传送带方向 0无 1右 2上 3左 4下 n速度
|
|
|
self.grid_damage_blood = dict() # 网格伤害血量
|
|
|
- self.grid_damage_time = dict() # 网格伤害时刻 只有糖泡爆炸时才会增加
|
|
|
+ self.grid_damage_time = defaultdict(None) # 网格伤害时刻 只有糖泡爆炸时才会增加
|
|
|
self.grid_damage_multiples = dict() # 伤害次数(倍数)
|
|
|
# self.grid_damage_orientations = dict() # 网格伤害方向
|
|
|
self.grid_damage_orientations = defaultdict(set)
|
|
|
@@ -252,6 +271,7 @@ class Level:
|
|
|
self.left_black = None # 屏幕右侧黑条
|
|
|
|
|
|
self.grid_bomb_time_at = dict() # 糖泡伤害时刻
|
|
|
+ self.level_variables = dict()
|
|
|
|
|
|
self.blood_bar = None
|
|
|
self.status_bar = None
|
|
|
@@ -275,6 +295,7 @@ class Level:
|
|
|
self.custom_next_map = None
|
|
|
self.portal = dict()
|
|
|
self.portal_set = []
|
|
|
+ self.has_achievemeny_check = False
|
|
|
|
|
|
self.special_music_volume = 1 # 若需放大音乐
|
|
|
|
|
|
@@ -336,6 +357,12 @@ class Level:
|
|
|
# 紫色毒陷阱判断
|
|
|
DebuffPoisonGrid(self.me, self.npcs, self.skill_instances)
|
|
|
|
|
|
+ def set_level_variables(self, name, value):
|
|
|
+ self.level_variables[name] = value
|
|
|
+
|
|
|
+ def get_level_variables(self, name, default_value):
|
|
|
+ return self.level_variables.get(name, default_value)
|
|
|
+
|
|
|
def load_map_json(self):
|
|
|
# 加载关卡json文件
|
|
|
map_json = load_json("game/map/" + self.map_name + ".json")
|
|
|
@@ -385,7 +412,7 @@ class Level:
|
|
|
self.district_square = {"x1": 0, "x2": 0, "y1": 0, "y2": 0}
|
|
|
if "finish" in self.map_json["basic"].keys():
|
|
|
self.finish_at = (self.map_json["basic"]["finish"][0], self.map_json["basic"]["finish"][1])
|
|
|
- self.main_area = pygame.Surface((self.map_x_pos, self.map_y_pos)).convert()
|
|
|
+ self.main_area = MainArea((self.map_x_pos, self.map_y_pos)).convert()
|
|
|
self.left_black = pygame.Surface((1, 600))
|
|
|
|
|
|
if "haunted" in self.map_json["basic"].keys():
|
|
|
@@ -458,6 +485,35 @@ class Level:
|
|
|
self.blood_bar.set_name(self.your_name)
|
|
|
self.ui_instances_top.append(self.blood_bar)
|
|
|
|
|
|
+ def earth_quake_effect(self, strength=0.1, times=3, duration_per_time=200, decrease=True):
|
|
|
+ '''屏幕震动效果,强度表示移动像素数量,times表示震动次数,duration_per_time表示每次震动持续时间'''
|
|
|
+ self.earth_quake_strength = strength
|
|
|
+ self.earth_quake_times = times
|
|
|
+ self.earth_quake_duration_per_time = duration_per_time
|
|
|
+ self.earth_quake_time = pygame.time.get_ticks()
|
|
|
+ self.earth_quake_decrease = decrease
|
|
|
+
|
|
|
+ def run_earth_quake_effect(self, screen: pygame.Surface = None):
|
|
|
+ '''运行屏幕震动效果'''
|
|
|
+ global Y_SCALE_FACTOR
|
|
|
+ if self.earth_quake_strength <= 0 or self.earth_quake_times <= 0:
|
|
|
+ Y_SCALE_FACTOR = 1
|
|
|
+ return
|
|
|
+ now = pygame.time.get_ticks()
|
|
|
+ if now - self.earth_quake_time >= self.earth_quake_duration_per_time:
|
|
|
+ self.earth_quake_times -= 1
|
|
|
+ self.earth_quake_time = now
|
|
|
+ if self.earth_quake_decrease:
|
|
|
+ self.earth_quake_strength = self.earth_quake_strength * 0.5
|
|
|
+ if self.earth_quake_times <= 0:
|
|
|
+ self.earth_quake_strength = 0
|
|
|
+ return
|
|
|
+ # 计算偏移量(抛物线计算当前高度)
|
|
|
+ t = (now - self.earth_quake_time) / self.earth_quake_duration_per_time
|
|
|
+ Y_SCALE_FACTOR = 1 - self.earth_quake_strength * t * (1 - t)
|
|
|
+ MAX_BIAS = G.MAIN_AREA_Y_POS * (1-Y_SCALE_FACTOR)//2
|
|
|
+ screen.fill((0, 0, 0, 0), rect=(0, 21, G.MAIN_AREA_X_POS, MAX_BIAS))
|
|
|
+
|
|
|
def load_floor(self):
|
|
|
# 加载地板floor
|
|
|
self.floor_image = pygame.Surface((self.map_x_pos, self.map_y_pos), flags=pygame.HWSURFACE)
|
|
|
@@ -552,6 +608,7 @@ class Level:
|
|
|
if self.check_achievement() and G.CURRENT_LEVEL == G.TOTAL_LEVEL and not G.HAS_RECORD:
|
|
|
G.HAS_RECORD = True
|
|
|
sound_player.playWin("PlayerWin")
|
|
|
+ WinEffect(self.me, self.me, "big", self.skill_instances)
|
|
|
# 构建保存文件的路径
|
|
|
user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
|
|
|
qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
|
|
|
@@ -612,6 +669,9 @@ class Level:
|
|
|
G.MONSTER_RECORD_LIST = []
|
|
|
except:
|
|
|
G.MONSTER_RECORD_LIST = []
|
|
|
+ else:
|
|
|
+ if G.CURRENT_LEVEL == G.TOTAL_LEVEL:
|
|
|
+ WinEffect(self.me, self.me, "normal", self.skill_instances)
|
|
|
|
|
|
def load_district_and_enemies(self):
|
|
|
if len(self.npcs) > 0: # npc还没有被杀光
|
|
|
@@ -621,7 +681,9 @@ class Level:
|
|
|
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()
|
|
|
+ if not self.has_achievemeny_check:
|
|
|
+ self.has_achievemeny_check = True
|
|
|
+ self.check_game_achievement()
|
|
|
return
|
|
|
self.district_idx += 1
|
|
|
a_district = self.map_json["districts"][self.district_idx - 1]
|
|
|
@@ -664,6 +726,7 @@ class Level:
|
|
|
def update(self, screen: pygame.Surface):
|
|
|
# a = pygame.time.get_ticks()
|
|
|
self.current_time = pygame.time.get_ticks()
|
|
|
+ self.run_earth_quake_effect(screen) # 运行屏幕震动效果
|
|
|
|
|
|
# 刷新帧率
|
|
|
self.display_frame_rate(self.current_time, screen)
|
|
|
@@ -758,6 +821,11 @@ class Level:
|
|
|
for u in self.ui_instances_bot:
|
|
|
u.update()
|
|
|
|
|
|
+ if Y_SCALE_FACTOR != 1:
|
|
|
+ MAX_BIAS = G.MAIN_AREA_Y_POS * (1-Y_SCALE_FACTOR)//2
|
|
|
+ # 上下MAX_BIAS区域填充(0,0,0,0)
|
|
|
+ self.main_area.fill((255, 255, 255, 0), (self.scroll_x_pos, self.scroll_y_pos + 21, G.MAIN_AREA_X_POS, MAX_BIAS))
|
|
|
+
|
|
|
# 显示地板
|
|
|
self.main_area.blit(
|
|
|
self.floor_image,
|