HSPポータル
サイトマップ お問い合わせ


HSPTV!掲示板


未解決 解決 停止 削除要請

2017
0402
℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡沢山の玉を表示し その当たり判定を教えてください!!3解決


℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡

リンク

2017/4/2(Sun) 10:40:06|NO.78795

大量の玉を描画して、
自機が当たったら玉は消えて得点が加算されるゲームを作っているんですが、
当たり判定が分からないので教えて下さい!!

↓↓スクリプトです↓↓

//拡張プラグインを読み込み #uselib "user32" #func GetWindowLong "GetWindowLongA" int, int #func SetWindowLong "SetWindowLongA" int, int, int #func SetWindowPos "SetWindowPos" int, nullptr, nullptr, nullptr, nullptr, nullptr, int #func GetClassLong "GetClassLongA" int, int #func SetClassLong "SetClassLongA" int, int, int #include "gdi32.as" //マクロ #define ctype RGB(%1,%2,%3) (%1 | %2 << 8 | %3 << 16) //モジュール開始 #module #define ctype max( %1, %2 ) ( %1 )*( %1 > %2 ) + ( %2 )*( %1 <= %2 ) #define ctype min( %1, %2 ) ( %1 )*( %1 < %2 ) + ( %2 )*( %1 >= %2 ) #const DEFAULT_R 20 #deffunc rboxf int _x1, int _y1, int _x2, int _y2, int _r x1 = min(_x1, _x2) : x2 = max(_x1, _x2) y1 = min(_y1, _y2) : y2 = max(_y1, _y2) box_width = x2 - x1 : box_height = y2 - y1 if ( _r <= 0 ) { r = DEFAULT_R } else { r = _r } r = min( r, min( box_width / 2, box_height / 2 ) ) boxf x1, y1+r, x2, y2-r boxf x1+r, y1, x2-r, y2 repeat 4 x = x1 + ( cnt \ 2 ) * ( box_width - r * 2 + 1) y = y1 + ( cnt / 2 ) * ( box_height - r * 2 + 1 ) circle x, y, x + r * 2, y + r * 2 loop return #deffunc CenterMes str moji sdim word,1024 font "游ゴシック",20,0 msgx=320-(strlen(moji)*5) pos msgx,230 mes moji return //モジュール終了 #global //変数の宣言 dim hInput, 1 sdim word,1024 //絶対に必要な命令 oncmd gosub *ctlcoloredit, $133 onexit *exit //テスト時 goto *start //画面作成 screen 0,ginfo(20),ginfo(21),0,0,0 width 640,480,ginfo(20)/2-320,ginfo(21)/2-300 //タイトル名 title "CircleTraining ver1.0"   //*******中略*******// *start //最大化ボタンとウィンドウサイズ可変有効のウィンドウを作成 screen 0,ginfo(20),ginfo(21),0,0,0 GetWindowLong hwnd, -16 SetWindowLong hwnd, -16, stat | $10000 | $40000 width 640,480,ginfo(20)/2-320,ginfo(21)/2-300 //タイトル名 title "CircleTraining ver1.0" //変数宣言 score = 10 esa_max = 10000 repeat esa_max esar(cnt)=rnd(256) esag(cnt)=rnd(256) esab(cnt)=rnd(256) esax(cnt)=rnd(50000) esay(cnt)=rnd(50000) loop //メインループ *mainloop //描画開始 redraw 0 //背景 color 255,255,255 : boxf //変数管理 if score \ 250 = 0 : size = size + 1 if score >= 999999999 : score = 999999999 if size >= 100 : size = 100 //自機描画 color 255,0,0 circle ginfo_winx/2-(size+1)+2,(ginfo_winy/2-(size+1))-12,ginfo_winx/2+(size+1)+12,ginfo_winy/2+(size+1)-2,1 color 0,0,0 font "游ゴシック",20,0 moji = ""+score msgx=ginfo_winx/2-(strlen(moji)*5)+5 msgy=ss pos msgx,ginfo_winy/2-20 mes moji if mousex>=ginfo_winx/2 : mx=mx-(1+speed) if mousex<=ginfo_winx/2 : mx=mx+(1+speed) if mousey>=ginfo_winy/2 : my=my-(1+speed) if mousey<=ginfo_winy/2 : my=my+(1+speed) GetClassLong hwnd, -26 SetClassLong hwnd, -26, stat | $8 //玉を描画 repeat esa_max color esar(cnt),esag(cnt),esab(cnt) circle esax(cnt)+mx,esay(cnt)+my,esax(cnt)+mx+5,esay(cnt)+my+5,1 if esax(cnt) >= mx -5 & esay(cnt) <= my - 5 & esax(cnt) >= mx & esay(cnt) <= my : else : score = score + 1 loop //描画終了 redraw 1 //時間待ち await 1 //メインループへ goto *mainloop *ctlcoloredit if hInput.0 = lparam { SetTextColor wparam, RGB($FF, $FF ,$FF) SetBkColor wparam, RGB(124, 92, 220) return hBrush.0 } return *exit DeleteObject hBrush.0 end



この記事に返信する


わた雲

リンク

2017/4/2(Sun) 12:24:17|NO.78804

別のウィンドウに単色ベタ塗り(たとえば255,0,0)のたまを表示し、pget命令により別ウィンドウの座標(mx,my)の色を読み取り、
その色が(255,0,0)であったら当たりとするというのはどうでしょう。

pgetは数学的に表しにくい当たり判定をつけたり、
ほかにもbmpsaveで保存してデータを読み取るなど便利に使えるので愛用しております。
ただ、別ウィンドウに表示するたまは、自機の形の分だけ膨らませましょう。

自機の当たり判定が四角、たまが丸なら、過度の丸い四角形を表示するといった具合です。



InoueSoftware

リンク

2017/4/2(Sun) 13:05:16|NO.78807

大量の玉を描画する時点で、自機の上にあるかないかを確認するのもいいと思います。

//玉を描画 repeat esa_max color esar(cnt),esag(cnt),esab(cnt) circle esax(cnt)+mx,esay(cnt)+my,esax(cnt)+mx+5,esay(cnt)+my+5,1 //円を矩形とみてあたり判定 if (ginfo_winx/2-(size+1)+2)<(esax(cnt)+mx)&&((ginfo_winy/2-(size+1))-12)<(esay(cnt)+my)&&(ginfo_winx/2+(size+1)+12)>(esax(cnt)+mx+5)&&(ginfo_winy/2+(size+1)-2)>(esay(cnt)+my+5){ score+=10//当たった(中に入っている) } loop
――――
ところで このスレの投稿者名は、前回の@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@さんの便乗だと思ったら
前回の名前を改名しただけだった(笑)
スレッド一覧の崩壊がいつか名物になりそう...



℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡℡

リンク

2017/4/2(Sun) 17:06:55|NO.78816

ありがとうございます!!
参考にします!!



ONION software Copyright 1997-2025(c) All rights reserved.