图像目录和 cx_Freeze

Image directories and cx_Freeze

所以基本上我想将 .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
    )

您可以在 "include_files" 指令中包含一个相对目录。像这样:

include_files = [("game_assets", "assets")]

这会将目录 "game_assets" 中的所有文件复制到目标目录 "assets"。当然,您可以随意使用任何名称!