所以基本上我想将.py脚本转换为可执行文件。唯一的问题是setup.py文件必须与图像和声音文件位于同一目录中,而我的游戏文件位于setup.py之上的目录中。
我如何编辑安装文件,以便我不必四处转换并更改我的游戏文件中的所有代码?如果需要,我将编辑游戏文件,但最好不要。
from os import path
img_dir = path.join(path.dirname(__file__), 'img')
snd_dir = path.join(path.dirname(__file__), 'snd')
#ways i load in images:
background = pygame.image.load(path.join(img_dir,
"background.jpg")).convert()
alien_images = []
alien_list = ['alien1.png', 'alien2.png']
for img in alien_list:
alien_images.append(pygame.image.load(path.join(img_dir,
img)).convert())`
这是我现在拥有的安装文件。除了当然无法找到图像和声音外,它没有错误。
import cx_Freeze
executables = [cx_Freeze.Executable("Shmup.py")]
cx_Freeze.setup(
name = "Shoot 'm up!",
options = {"build_exe": {"packages":["pygame"],
"include_files": ["alien1.png", "alien2.png",
"background.jpg", "laser1.png",
"powerUp.png", "shield.png",
"regularExplosion00.png",
"regularExplosion01.png",
"regularExplosion02.png",
"regularExplosion03.png",
"regularExplosion04.png",
"regularExplosion05.png",
"regularExplosion06.png",
"regularExplosion07.png",
"regularExplosion07.png",
"regularExplosion08.png",
"regularExplosion09.png",
"ship1.png",
"sonicExplosion00.png",
"sonicExplosion01.png",
"sonicExplosion02.png",
"sonicExplosion03.png",
"sonicExplosion04.png",
"sonicExplosion05.png",
"sonicExplosion06.png",
"sonicExplosion07.png",
"sonicExplosion08.png",
"sonicExplosion09.png",
"Expl.wav", "Expl2.wav",
"Music.ogg", "Pew.wav",
"Powerup.wav", "Rumble.ogg"]}},
executables = executables
)
答案 0 :(得分:0)
您可以在" include_files"中添加相对目录。指示。像这样:
include_files = [("game_assets", "assets")]
这将复制目录中的所有文件" game_assets"到目标目录" assets"。当然,你可以随意使用你想要的任何名称!