前回はスライドパズルの基本部分を作成しました。 今回は前回のものに手を加えていき、よりゲームらしくしてみましょう。 まずは、前回3×3マスの1面だけだったものを、 3×3マス、4×3マス、4×4マスの合計3面を1つのゲームとしたステージ制の導入方法から説明します。
1 2 3 4 5 6 7 8 |
#define SX (ginfo_winx / numx.stage) // ステージ毎の1マスの横幅 #define SY (ginfo_winy / numy.stage) // ステージ毎の1マスの高さ numx = 3, 4, 4 // 第1ステージ、第2ステージ、第3ステージの横マス個数 numy = 3, 3, 4 // 第1ステージ、第2ステージ、第3ステージの縦マス個数 randomize gosub *game_start end |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
*game_start stage = 0 // 現在のステージを初期化 foreach numx space = 0 clear = 0 gosub *draw_tips gosub *shuffle gosub *draw_map gosub *game_main // ステージ毎のループ gosub *game_clear // ステージ毎のクリア処理 loop dialog "Stages All Clear !\n\nThank you for Playing." return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
*draw_tips buffer 1, ginfo_winx, ginfo_winy color 150, 255, 100 : boxf : color , , 255 font msmincho, SY, 1 repeat numx.stage * numy.stage pos cnt \ numx.stage * SX + (SX - SY) / 2, cnt / numx.stage * SY : mes strf("%02d", cnt + 1) loop buffer 2, ginfo_winx, ginfo_winy gcopy 1, , , ginfo_winx, ginfo_winy color 255 repeat numx.stage + 1 boxf cnt * SX - 2, -1, cnt * SX + 1, ginfo_winy loop repeat numy.stage + 1 boxf -1, cnt * SY - 2, ginfo_winx, cnt * SY + 1 loop gsel 0 return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
*shuffle dim tip, numx.stage * numy.stage repeat numx.stage * numy.stage : tip.cnt = cnt : loop repeat length(tip) * length(tip) i = space, rnd(4) if i.1 = 0 : if space \ numx.stage = 0 : continue : else : space-- if i.1 = 1 : if space / numx.stage = 0 : continue : else : space -= numx.stage if i.1 = 2 : if space \ numx.stage = numx.stage - 1 : continue : else : space++ if i.1 = 3 : if space / numx.stage = numy.stage - 1 : continue : else : space += numx.stage tip.space = tip.space ^ tip.i tip.i = tip.space ^ tip.i tip.space = tip.space ^ tip.i loop return |
1 2 3 4 5 6 7 8 9 10 |
*draw_map redraw 0 color 255, 255, 255 : boxf repeat numx.stage * numy.stage if cnt = space : continue pos cnt \ numx.stage * SX, cnt / numx.stage * SY gcopy 2, tip.cnt \ numx.stage * SX, tip.cnt / numx.stage * SY, SX, SY loop redraw 1 return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
*game_main repeat wait 1 stick key if key & 256 { i.0 = mousex / SX + mousey / SY * numx.stage i.1 = (i - 1 = space) & (i \ numx.stage ! 0) i.2 = (i - numx.stage = space) & (i / numx.stage ! 0) i.3 = (i + 1 = space) & (i \ numx ! numx.stage - 1) i.4 = (i + numx.stage = space) & (i / numx.stage ! numy.stage - 1) if i.1 | i.2 | i.3 | i.4 { tip.space = tip.space ^ tip.i tip.i = tip.space ^ tip.i tip.space = tip.space ^ tip.i space = i gosub *draw_map gosub *clear_check if clear : break } } loop return |
1 2 3 4 5 6 |
*clear_check clear = 1 repeat numx.stage * numy.stage if tip.cnt ! cnt : clear = 0 : break loop return |
1 2 3 4 5 6 7 8 9 10 11 |
*game_clear repeat 8, 1 wait 10 gmode 3, SX, SY, cnt * 32 pos space \ numx.stage * SX, space / numx.stage * SY gcopy 2, tip.space \ numx.stage * SX, tip.space / numx.stage * SY loop pos 0, 0 : gcopy 1, , , ginfo_winx, ginfo_winy dialog "Game Clear !" stage++ // ステージを先に進める return |
1 2 3 4 5 6 7 8 9 10 |
#define NAME "Slide Pazzle" // タイトル名 #define SX (ginfo_winx / numx.stage) #define SY (ginfo_winy / numy.stage) numx = 3, 4, 4 numy = 3, 3, 4 item = "Game Start", "Exit" // メニュー項目 randomize gosub *menu end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
*menu index = 0 // 選択項目番号 gosub *draw_menu repeat wait 5 stick key if key & 2 : index-- : if index < 0 : index = length(item) - 1 // 上へ if key & 8 : index++ : if index >= length(item) : index = 0 // 下へ if key & 10 : gosub *draw_menu // 上or下キーなら再描画 // 決定ボタンはエンターキー if key & 32 { switch index // Game Start case 0: gosub *game_start gosub *draw_menu swbreak // Exit default: break swend } loop return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
*draw_menu // タイトル描画 title NAME redraw 0 color 255, 200, 255 : boxf : color , 200 font msmincho, 64, 1 pos , -100 : mes NAME // 横幅取得用の配置 pos (ginfo_winx - ginfo_mesx) / 2, 30 : mes NAME // 選択項目描画 font msmincho, 40, 1 foreach item color (index = cnt) * 200, 100, (index ! cnt) * 200 pos , -100 : mes item.cnt // 横幅取得用の配置 pos (ginfo_winx - ginfo_mesx) / 2, (ginfo_winy - 230) / length(item) * cnt + 200 : mes item.cnt loop redraw 1 return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
*game_start stage = 0 foreach numx space = 0 clear = 0 moved = 0, 0 // 0:制限手数, 1:手数 gosub *draw_tips gosub *shuffle gosub *draw_map gosub *game_main gosub *game_clear if clear = 2 : continue cnt // ゲームオーバー時はもう1回 loop dialog "Stages All Clear !\n\nThank you for Playing." return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
*shuffle dim tip, numx.stage * numy.stage repeat numx.stage * numy.stage : tip.cnt = cnt : loop repeat length(tip) * length(tip) i = space, rnd(4) if i.1 = 0 : if space \ numx.stage = 0 : continue : else : space-- if i.1 = 1 : if space / numx.stage = 0 : continue : else : space -= numx.stage if i.1 = 2 : if space \ numx.stage = numx.stage - 1 : continue : else : space++ if i.1 = 3 : if space / numx.stage = numy.stage - 1 : continue : else : space += numx.stage tip.space = tip.space ^ tip.i tip.i = tip.space ^ tip.i tip.space = tip.space ^ tip.i moved++ loop moved = moved / 10 * 20 // 制限手数を適度に緩和 return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
*game_main title strf("%s (残り:%d)", NAME, moved - moved.1) repeat wait 1 stick key if key & 256 { i.0 = mousex / SX + mousey / SY * numx.stage i.1 = (i - 1 = space) & (i \ numx.stage ! 0) i.2 = (i - numx.stage = space) & (i / numx.stage ! 0) i.3 = (i + 1 = space) & (i \ numx ! numx.stage - 1) i.4 = (i + numx.stage = space) & (i / numx.stage ! numy.stage - 1) if i.1 | i.2 | i.3 | i.4 { tip.space = tip.space ^ tip.i tip.i = tip.space ^ tip.i tip.space = tip.space ^ tip.i space = i moved.1++ title strf("%s (残り:%d, 手数:%d)", NAME, moved - moved.1, moved.1) gosub *draw_map gosub *clear_check if clear : break } } loop return |
1 2 3 4 5 6 7 |
*clear_check clear = 1 repeat numx.stage * numy.stage if tip.cnt ! cnt : clear = 0 : break loop if moved.1 >= moved : clear = 2 // 制限手数に達したらクリア失敗 return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
*game_clear if clear = 1 { repeat 8, 1 wait 10 gmode 3, SX, SY, cnt * 32 pos space \ numx.stage * SX, space / numx.stage * SY gcopy 2, tip.space \ numx.stage * SX, tip.space / numx.stage * SY loop pos 0, 0 : gcopy 1, , , ginfo_winx, ginfo_winy dialog "Game Clear !" stage++ } else { dialog "Game Failed..." } return |