windows10です。
題の通りで、pygameを使ったロールプレイングゲームを自分で改造して友達と一緒に楽しみたいのですが、pyinstallerでそのままexe化してもうまく起動しませんでした。調べたところ、いろいろやり方があるみたいですがその記事が古かったり難しくよくわかりませんでした。exe化したいのは例えば以下のコードです。
python
1import pygame 2import sys 3import random 4from pygame.locals import * 5 6# 色の定義 7WHITE = (255, 255, 255) 8BLACK = ( 0, 0, 0) 9RED = (255, 0, 0) 10CYAN = ( 0, 255, 255) 11BLINK = [(224,255,255), (192,240,255), (128,224,255), (64,192,255), (128,224,255), (192,240,255)] 12 13# 画像の読み込み 14imgTitle = pygame.image.load("image/title.png") 15imgWall = pygame.image.load("image/wall.png") 16imgWall2 = pygame.image.load("image/wall2.png") 17imgDark = pygame.image.load("image/dark.png") 18imgPara = pygame.image.load("image/parameter.png") 19imgBtlBG = pygame.image.load("image/btlbg.png") 20imgEnemy = pygame.image.load("image/enemy0.png") 21imgItem = [ 22 pygame.image.load("image/potion.png"), 23 pygame.image.load("image/blaze_gem.png"), 24 pygame.image.load("image/spoiled.png"), 25 pygame.image.load("image/apple.png"), 26 pygame.image.load("image/meat.png") 27] 28imgFloor = [ 29 pygame.image.load("image/floor.png"), 30 pygame.image.load("image/tbox.png"), 31 pygame.image.load("image/cocoon.png"), 32 pygame.image.load("image/stairs.png") 33] 34imgPlayer = [ 35 pygame.image.load("image/mychr0.png"), 36 pygame.image.load("image/mychr1.png"), 37 pygame.image.load("image/mychr2.png"), 38 pygame.image.load("image/mychr3.png"), 39 pygame.image.load("image/mychr4.png"), 40 pygame.image.load("image/mychr5.png"), 41 pygame.image.load("image/mychr6.png"), 42 pygame.image.load("image/mychr7.png"), 43 pygame.image.load("image/mychr8.png") 44] 45imgEffect = [ 46 pygame.image.load("image/effect_a.png"), 47 pygame.image.load("image/effect_b.png") 48] 49 50# 変数の宣言 51speed = 1 52idx = 0 53tmr = 0 54floor = 0 55fl_max = 1 56welcome = 0 57 58pl_x = 0 59pl_y = 0 60pl_d = 0 61pl_a = 0 62pl_lifemax = 0 63pl_life = 0 64pl_str = 0 65food = 0 66potion = 0 67blazegem = 0 68treasure = 0 69 70emy_name = "" 71emy_lifemax = 0 72emy_life = 0 73emy_str = 0 74emy_x = 0 75emy_y = 0 76emy_step = 0 77emy_blink = 0 78 79dmg_eff = 0 80btl_cmd = 0 81 82COMMAND = ["[A]ttack", "[P]otion", "[B]laze gem", "[R]un"] 83TRE_NAME = ["Potion", "Blaze gem", "Food spoiled.", "Food +20", "Food +100"] 84EMY_NAME = [ 85 "Green slime", "Red slime", "Axe beast", "Ogre", "Sword man", 86 "Death hornet", "Signal slime", "Devil plant", "Twin killer", "Hell" 87 ] 88 89MAZE_W = 11 90MAZE_H = 9 91maze = [] 92for y in range(MAZE_H): 93 maze.append([0]*MAZE_W) 94 95DUNGEON_W = MAZE_W*3 96DUNGEON_H = MAZE_H*3 97dungeon = [] 98for y in range(DUNGEON_H): 99 dungeon.append([0]*DUNGEON_W) 100 101def make_dungeon(): # ダンジョンの自動生成 102 XP = [ 0, 1, 0,-1] 103 YP = [-1, 0, 1, 0] 104 #周りの壁 105 for x in range(MAZE_W): 106 maze[0][x] = 1 107 maze[MAZE_H-1][x] = 1 108 for y in range(1, MAZE_H-1): 109 maze[y][0] = 1 110 maze[y][MAZE_W-1] = 1 111 #中を何もない状態に 112 for y in range(1, MAZE_H-1): 113 for x in range(1, MAZE_W-1): 114 maze[y][x] = 0 115 #柱 116 for y in range(2, MAZE_H-2, 2): 117 for x in range(2, MAZE_W-2, 2): 118 maze[y][x] = 1 119 #柱から上下左右に壁を作る 120 for y in range(2, MAZE_H-2, 2): 121 for x in range(2, MAZE_W-2, 2): 122 d = random.randint(0, 3) 123 if x > 2: # 二列目からは左に壁を作らない 124 d = random.randint(0, 2) 125 maze[y+YP[d]][x+XP[d]] = 1 126 127 # 迷路からダンジョンを作る 128 #全体を壁にする 129 for y in range(DUNGEON_H): 130 for x in range(DUNGEON_W): 131 dungeon[y][x] = 9 132 #部屋と通路の配置 133 for y in range(1, MAZE_H-1): 134 for x in range(1, MAZE_W-1): 135 dx = x*3+1 136 dy = y*3+1 137 if maze[y][x] == 0: 138 if random.randint(0, 99) < 20: # 部屋を作る 139 for ry in range(-1, 2): 140 for rx in range(-1, 2): 141 dungeon[dy+ry][dx+rx] = 0 142 else: # 通路を作る 143 dungeon[dy][dx] = 0 144 if maze[y-1][x] == 0: dungeon[dy-1][dx] = 0 145 if maze[y+1][x] == 0: dungeon[dy+1][dx] = 0 146 if maze[y][x-1] == 0: dungeon[dy][dx-1] = 0 147 if maze[y][x+1] == 0: dungeon[dy][dx+1] = 0 148 149def draw_dungeon(bg, fnt): # ダンジョンを描画する 150 bg.fill(BLACK) 151 for y in range(-4, 6): 152 for x in range(-5, 6): 153 X = (x+5)*80 154 Y = (y+4)*80 155 dx = pl_x + x 156 dy = pl_y + y 157 if 0 <= dx and dx < DUNGEON_W and 0 <= dy and dy < DUNGEON_H: 158 if dungeon[dy][dx] <= 3: 159 bg.blit(imgFloor[dungeon[dy][dx]], [X, Y]) 160 if dungeon[dy][dx] == 9: 161 bg.blit(imgWall, [X, Y-40]) 162 if dy >= 1 and dungeon[dy-1][dx] == 9: 163 bg.blit(imgWall2, [X, Y-80]) 164 if x == 0 and y == 0: # 主人公キャラの表示 165 bg.blit(imgPlayer[pl_a], [X, Y-40]) 166 bg.blit(imgDark, [0, 0]) # 四隅が暗闇の画像を重ねる 167 draw_para(bg, fnt) # 主人公の能力を表示 168 169def put_event(): # 床にイベントを配置する 170 global pl_x, pl_y, pl_d, pl_a 171 # 階段の配置 172 while True: 173 x = random.randint(3, DUNGEON_W-4) 174 y = random.randint(3, DUNGEON_H-4) 175 if(dungeon[y][x] == 0): 176 for ry in range(-1, 2): # 階段の周囲を床にする 177 for rx in range(-1, 2): 178 dungeon[y+ry][x+rx] = 0 179 dungeon[y][x] = 3 180 break 181 # 宝箱と繭の配置 182 for i in range(60): 183 x = random.randint(3, DUNGEON_W-4) 184 y = random.randint(3, DUNGEON_H-4) 185 if(dungeon[y][x] == 0): 186 dungeon[y][x] = random.choice([1,2,2,2,2]) 187 # プレイヤーの初期位置 188 while True: 189 pl_x = random.randint(3, DUNGEON_W-4) 190 pl_y = random.randint(3, DUNGEON_H-4) 191 if(dungeon[pl_y][pl_x] == 0): 192 break 193 pl_d = 1 194 pl_a = 2 195 196def move_player(key): # 主人公の移動 197 global idx, tmr, pl_x, pl_y, pl_d, pl_a, pl_life, food, potion, blazegem, treasure 198 199 if dungeon[pl_y][pl_x] == 1: # 宝箱に載った 200 dungeon[pl_y][pl_x] = 0 201 treasure = random.choice([0,0,0,1,1,1,1,1,1,2]) 202 if treasure == 0: 203 potion = potion + 1 204 if treasure == 1: 205 blazegem = blazegem + 1 206 if treasure == 2: 207 food = int(food/2) 208 idx = 3 209 tmr = 0 210 return 211 if dungeon[pl_y][pl_x] == 2: # 繭に載った 212 dungeon[pl_y][pl_x] = 0 213 r = random.randint(0, 99) 214 if r < 40: # 食料 215 treasure = random.choice([3,3,3,4]) 216 if treasure == 3: food = food + 20 217 if treasure == 4: food = food + 100 218 idx = 3 219 tmr = 0 220 else: # 敵出現 221 idx = 10 222 tmr = 0 223 return 224 if dungeon[pl_y][pl_x] == 3: # 階段に載った 225 idx = 2 226 tmr = 0 227 return 228 229 # 方向キーで上下左右に移動 230 x = pl_x 231 y = pl_y 232 if key[K_UP] == 1: 233 pl_d = 0 234 if dungeon[pl_y-1][pl_x] != 9: 235 pl_y = pl_y - 1 236 if key[K_DOWN] == 1: 237 pl_d = 1 238 if dungeon[pl_y+1][pl_x] != 9: 239 pl_y = pl_y + 1 240 if key[K_LEFT] == 1: 241 pl_d = 2 242 if dungeon[pl_y][pl_x-1] != 9: 243 pl_x = pl_x - 1 244 if key[K_RIGHT] == 1: 245 pl_d = 3 246 if dungeon[pl_y][pl_x+1] != 9: 247 pl_x = pl_x + 1 248 pl_a = pl_d*2 249 if pl_x != x or pl_y != y: # 移動したら食料の量と体力を計算 250 pl_a = pl_a + tmr%2 # 移動したら足踏みのアニメーション 251 if food > 0: 252 food = food - 1 253 if pl_life < pl_lifemax: 254 pl_life = pl_life + 1 255 else: 256 pl_life = pl_life - 5 257 if pl_life <= 0: 258 pl_life = 0 259 pygame.mixer.music.stop() 260 idx = 9 261 tmr = 0 262 263def draw_text(bg, txt, x, y, fnt, col): # 影付き文字の表示 264 sur = fnt.render(txt, True, BLACK) 265 bg.blit(sur, [x+1, y+2]) 266 sur = fnt.render(txt, True, col) 267 bg.blit(sur, [x, y]) 268 269 ### ### (中略) ### #(中略) 270 elif idx == 22: # 戦闘終了 271 pygame.mixer.music.load("sound/ohd_bgm_field.ogg") 272 pygame.mixer.music.play(-1) 273 idx = 1 274 draw_text(screen, "[S]peed "+str(speed), 740, 40, fontS, WHITE) 275 pygame.display.update() 276 clock.tick(4+2*speed) 277if __name__ == '__main__': 278 main()
文字数制限があるため途中を省略しました。いろいろやり方があるのかもしれませんが初心者なのでできれば比較的簡単なやり方が知りたいです。どうぞよろしくお願いします。