|
 |
|
2017/7/18(Tue) 22:59:56|NO.80657
いまのままだと、敵が右か下に動いたときに、@までひとっ跳びできてしまいます。理由はcntだってわかったんですけど、自分じゃ解消できません。教えてくれる人いませんか。
//近づいてくる敵
enemy_counter1++
if enemy_counter1 = 50 {
repeat 縦
ct = cnt
repeat 横
if masu(cnt,ct)="%"{;もしその座標に敵がいるなら
//敵が@から10マス以内にいるとき
if (mariox/16 - cnt)<10 | (cnt - mariox/16)<10 | (marioy/16 - ct)<10 | (ct - marioy/16)<10 {
if mariox/16 > cnt {//敵が@の左にいる つまり 敵は右に進む
if cnt+1>横:goto *hata1
if masu(cnt+1,ct)!="":goto *hata1;障害物がある場合移動しない
masu(cnt+1,ct)=masu(cnt,ct);左に移動
masu(cnt,ct)="";もといた場所を消す
}
if cnt > mariox/16 {//敵が@の右にいる つまり 敵は左に進む
if cnt-1<0:goto *hata1
if masu(cnt-1,ct)!="":goto *hata1;障害物がある場合移動しない
masu(cnt-1,ct)=masu(cnt,ct);左に移動
masu(cnt,ct)="";もといた場所を消す
}
if marioy/16 > ct {//敵が@の上にいる つまり 敵は下に進む
if ct+1>縦:goto *hata1
if masu(cnt,ct+1)!="":goto *hata1
masu(cnt,ct+1)=masu(cnt,ct);下に移動
masu(cnt,ct)="";もといた場所を消す
}
if ct > marioy/16 {//敵が@の下にいる つまり 敵は上に進む
if ct-1<0:goto *hata1
if masu(cnt,ct-1)!="":goto *hata1
masu(cnt,ct-1)=masu(cnt,ct);上に移動
masu(cnt,ct)="";もといた場所を消す
}
}
}
*hata1
loop
loop
enemy_counter1 = 0
}

| |
|
2017/7/19(Wed) 01:11:38|NO.80659
「二重ループを使って敵の位置をサーチし、見つけ次第移動させる」、
という処理を行っていますが、次のループで移動先がまたサーチに引っかかってしまい、
「見つける→移動させる→見つける→移動させる→……」という処理を、
条件を満たさなくなるまで何度も繰り返してしまっているようです。
敵を見つけたら、ループを脱出させるようにしてみます。
プログラムの全貌がわからないのでテストはできませんが、これでどうでしょうか?
//近づいてくる敵
enemy_counter1++
if enemy_counter1 = 50 {
flag=0 //ループ脱出時に立てるフラグ
repeat 縦
ct = cnt
repeat 横
if masu(cnt,ct)="%"{;もしその座標に敵がいるなら
//敵が@から10マス以内にいるとき
if (mariox/16 - cnt)<10 | (cnt - mariox/16)<10 | (marioy/16 - ct)<10 | (ct - marioy/16)<10 {
if mariox/16 > cnt {//敵が@の左にいる つまり 敵は右に進む
if cnt+1>横: continue
if masu(cnt+1,ct)!="":goto *hata1;障害物がある場合移動しない
masu(cnt+1,ct)=masu(cnt,ct);左に移動
masu(cnt,ct)="";もといた場所を消す
flag=1 : break
}
if cnt > mariox/16 {//敵が@の右にいる つまり 敵は左に進む
if cnt-1<0: continue
if masu(cnt-1,ct)!="":goto *hata1;障害物がある場合移動しない
masu(cnt-1,ct)=masu(cnt,ct);左に移動
masu(cnt,ct)="";もといた場所を消す
flag=1 : break
}
if marioy/16 > ct {//敵が@の上にいる つまり 敵は下に進む
if ct+1>縦: continue
if masu(cnt,ct+1)!="":goto *hata1
masu(cnt,ct+1)=masu(cnt,ct);下に移動
masu(cnt,ct)="";もといた場所を消す
flag=1 : break
}
if ct > marioy/16 {//敵が@の下にいる つまり 敵は上に進む
if ct-1<0: continue
if masu(cnt,ct-1)!="":goto *hata1
masu(cnt,ct-1)=masu(cnt,ct);上に移動
masu(cnt,ct)="";もといた場所を消す
flag=1 : break
}
}
}
loop
if flag : break
loop
enemy_counter1 = 0
}
(個人的に、敵を動かす必要が出てくるたびにいちいちサーチするのではなく、
敵の座標をあらわす変数を用意して、それを基準に処理を行った方がいいと思う)

| |
|
2017/7/19(Wed) 01:13:08|NO.80660
全体です。問題の場所は182行からあります。最初に空のメモ帳を読み込むと動きます。
//mario editor を作ります。
広さ = 3 //ワールドの広さ
screen 0,640*広さ,640*広さ,0,0,0,640,640
mariox = 320 : marioy = 320 : jump_sw = 0 :横=40*広さ : 縦=40*広さ : sdim masu,10,横,縦
sdim baggage,10,10 : sdim 数字,10,10 : sdim block,10 :PosX = 320 : PosY = 320:groll PosX,PosY
baggage(0)="0"
baggage(1)="1"
baggage(2)="2"
//メモ帳をバッファに読み込む
dialog "txt",16,"テキストファイル"
if stat = 0 : end
sdim buf,2,横,縦;メモ帳から読み込むためのバッファ
notesel buf : noteload refstr
//ここまででテキストファイルからbufに内容を読み込めた
//bufの内容をmasu(x,y)に読み込んでいく
count=0 : repeat 縦 : ct=cnt : repeat 横 : noteget masu(cnt,ct),count : count++ : loop : loop
await 10
*main
redraw 0
color 0,0,0 : boxf//画面初期化
color 255,255,255
line ((640*広さ)-320)+16,320,320,320 :line ((640*広さ)-320)+16,((640*広さ)-320)+16,((640*広さ)-320)+16,320
line 320,((640*広さ)-320)+16,((640*広さ)-320)+16,((640*広さ)-320)+16:line 320,320,320,((640*広さ)-320)+16
//移動 入力受付 以下
stick key, 15 + 256 + 512
if ((key&1)!0)&(PosX > 0) : PosX-- : groll PosX,PosY
if ((key&2)!0)&(PosY > 0) :PosY-- :groll PosX,PosY
if ((key&4)!0)&(PosX < 1280) : PosX++ : groll PosX,PosY
if ((key&8)!0)&(PosY < 1280) : PosY++ : groll PosX,PosY
mariox = PosX + 320 //プレイヤーの中央座標の更新
marioy = PosY + 320 // 〃
title "BGX : "+ginfo(8)+" / BGY : "+ginfo(9)+"
pos mariox,marioy : mes "@"//マリオの場所
//マップを自分から距離20まで表示
repeat 40,(marioy/16)-20
ct = cnt
repeat 40,(mariox/16)-20
pos 16*cnt,16*ct
mes masu(cnt,ct)
loop
loop
//衝突判定 以下
箱のサイズ=14
repeat 縦
ct = cnt
repeat 横
if masu(cnt,ct) = "□" || masu(cnt,ct) = "壁"{//そこにブロックがあるとき
//右から当たる場合
if (marioy >= 16*(ct)-箱のサイズ) && (marioy <= 16*(ct)+箱のサイズ){
if mariox == 16*(cnt)+箱のサイズ : PosX++
}
//左から当たる場合
if (marioy >= 16*(ct)-箱のサイズ) && (marioy <= 16*(ct)+箱のサイズ){
if mariox == 16*(cnt)-箱のサイズ : PosX--
}
//上から当たる場合
if (mariox >= 16*(cnt)-箱のサイズ) && (mariox <= 16*(cnt)+箱のサイズ){
if marioy == 16*(ct)-箱のサイズ : PosY--
}
//下から当たる場合
if (mariox >= 16*(cnt)-箱のサイズ) && (mariox <= 16*(cnt)+箱のサイズ){
if marioy == 16*(ct)+箱のサイズ : PosY++
}
}
loop
loop
//自分から3マスまで置いたり消したりできる
if (((mousex+PosX)/16) <= (mariox/16)+3) && (((mousex+PosX)/16) >= (mariox/16)-3) && (((mousey+PosY)/16) <= (marioy/16)+3) && (((mousey+PosY)/16) >= (marioy/16)-3){
//マウスで座標を選ぶ
pos ((mousex+PosX)/16)*16,((mousey+PosY)/16)*16
if block_count = 0 : mes "[]"
if block_count = 1 : mes "壁"
if block_count = 2 : mes "□"
if block_count = 3 : mes "&"
if block_count = 4 : mes "移"
if block_count = 5 : mes "飛"
if block_count = 6 : mes "%"
if key & 512 {
masu(((mousex+PosX)/16),((mousey+PosY)/16))=block
}
}
//アイテムを拾う
getkey grab, 71: if grab{
repeat 10:poke 数字.cnt,0,48+cnt : loop
repeat 10
if masu(mariox/16,marioy/16)=数字(cnt) {
repeat 10
if baggage(cnt)=""{//スペースがあるなら
baggage(cnt)=masu(mariox/16,marioy/16)
goto *spaceari//スペースが見つかった時点でループから抜け出す
}
if cnt = 9 : goto *nospace//スペースがなかったらアイテムをフィールドから消さない
loop
}
if hairanai=1{
*spaceari
masu((mariox/16),(marioy/16))=""//拾ったアイテムをフィールドから消す
*nospace
break
}
loop
}
//アイテムを落とす
getkey drop, 68: if drop{
*dropitem
redraw 0
color 0,0,0 : boxf//画面初期化
color 255,255,255
repeat 10: pos PosX+16,(16*cnt)+PosY : mes baggage(cnt) : loop
pos PosX,(16*dropitem_y)+PosY : mes "→"
stick key
if key = 2 : dropitem_y--
if key = 8 : dropitem_y++
if dropitem_y<0 : dropitem_y++
if dropitem_y>9 : dropitem_y--
if key = 32{
if baggage(dropitem_y) != ""{
if masu((mariox/16),(marioy/16)) = ""{//今立ってる場所に何もないなら
masu((mariox/16),(marioy/16)) = baggage(dropitem_y)
baggage(dropitem_y) = ""
}
//今立ってる場所に何かがあるならなにもしない
}
}
getkey close, 27: if close:goto *main
redraw 1
await 10
goto *dropitem
}
//かばんの中のアイテムを見る
getkey item, 88: if item{
*watchitem
redraw 0
color 0,0,0 : boxf//画面初期化
color 255,255,255
repeat 10: pos PosX+16,(16*cnt)+PosY : mes baggage(cnt) : loop
getkey close, 27: if close:goto *main
redraw 1
await 10
goto *watchitem
}
//置くブロックを変える
getkey change_block, 67: if change_block : keyb++ : else : keyb=0
if keyb = 1 {
block_count++
if block_count = 0 : block = ""
if block_count = 1 : block = "壁"
if block_count = 2 : block = "□"
if block_count = 3 : block = "&"
if block_count = 4 : block = "移"
if block_count = 5 : block = "飛"
if block_count = 6 : block = "%"
if block_count = 7 : block_count = 0 : block = ""
}
//近づいてくる敵
enemy_counter1++
if enemy_counter1 = 50 {
repeat 縦
ct = cnt
repeat 横
if masu(cnt,ct)="%"{;もしその座標に敵がいるなら
//敵が@から10マス以内にいるとき
if (mariox/16 - cnt)<10 | (cnt - mariox/16)<10 | (marioy/16 - ct)<10 | (ct - marioy/16)<10 {
if mariox/16 > cnt {//敵が@の左にいる つまり 敵は右に進む
if cnt+1>横:goto *hata1
if masu(cnt+1,ct)!="":goto *hata1;障害物がある場合移動しない
masu(cnt+1,ct)=masu(cnt,ct);左に移動
masu(cnt,ct)="";もといた場所を消す
}
if cnt > mariox/16 {//敵が@の右にいる つまり 敵は左に進む
if cnt-1<0:goto *hata1
if masu(cnt-1,ct)!="":goto *hata1;障害物がある場合移動しない
masu(cnt-1,ct)=masu(cnt,ct);左に移動
masu(cnt,ct)="";もといた場所を消す
}
if marioy/16 > ct {//敵が@の上にいる つまり 敵は下に進む
if ct+1>縦:goto *hata1
if masu(cnt,ct+1)!="":goto *hata1
masu(cnt,ct+1)=masu(cnt,ct);下に移動
masu(cnt,ct)="";もといた場所を消す
}
if ct > marioy/16 {//敵が@の下にいる つまり 敵は上に進む
if ct-1<0:goto *hata1
if masu(cnt,ct-1)!="":goto *hata1
masu(cnt,ct-1)=masu(cnt,ct);上に移動
masu(cnt,ct)="";もといた場所を消す
}
}
}
*hata1
loop
loop
enemy_counter1 = 0
}
//ランダムに動く敵
enemy_counter++
if enemy_counter = 50 {
repeat 縦
ct = cnt
repeat 横
if masu(cnt,ct)="&"{;もしその座標に敵がいるなら
direction_teki = rnd(4)
if direction_teki = 0{;左
if cnt-1<0: goto *hata2
if masu(cnt-1,ct)!="":goto *hata2;障害物がある場合移動しない
masu(cnt-1,ct)=masu(cnt,ct);左に移動
masu(cnt,ct)="";もといた場所を消す
}
if direction_teki = 1{;上
if ct-1<0:goto *hata2
if masu(cnt,ct-1)!="":goto *hata2
masu(cnt,ct-1)=masu(cnt,ct);上に移動
masu(cnt,ct)="";もといた場所を消す
}
if direction_teki = 2{;右
if cnt+1>39:goto *hata2
if masu(cnt+1,ct)!="":goto *hata2
masu(cnt+1,ct)=masu(cnt,ct);右に移動
masu(cnt,ct)="";もといた場所を消す
}
if direction_teki = 3{;下
if ct+1>39:goto *hata2
if masu(cnt,ct+1)!="":goto *hata2
masu(cnt,ct+1)=masu(cnt,ct);下に移動
masu(cnt,ct)="";もといた場所を消す
}
}
*hata2
loop
loop
enemy_counter = 0
}
//移ブロックに触るとマップを移動する
if masu(mariox/16,marioy/16)="移"{
notesel buf
noteload "map2.txt"
count_note=0
repeat 縦
ct=cnt
repeat 横
noteget masu(cnt,ct),count_note
count_note++
loop
loop
goto *main
}
//飛ブロックに触るとワールドマップに移動する
if masu(mariox/16,marioy/16)="飛" : goto *worldmap
onexit goto *save
redraw 1
await 10
goto *main
*save
notesel buf
count=0
repeat 縦
ct=cnt
repeat 横
noteadd masu(cnt,ct),count,1
count++
loop
loop
dialog "txt",16,"テキストファイル"
if stat = 0 : end
notesave refstr
end
*worldmap
redraw 0
color 0,0,0:boxf
color 255,255,255
line
redraw 1
await 10
goto *worldmap

| |
|
2017/7/19(Wed) 01:13:50|NO.80661
すみません、ラベルの消し漏れがありました。
こちらに置き換えてください。
//近づいてくる敵
enemy_counter1++
if enemy_counter1 = 50 {
flag=0 //ループ脱出時に立てるフラグ
repeat 縦
ct = cnt
repeat 横
if masu(cnt,ct)="%"{;もしその座標に敵がいるなら
//敵が@から10マス以内にいるとき
if (mariox/16 - cnt)<10 | (cnt - mariox/16)<10 | (marioy/16 - ct)<10 | (ct - marioy/16)<10 {
if mariox/16 > cnt {//敵が@の左にいる つまり 敵は右に進む
if cnt+1>横: continue
if masu(cnt+1,ct)!="": continue ;障害物がある場合移動しない
masu(cnt+1,ct)=masu(cnt,ct);左に移動
masu(cnt,ct)="";もといた場所を消す
flag=1 : break
}
if cnt > mariox/16 {//敵が@の右にいる つまり 敵は左に進む
if cnt-1<0: continue
if masu(cnt-1,ct)!="": continue ;障害物がある場合移動しない
masu(cnt-1,ct)=masu(cnt,ct);左に移動
masu(cnt,ct)="";もといた場所を消す
flag=1 : break
}
if marioy/16 > ct {//敵が@の上にいる つまり 敵は下に進む
if ct+1>縦: continue
if masu(cnt,ct+1)!="": continue
masu(cnt,ct+1)=masu(cnt,ct);下に移動
masu(cnt,ct)="";もといた場所を消す
flag=1 : break
}
if ct > marioy/16 {//敵が@の下にいる つまり 敵は上に進む
if ct-1<0: continue
if masu(cnt,ct-1)!="": continue
masu(cnt,ct-1)=masu(cnt,ct);上に移動
masu(cnt,ct)="";もといた場所を消す
flag=1 : break
}
}
}
loop
if flag : break
loop
enemy_counter1 = 0
}

| |
|
2017/7/19(Wed) 01:37:03|NO.80662
おお、回答ありがとうございます。参考にしていろいろためしてみます。
ちなみにプログラムは、
最初に空のメモ帳を読み込む必要がある
十字キーで@が動く
キーボードのCで置くブロックや敵を選べる(&と%は敵)
&を追いかけてくる敵にしたい
@の周囲3マスはマウスの右クリックでブロックと敵を置ける
ブロックは@や敵に対してあたり判定がある
|
|
2017/7/19(Wed) 02:01:13|NO.80663
追いかけてくる敵は&じゃなくて%でした。&はランダムに動く敵です。
|
|
2017/7/19(Wed) 08:23:03|NO.80664
アドバイスを参考にとりあえずまともに動くようになりました。まだたまに、2マスジャンプしたりします。敵を大量に表示してもちゃんと動いてくれます。
プログラムの書き方など、こうするともっといいよとかあったらおしえてください。
//mario editor を作ります。
広さ = 3 //ワールドの広さ
screen 0,640*広さ,640*広さ,0,0,0,640,640
mariox = 320 : marioy = 320 : jump_sw = 0 :横=40*広さ : 縦=40*広さ : sdim masu,10,横,縦 : dim enemyx,100 : dim enemyy,100 : enemy_num=0
sdim baggage,10,10 : sdim 数字,10,10 : sdim block,10 :PosX = 320 : PosY = 320:groll PosX,PosY
//敵座標すべてに-1をいれる 敵がいないということ
repeat 100
ct=cnt
repeat 100
enemyx(cnt) = -1
enemyy(ct) = -1
loop
loop
baggage(0)="0"
baggage(1)="1"
baggage(2)="2"
//メモ帳をバッファに読み込む
dialog "txt",16,"テキストファイル"
if stat = 0 : end
sdim buf,2,横,縦;メモ帳から読み込むためのバッファ
notesel buf : noteload refstr
//ここまででテキストファイルからbufに内容を読み込めた
//bufの内容をmasu(x,y)に読み込んでいく
count=0 : repeat 縦 : ct=cnt : repeat 横 : noteget masu(cnt,ct),count : count++ : loop : loop
await 10
*main
redraw 0
color 0,0,0 : boxf//画面初期化
color 255,255,255
line ((640*広さ)-320)+16,320,320,320 :line ((640*広さ)-320)+16,((640*広さ)-320)+16,((640*広さ)-320)+16,320
line 320,((640*広さ)-320)+16,((640*広さ)-320)+16,((640*広さ)-320)+16:line 320,320,320,((640*広さ)-320)+16
//移動 入力受付 以下
stick key, 15
if ((key&1)!0)&(PosX > 0) : PosX-- : groll PosX,PosY
if ((key&2)!0)&(PosY > 0) :PosY-- :groll PosX,PosY
if ((key&4)!0)&(PosX < 1280) : PosX++ : groll PosX,PosY
if ((key&8)!0)&(PosY < 1280) : PosY++ : groll PosX,PosY
mariox = PosX + 320 //プレイヤーの中央座標の更新
marioy = PosY + 320 // 〃
title "BGX : "+ginfo(8)+" / BGY : "+ginfo(9)+"
pos mariox,marioy : mes "@"//マリオの場所
//マップを自分から距離20まで表示
repeat 40,(marioy/16)-20
ct = cnt
repeat 40,(mariox/16)-20
pos 16*cnt,16*ct
mes masu(cnt,ct)
loop
loop
//衝突判定 以下
箱のサイズ=14
repeat 縦
ct = cnt
repeat 横
if masu(cnt,ct) = "□" || masu(cnt,ct) = "壁"{//そこにブロックがあるとき
//右から当たる場合
if (marioy >= 16*(ct)-箱のサイズ) && (marioy <= 16*(ct)+箱のサイズ){
if mariox == 16*(cnt)+箱のサイズ : PosX++
}
//左から当たる場合
if (marioy >= 16*(ct)-箱のサイズ) && (marioy <= 16*(ct)+箱のサイズ){
if mariox == 16*(cnt)-箱のサイズ : PosX--
}
//上から当たる場合
if (mariox >= 16*(cnt)-箱のサイズ) && (mariox <= 16*(cnt)+箱のサイズ){
if marioy == 16*(ct)-箱のサイズ : PosY--
}
//下から当たる場合
if (mariox >= 16*(cnt)-箱のサイズ) && (mariox <= 16*(cnt)+箱のサイズ){
if marioy == 16*(ct)+箱のサイズ : PosY++
}
}
loop
loop
//自分から3マスまで置いたり消したりできる
if (((mousex+PosX)/16) <= (mariox/16)+3) && (((mousex+PosX)/16) >= (mariox/16)-3) && (((mousey+PosY)/16) <= (marioy/16)+3) && (((mousey+PosY)/16) >= (marioy/16)-3){
//マウスで座標を選ぶ
pos ((mousex+PosX)/16)*16,((mousey+PosY)/16)*16
if block_count = 0 : mes "[]"
if block_count = 1 : mes "壁"
if block_count = 2 : mes "□"
if block_count = 3 : mes "&"
if block_count = 4 : mes "移"
if block_count = 5 : mes "飛"
if block_count = 6 : mes "%"
getkey rightclick, 2
if rightclick : masu(((mousex+PosX)/16),((mousey+PosY)/16))=block
}
//アイテムを拾う
getkey grab, 71: if grab{
repeat 10:poke 数字.cnt,0,48+cnt : loop
repeat 10
if masu(mariox/16,marioy/16)=数字(cnt) {
repeat 10
if baggage(cnt)=""{//スペースがあるなら
baggage(cnt)=masu(mariox/16,marioy/16)
goto *spaceari//スペースが見つかった時点でループから抜け出す
}
if cnt = 9 : goto *nospace//スペースがなかったらアイテムをフィールドから消さない
loop
}
if hairanai=1{
*spaceari
masu((mariox/16),(marioy/16))=""//拾ったアイテムをフィールドから消す
*nospace
break
}
loop
}
//アイテムを落とす
getkey drop, 68: if drop{
*dropitem
redraw 0
color 0,0,0 : boxf//画面初期化
color 255,255,255
repeat 10: pos PosX+16,(16*cnt)+PosY : mes baggage(cnt) : loop
pos PosX,(16*dropitem_y)+PosY : mes "→"
stick key
if key = 2 : dropitem_y--
if key = 8 : dropitem_y++
if dropitem_y<0 : dropitem_y++
if dropitem_y>9 : dropitem_y--
if key = 32{
if baggage(dropitem_y) != ""{
if masu((mariox/16),(marioy/16)) = ""{//今立ってる場所に何もないなら
masu((mariox/16),(marioy/16)) = baggage(dropitem_y)
baggage(dropitem_y) = ""
}
//今立ってる場所に何かがあるならなにもしない
}
}
getkey close, 27: if close:goto *main
redraw 1
await 10
goto *dropitem
}
//かばんの中のアイテムを見る
getkey item, 88: if item{
*watchitem
redraw 0
color 0,0,0 : boxf//画面初期化
color 255,255,255
repeat 10: pos PosX+16,(16*cnt)+PosY : mes baggage(cnt) : loop
getkey close, 27: if close:goto *main
redraw 1
await 10
goto *watchitem
}
//置くブロックを変える
getkey change_block, 67: if change_block : keyb++ : else : keyb=0
if keyb = 1 {
block_count++
if block_count = 0 : block = ""
if block_count = 1 : block = "壁"
if block_count = 2 : block = "□"
if block_count = 3 : block = "&"
if block_count = 4 : block = "移"
if block_count = 5 : block = "飛"
if block_count = 6 : block = "%"
if block_count = 7 : block_count = 0 : block = ""
}
//近づいてくる敵
//フィールドマップすべてを敵をサーチ
flag=0
repeat 縦
ct = cnt
repeat 横
if masu(cnt,ct)="%" {;その座標に敵を見つけたなら 番号をつけていく
//その番の敵の座標がmasu(enemyx(enemy_num), enemyy(enemy_num))
enemyx(enemy_num)=cnt
enemyy(enemy_num)=ct
enemy_num++
if enemy_num==100:enemy_num=0:flag=1:break//100体見つけた時点で2重ループを脱出
}
loop
if flag=1:break
loop
enemy_counter1++
if enemy_counter1 = 25 {
enemy_num=0
while (enemyx(enemy_num)!=-1) && (enemyy(enemy_num)!=-1)
//敵が@から10マス以内にいるとき
if (mariox/16 - enemyx(enemy_num))<10 | (enemyx(enemy_num) - mariox/16)<10 | (marioy/16 - enemyy(enemy_num))<10 | (enemyy(enemy_num) - marioy/16)<10 {
if mariox/16 > enemyx(enemy_num) {//敵が@の左にいる つまり 敵は右に進む
if enemyx(enemy_num)+1>横:goto *hata1
if masu(enemyx(enemy_num)+1,enemyy(enemy_num))!="":goto *hata1 ;障害物がある場合移動しない
masu(enemyx(enemy_num)+1,enemyy(enemy_num))=masu(enemyx(enemy_num),enemyy(enemy_num));左に移動
masu(enemyx(enemy_num),enemyy(enemy_num))="";もといた場所を消す
enemyx(enemy_num)=-1
enemyy(enemy_num)=-1
goto *hata1
}
if enemyx(enemy_num) > mariox/16 {//敵が@の右にいる つまり 敵は左に進む
if enemyx(enemy_num)-1<0:goto *hata1
if masu(enemyx(enemy_num)-1,enemyy(enemy_num))!="":goto *hata1 ;障害物がある場合移動しない
masu(enemyx(enemy_num)-1,enemyy(enemy_num))=masu(enemyx(enemy_num),enemyy(enemy_num));左に移動
masu(enemyx(enemy_num),enemyy(enemy_num))="";もといた場所を消す
enemyx(enemy_num)=-1
enemyy(enemy_num)=-1
goto *hata1
}
if marioy/16 > enemyy(enemy_num) {//敵が@の上にいる つまり 敵は下に進む
if enemyy(enemy_num)+1>縦:goto *hata1
if masu(enemyx(enemy_num),enemyy(enemy_num)+1)!="":goto *hata1
masu(enemyx(enemy_num),enemyy(enemy_num)+1)=masu(enemyx(enemy_num),enemyy(enemy_num));下に移動
masu(enemyx(enemy_num),enemyy(enemy_num))="";もといた場所を消す
enemyx(enemy_num)=-1
enemyy(enemy_num)=-1
goto *hata1
}
if enemyy(enemy_num) > marioy/16 {//敵が@の下にいる つまり 敵は上に進む
if enemyy(enemy_num)-1<0:goto *hata1
if masu(enemyx(enemy_num),enemyy(enemy_num)-1)!="":goto *hata1
masu(enemyx(enemy_num),enemyy(enemy_num)-1)=masu(enemyx(enemy_num),enemyy(enemy_num));上に移動
masu(enemyx(enemy_num),enemyy(enemy_num))="";もといた場所を消す
enemyx(enemy_num)=-1
enemyy(enemy_num)=-1
goto *hata1
}
}
*hata1
enemy_num++
if enemy_num=100:_break
wend
enemy_counter1 = 0
}
//ランダムに動く敵
enemy_counter++
if enemy_counter = 50 {
repeat 縦
ct = cnt
repeat 横
if masu(cnt,ct)="&"{;もしその座標に敵がいるなら
direction_teki = rnd(4)
if direction_teki = 0{;左
if cnt-1<0: goto *hata2
if masu(cnt-1,ct)!="":goto *hata2;障害物がある場合移動しない
masu(cnt-1,ct)=masu(cnt,ct);左に移動
masu(cnt,ct)="";もといた場所を消す
}
if direction_teki = 1{;上
if ct-1<0:goto *hata2
if masu(cnt,ct-1)!="":goto *hata2
masu(cnt,ct-1)=masu(cnt,ct);上に移動
masu(cnt,ct)="";もといた場所を消す
}
if direction_teki = 2{;右
if cnt+1>39:goto *hata2
if masu(cnt+1,ct)!="":goto *hata2
masu(cnt+1,ct)=masu(cnt,ct);右に移動
masu(cnt,ct)="";もといた場所を消す
}
if direction_teki = 3{;下
if ct+1>39:goto *hata2
if masu(cnt,ct+1)!="":goto *hata2
masu(cnt,ct+1)=masu(cnt,ct);下に移動
masu(cnt,ct)="";もといた場所を消す
}
}
*hata2
loop
loop
enemy_counter = 0
}
//移ブロックに触るとマップを移動する
if masu(mariox/16,marioy/16)="移"{
notesel buf
noteload "map2.txt"
count_note=0
repeat 縦
ct=cnt
repeat 横
noteget masu(cnt,ct),count_note
count_note++
loop
loop
goto *main
}
//飛ブロックに触るとワールドマップに移動する
if masu(mariox/16,marioy/16)="飛" : goto *worldmap
onexit goto *save
redraw 1
await 10
goto *main
*save
notesel buf
count=0
repeat 縦
ct=cnt
repeat 横
noteadd masu(cnt,ct),count,1
count++
loop
loop
dialog "txt",16,"テキストファイル"
if stat = 0 : end
notesave refstr
end
*worldmap
redraw 0
color 0,0,0:boxf
color 255,255,255
line
redraw 1
await 10
goto *worldmap

| |
|
2017/7/21(Fri) 04:55:11|NO.80676
これブロックを並べるゲームなんですけど、条件に当てはまるブロックの並びがあったらhouseをインクリメントして表示するっていうのがしたいんです。
例えば、5x5の壁でできた家がひとつあったらhouseは1、家を10作ったらhouseも10というふうに表示させたいんですけど、どうすればいいですか。
いまのままだと、条件に当てはまるのがひとつあるだけで、houseがずっと増えていきます。家を一つ作るたびにhouseを1インクリメントしたいんですけど、どうすればいいですか。
今のところ考えてるのは dim house, 40:house_num=0を別に用意することなんですけど、結局条件を満たしていたらインクリメントし続けるってところが解消できません。
おしえてくれるひといたらおしえてください。
repeat 80,20
ct=cnt
repeat 80,20
if masu(cnt,ct)="壁"&&masu(cnt+1,ct) ="壁"&&masu(cnt+2,ct)="壁"&&masu(cnt+3,ct)="壁"&&masu(cnt+4,ct)="壁"{
if masu(cnt,ct+1)="壁"&&masu(cnt+1,ct+1)=""&&masu(cnt+2,ct+1)=""&&masu(cnt+3,ct+1)=""&&masu(cnt+4,ct+1)="壁"{
if masu(cnt,ct+2)="壁"&&masu(cnt+1,ct+2)=""&&masu(cnt+2,ct+2)=""&&masu(cnt+3,ct+2)=""&&masu(cnt+4,ct+2)="壁"{
if masu(cnt,ct+3)="壁"&&masu(cnt+1,ct+3)=""&&masu(cnt+2,ct+3)=""&&masu(cnt+3,ct+3)=""&&masu(cnt+4,ct+3)="壁"{
if masu(cnt,ct+4)="壁"&&masu(cnt+1,ct+4)="壁"&&masu(cnt+2,ct+4)="壁"&&masu(cnt+3,ct+4)="壁"&&masu(cnt+4,ct+4)="壁"{
house=house+5
}
}
}
}
}
loop
loop
pos PosX,PosY:mes house
|
|
2017/7/21(Fri) 12:01:21|NO.80677
masu()の配列変数をいったんmasu_sub()などの別の配列変数に
まるごとコピーしてからmasu_sub()でhouseの判定をして
成立したら判定した部分の"壁"を"完"などに置き換えて再度判定をすれば
条件を満たしていたらインクリメントし続けるということはなくなると思います
|
|
2017/7/21(Fri) 15:51:08|NO.80679
とりあえずこうなったんですけど、家を壊したら家の数をディクリメントはどうすればいいですか。
自分には難しくてとても思いつきません。実は今回思いついたコードも不本意なんですけど、教えてくれる人いたら教えてください。
repeat 80,20
ct=cnt
repeat 80,20
if masu(cnt,ct)="壁"&&masu(cnt+1,ct) ="壁"&&masu(cnt+2,ct)="壁"&&masu(cnt+3,ct)="壁"&&masu(cnt+4,ct)="壁"{
if masu(cnt,ct+1)="壁"&&masu(cnt+1,ct+1)=""&&masu(cnt+2,ct+1)=""&&masu(cnt+3,ct+1)=""&&masu(cnt+4,ct+1)="壁"{
if masu(cnt,ct+2)="壁"&&masu(cnt+1,ct+2)=""&&masu(cnt+2,ct+2)=""&&masu(cnt+3,ct+2)=""&&masu(cnt+4,ct+2)="壁"{
if masu(cnt,ct+3)="壁"&&masu(cnt+1,ct+3)=""&&masu(cnt+2,ct+3)=""&&masu(cnt+3,ct+3)=""&&masu(cnt+4,ct+3)="壁"{
if masu(cnt,ct+4)="壁"&&masu(cnt+1,ct+4)="壁"&&masu(cnt+2,ct+4)="壁"&&masu(cnt+3,ct+4)="壁"&&masu(cnt+4,ct+4)="壁"{
masu(cnt,ct)="家": masu(cnt+1,ct)="家": masu(cnt+2,ct)="家": masu(cnt+3,ct)="家": masu(cnt+4,ct)="家"
masu(cnt,ct+1)="家": masu(cnt+4,ct+1)="家"
masu(cnt,ct+2)="家": masu(cnt+4,ct+2)="家"
masu(cnt,ct+3)="家": masu(cnt+4,ct+3)="家"
masu(cnt,ct+4)="家": masu(cnt+1,ct+4)="家":masu(cnt+2,ct+4)="家":masu(cnt+3,ct+4)="家":masu(cnt+4,ct+4)="家"
house++
}
}
}
}
}
loop
loop

| |
|
2017/7/21(Fri) 17:37:37|NO.80680
やはりその場合も
masu()の配列変数をいったんmasu_sub()などの別の配列変数に
まるごとコピーしてからmasu_sub()で"家"の判定をして
条件を満たしていたらインクリメントし
判定した部分の"家"を"完"などに置き換えます
家の数を1から数えることになるので
家が壊されていればその分家の数が減り
デクリメントする必要がなくなると思います
|
|
2017/7/21(Fri) 17:53:57|NO.80681
できました!ありがとうございました。
|
|
2017/7/22(Sat) 05:58:51|NO.80685
村人に番号をつけました。画面に表示されてる村人をクリックすると、その番号を取得して、下のほうに表示する。というのをしようとしています。
その取得がうまくできません。コードは省いて書いてあります。どううまくいかないのかというと、例えば一番左上のV(村人)がvillager_numは0になるはずなのにそこが、1になっています。
そして、右下のほうにいる2人のVは両方とも0になっています。教えてくれる人いたら教えてください。
//始まる前にすでに配置済みの村人をサーチして番号を振っていく
flag3=0
repeat 80,20
ct = cnt
repeat 80,20
if masu(cnt,ct)=="V" {;その座標に 村人 を見つけたなら 番号をつけていく
//その番の 村人 の座標がmasu(villagerx(villager_num), villagery(villager_num))
villagerx(villager_num)=cnt
villagery(villager_num)=ct
villager_num++
if villager_num==100:villager_num=0:flag3=1:break//100体見つけた時点で2重ループを脱出
}
loop
if flag3=1:break
loop
メインループ開始
//leftclickで村人を選択
if ((key==256)!0) && masu(((mousex+PosX)/16),((mousey+PosY)/16))="V" && Lclick_sw = 0{
masu(((mousex+PosX)/16),((mousey+PosY)/16))="[V]"
vil_kiokux=((mousex+PosX)/16)
vil_kiokuy=((mousey+PosY)/16)
Lclick_sw=1
}
;何もないところをクリックすると上の選択を解除
if ((key==256)!0) && masu(((mousex+PosX)/16),((mousey+PosY)/16))="" && Lclick_sw = 1{
masu(vil_kiokux,vil_kiokuy)="V"
Lclick_sw=0
}
;村人を選んだ状態で空のマスをクリックするとそこまで移動
if ((key==512)!0) && masu(vil_kiokux,vil_kiokuy)="[V]" && masu(((mousex+PosX)/16),((mousey+PosY)/16))="" && Lclick_sw = 1{
}
//自分の村人を選んだ座標が 番号をもつ村人の座標と同じなら表示
repeat 100
if masu(vil_kiokux,vil_kiokuy) == "[V]" && masu(villagerx(cnt), villagery(cnt)) == "V"{
villager_num = cnt
pos PosX+100,PosY+624 : mes "選んだ村人の番号" + villager_num
break
}
loop
if rightclick {
if block="V":goto *hata4;村人は一人ずつしか置けなくした 番号の問題
masu(((mousex+PosX)/16),((mousey+PosY)/16))=block
//新しく生まれた村人に最大の番号を振っていく
*hata4
if block="V" && flag9=0{;置いたのが村人なら 最大の 番号をつけていく
//その番の 村人 の座標がmasu(villagerx(villager_num), villagery(villager_num))
villager_num++
villagerx(villager_num)=(mousex+PosX)/16 ;ここにはmasu(,)の座標を入れていく
villagery(villager_num)=(mousey+PosY)/16
masu(((mousex+PosX)/16),((mousey+PosY)/16))=block
if villager_num==100:villager_num=0
flag9++
}
}else:flag9=0
全体
https://gist.github.com/Zerosen/a4d2ed399871d88655d559676bf8f717

| |
|
2017/7/22(Sat) 11:51:04|NO.80688
自分で解決できました。
|
|