|
|
|
@ -5,10 +5,10 @@ import os
|
|
|
|
|
# 初始化 Pygame
|
|
|
|
|
pygame.init()
|
|
|
|
|
|
|
|
|
|
# 设置窗口尺寸
|
|
|
|
|
cell_size = 20 # 单元格大小
|
|
|
|
|
grid_width = 30 # 网格宽度
|
|
|
|
|
grid_height = 20 # 网格高度
|
|
|
|
|
# 设置窗口尺寸 - 增大一倍
|
|
|
|
|
cell_size = 20 # 保持单元格大小不变
|
|
|
|
|
grid_width = 60 # 网格宽度增加一倍
|
|
|
|
|
grid_height = 40 # 网格高度增加一倍
|
|
|
|
|
window_width = grid_width * cell_size
|
|
|
|
|
window_height = grid_height * cell_size
|
|
|
|
|
window = pygame.display.set_mode((window_width, window_height))
|
|
|
|
@ -30,11 +30,8 @@ if os.path.exists(frame_folder):
|
|
|
|
|
for frame_file in sorted(os.listdir(frame_folder)):
|
|
|
|
|
if frame_file.endswith(".png"):
|
|
|
|
|
frame = pygame.image.load(os.path.join(frame_folder, frame_file))
|
|
|
|
|
# 等比例缩放帧图片
|
|
|
|
|
frame_width, frame_height = frame.get_size()
|
|
|
|
|
scale_factor = min(window_width / frame_width, window_height / frame_height) * 0.8 # 缩小一点以便显示文字
|
|
|
|
|
scaled_frame = pygame.transform.scale(frame,
|
|
|
|
|
(int(frame_width * scale_factor), int(frame_height * scale_factor)))
|
|
|
|
|
# 缩放帧图片以覆盖整个窗口
|
|
|
|
|
scaled_frame = pygame.transform.scale(frame, (window_width, window_height))
|
|
|
|
|
frames.append(scaled_frame)
|
|
|
|
|
else:
|
|
|
|
|
print(f"警告: 文件夹 '{frame_folder}' 不存在,将不显示胜利动画")
|
|
|
|
@ -42,10 +39,10 @@ else:
|
|
|
|
|
# 设置字体(使用支持中文的字体文件)
|
|
|
|
|
try:
|
|
|
|
|
font_path = "c:/Windows/Fonts/simhei.ttf" # 替换为你的中文字体文件路径
|
|
|
|
|
font = pygame.font.Font(font_path, 36) # 使用中文字体,字号 36
|
|
|
|
|
font = pygame.font.Font(font_path, 48) # 增大字体大小
|
|
|
|
|
except:
|
|
|
|
|
print("无法加载指定字体,使用默认字体")
|
|
|
|
|
font = pygame.font.Font(None, 36) # 使用默认字体
|
|
|
|
|
font = pygame.font.Font(None, 48) # 使用默认字体,增大字体大小
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 生成随机迷宫
|
|
|
|
@ -225,11 +222,8 @@ while running:
|
|
|
|
|
elif game_state == "victory":
|
|
|
|
|
# 绘制胜利动画
|
|
|
|
|
if frames: # 如果有加载动画帧
|
|
|
|
|
# 将帧居中显示
|
|
|
|
|
frame_width, frame_height = frames[current_frame].get_size()
|
|
|
|
|
x = (window_width - frame_width) // 2
|
|
|
|
|
y = (window_height - frame_height) // 2
|
|
|
|
|
window.blit(frames[current_frame], (x, y))
|
|
|
|
|
# 直接绘制当前帧(已缩放为窗口大小)
|
|
|
|
|
window.blit(frames[current_frame], (0, 0))
|
|
|
|
|
|
|
|
|
|
# 更新帧索引
|
|
|
|
|
if pygame.time.get_ticks() - victory_time > 100: # 每100毫秒更新一次帧
|
|
|
|
@ -238,7 +232,7 @@ while running:
|
|
|
|
|
|
|
|
|
|
# 绘制胜利文字
|
|
|
|
|
victory_text = font.render("胜利!", True, (255, 0, 0)) # 红色文字
|
|
|
|
|
text_rect = victory_text.get_rect(center=(window_width // 2, window_height - 50))
|
|
|
|
|
text_rect = victory_text.get_rect(center=(window_width // 2, window_height - 70))
|
|
|
|
|
window.blit(victory_text, text_rect)
|
|
|
|
|
|
|
|
|
|
# 绘制提示文字
|
|
|
|
|