sdim mapstr,36,32 dim tmp,32,32 map_x=32:map_y=20 mapstr. 0="11111111111111111111111111111111" mapstr. 1="11100000000000000000000000000111" mapstr. 2="10000000110111000000000000000001" mapstr. 3="10000000000000000000000000000001" mapstr. 4="10000000110111000000000000000001" mapstr. 5="10000001000000000000000000000001" mapstr. 6="10000000000000000111000000000001" mapstr. 7="10000000011000001001000000000001" mapstr. 8="10000000001000001000000000000001" mapstr. 9="10000000000000001001000000001001" mapstr.10="10000000000000000001000000011111" mapstr.11="11000000000000000001000000001111" mapstr.12="11100000000000000000000000000011" mapstr.13="10000000000000000111100000000001" mapstr.14="10000000000000011111111100000001" mapstr.15="11111111111100111111111110000011" mapstr.16="10000000000000000011111110000001" mapstr.17="10000000000000000000111100000001" mapstr.18="10000000000000000000000000000001" mapstr.19="11111111111111111111111111111111" screen 0,map_x*16,map_y*16 title "移動範囲制限サンプル  クリックで移動" cls 4 xx=8:yy=8 ;初期位置 limit=6 ;移動可能距離 repeat ;メインループ? wait 1 gosub *check redraw 0 gosub *draw redraw 1 stick k if k&256 { ;クリックで移動 x=mousex/16 y=mousey/16 peek c,mapstr.y,x if c!='1' & (tmp.x.y>0):xx=x:yy=y } loop end *draw ;表示 repeat map_y y=cnt repeat map_x x=cnt if tmp.x.y { ;//領域内かどうか color 200,200,255 ;OK }else{ color 200,200,200 ;NG } if x=xx & (y=yy) :color 255,0,0 peek c,mapstr.y,x if c=='1' :color 0,0,255 boxf x*16,y*16,x*16+14,y*16+14 color 0,0,0:pos x*16,y*16:mes tmp.x.y ;確認用 loop loop return *check ;移動可能領域を調べる ;チェックする範囲 stx=xx-limit:edx=xx+limit if stx<1 :stx=1 if edx>=map_x :edx=map_x-1 sty=yy-limit:edy=yy+limit if sty<1 :sty=1 if edy>=map_y :edy=map_y-1 memset tmp,0,map_x*map_y*4 tmp.xx.yy=limit *chk_loop f=0 repeat edy-sty,sty y=cnt repeat edx-stx,stx x=cnt:mx=0 peek c,mapstr.y,x if c=='1' :continue t=y-1 if tmp.x.t>mx :mx=tmp.x.t t=x-1 if tmp.t.y>mx :mx=tmp.t.y t=x+1 if tmp.t.y>mx :mx=tmp.t.y t=y+1 if tmp.x.t>mx :mx=tmp.x.t if mx-1>tmp.x.y :tmp.x.y=mx-1:f=1 loop loop if f :goto *chk_loop return