今回は上図の通り、外壁を含んだ障害物の設置、ステージ及びキャラクタの情報表示、 見た目ではわかりませんが、キー反応感度の上昇等の機能改善を行います。 まずはキー反応感度を良くする部分から変えて行きます。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
*main repeat 10, 1 stick key if key & 5 : await (10 - cnt) * 10 : break : else : await 10 loop redraw 0 gosub *move_char gosub *hantei gosub *draw_back gosub *draw_item gosub *draw_char redraw 1 goto *main |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
*move_char if posx = itemx & posy = itemy { dir(len) = dir(len - 1) posx(len) = posx(len - 1) posy(len) = posy(len - 1) len++ item = 0 } repeat len - 1 dir(len - cnt - 1) = dir(len - cnt - 2) posx(len - cnt - 1) = posx(len - cnt - 2) posy(len - cnt - 1) = posy(len - cnt - 2) loop // stick key, 5 if key & 1 : dir = dir / 2 + (dir <= 1) * 8 if key & 4 : dir = dir * 2 - (dir >= 8) * 15 posx += (dir = 4) - (dir = 1) posy += (dir = 8) - (dir = 2) 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 |
*init size = 20 // マスサイズ縮小 map = ginfo_winx / size, ginfo_winy / size dim tip, map * map.1 repeat map * 2 tip((cnt \ map) + cnt / map * (map * map.1 - map)) = 1 // 上下端は外壁 loop repeat map.1 * 2 tip(cnt \ map.1 * map + cnt / map.1 * (map - 1)) = 1 // 左右端は外壁 loop repeat 16 tip(((map.1 - 4) / 2 + cnt / 4) * map + (map - 4) / 2 + cnt \ 4) = 1 // 中央に内壁 loop gosub *draw_tips // 上記壁情報を元に全マスを描画する len = 5 item = 0 dim dir, len dim posx, len dim posy, len repeat len dir.cnt = 4 posx.cnt = 6 - cnt posy.cnt = 2 loop return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
*draw_tips buffer 1 // とりあえず全マス通行可能な下地で塗りつぶす color 255, 200, 200 boxf , , map * size, map.1 * size // 個別に通行不可能マスを塗りなおしていく color 100 repeat map * map.1 if tip.cnt = 1 { i = cnt \ map * size, cnt / map * size boxf i.0, i.1, i.0 + size - 1, i.1 + size - 1 } loop gsel 0 return |
1 2 3 |
*draw_back pos 0, 0 : gcopy 1, , , map * size, map.1 * size // マップ画像をコピーするだけ 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 26 27 28 29 30 31 32 33 34 35 36 37 |
*hantei if tip(posy * map + posx) = 1 { i = -1 } else { repeat len - 1 i = cnt repeat len - i - 1, i + 1 if posx.i = posx.cnt & posy.i = posy.cnt { i = -2 break } loop if i = -2 : break loop } if i < 0 { life-- if i = -1 : s = "壁" : else : s = "自分" if life { dialog "長さ" + len + "で" + s + "に激突!", 1, "残り" + life + "回で終了です" gosub *init } else { dialog "長さ" + len + "で" + s + "に激突!\nやり直しますか?", 2, "ゲームオーバー" if stat = 6 : gosub *start : else : end } } if len >= mission.stage { stage++ if stage >= length(mission) { dialog "長さ" + mission(stage - 1) + "達成おめでとう", , "ゲームクリア!" end } else { dialog "長さ" + mission(stage - 1) + "達成です", , "ステージ" + stage + "クリア" gosub *init } } return |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
*draw_item if item = 0 { repeat 1 itemx = rnd(map.0) itemy = rnd(map.1) if tip(itemy * map + itemx) : continue cnt loop item = 1 } color 200, 255, 255 i = itemx * size, itemy * size boxf i.0, i.1, i.0 + size - 1, i.1 + size - 1 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
*hantei // ゴールを通過してないなら衝突チェック if len >= 0 { if tip(posy * map + posx) = 1 { i = -1 } else { repeat len - (len ! 0) i = cnt repeat len - i - 1, i + 1 if posx.i = posx.cnt & posy.i = posy.cnt { i = -2 break } loop if i = -2 : break loop } if i < 0 { life-- if i = -1 : s = "壁" : else : s = "自分" if life { dialog "長さ" + len + "で" + s + "に激突!", 1, "残り" + life + "回で終了です" gosub *init } else { dialog "長さ" + len + "で" + s + "に激突!\nやり直しますか?", 2, "ゲームオーバー" if stat = 6 : gosub *start : else : end } } // まだゴールに穴を開けてないなら開ける if len >= mission.stage & clear = 0 { clear = 1 tip(map / 2 - 1) = 2 tip(map / 2 - 0) = 2 gosub *draw_tips } } else { stage++ if stage >= length(mission) { dialog "長さ" + mission(stage - 1) + "達成おめでとう", , "ゲームクリア!" end } else { dialog "長さ" + mission(stage - 1) + "達成です", , "ステージ" + stage + "クリア" gosub *init } } 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 26 |
*init size = 20 clear = 0 map = ginfo_winx / size, ginfo_winy / size dim tip, map * map.1 repeat map * 2 tip((cnt \ map) + cnt / map * (map * map.1 - map)) = 1 loop repeat map.1 * 2 tip(cnt \ map.1 * map + cnt / map.1 * (map - 1)) = 1 loop repeat map.1 * 2 tip(cnt \ map.1 * map + cnt / map.1 * (map - 1)) = 1 loop gosub *draw_tips len = 5 item = 0 dim dir, len dim posx, len dim posy, len repeat len dir.cnt = 4 posx.cnt = 6 - cnt posy.cnt = 6 loop return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
*move_char if posx = itemx & posy = itemy { dir(len) = dir(len - 1) posx(len) = posx(len - 1) posy(len) = posy(len - 1) len++ item = 0 } if tip(posy * map + posx) ! 2 { repeat len - 1 dir(len - cnt - 1) = dir(len - cnt - 2) posx(len - cnt - 1) = posx(len - cnt - 2) posy(len - cnt - 1) = posy(len - cnt - 2) loop if key & 1 : dir = dir / 2 + (dir <= 1) * 8 if key & 4 : dir = dir * 2 - (dir >= 8) * 15 posx += (dir = 4) - (dir = 1) posy += (dir = 8) - (dir = 2) } else { len-- // 1ターン毎に短くしていく(クリアゲートを通っているように見える) } 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 26 27 28 29 |
*init size = 20 clear = 0 map = (ginfo_winx - infosize) / size, ginfo_winy / size dim tip, map * map.1 repeat map * 2 tip((cnt \ map) + cnt / map * (map * map.1 - map)) = 1 loop repeat map.1 * 2 tip(cnt \ map.1 * map + cnt / map.1 * (map - 1)) = 1 loop repeat map.1 * 2 tip(cnt \ map.1 * map + cnt / map.1 * (map - 1)) = 1 loop repeat 16 tip(((map.1 - 4) / 2 + cnt / 4) * map + (map - 4) / 2 + cnt \ 4) = 1 loop gosub *draw_tips len = 5 item = 0 dim dir, len dim posx, len dim posy, len repeat len dir.cnt = 4 posx.cnt = 6 - cnt posy.cnt = 6 loop return |
1 2 3 4 5 6 7 8 9 |
*start randomize stage = 0 life = 3 mission = 30, 40, 60 infosize = 200 // 情報表示エリア幅を定義 font msmincho, 32, 1 // 情報表示文字のサイズを設定 gosub *init return |
1 2 3 4 5 6 7 8 |
*draw_back pos 0, 0 : gcopy 1, , , map * size, map.1 * size color 255, 255, 200 : boxf ginfo_winx - infosize : color pos ginfo_winx - infosize + 10 pos , 10 : mes "ステージ" + strf("%3d", stage + 1) pos , 50 : mes "ライフ" + strf("%5d", life) pos , 90 : mes "体長" + strf("%7d", len) return |