#module #defcfunc getouter double x1s,double y1s,double x2s,double y2s,double x1e,double y1e x1=x2s - x1s z1=y2s - y1s x2=x1e - x1s z2=y1e - y1s ans=z1*x2-x1*z2 return ans>=0 #global players=2 ddim xpos,players ddim ypos,players ddim spd ,players ddim rad ,players repeat players xpos(cnt)=double(rnd(ginfo_winx)) ypos(cnt)=double(rnd(ginfo_winy)) loop repeat getkey wkey,'W' getkey skey,'S' spd(0)=double(wkey-skey)*10 getkey akey,'A' getkey dkey,'D' rad(0)-deg2rad(akey-dkey)*10. repeat players player=cnt xpos(cnt)+spd(cnt)*sin(-rad(cnt)) ypos(cnt)+spd(cnt)*cos(-rad(cnt)) ax_0=xpos(cnt)+(-30.)*cos(rad(cnt))+(-40.)*sin(rad(cnt)) ay_0=ypos(cnt)+(-30.)*sin(rad(cnt))-(-40.)*cos(rad(cnt)) ax_1=xpos(cnt)+( 30.)*cos(rad(cnt))+(-40.)*sin(rad(cnt)) ay_1=ypos(cnt)+( 30.)*sin(rad(cnt))-(-40.)*cos(rad(cnt)) ax_2=xpos(cnt)+( 30.)*cos(rad(cnt))+( 60.)*sin(rad(cnt)) ay_2=ypos(cnt)+( 30.)*sin(rad(cnt))-( 60.)*cos(rad(cnt)) ax_3=xpos(cnt)+(-30.)*cos(rad(cnt))+( 60.)*sin(rad(cnt)) ay_3=ypos(cnt)+(-30.)*sin(rad(cnt))-( 60.)*cos(rad(cnt)) dx_(0)=xpos(cnt)+(-30.)*cos(rad(cnt))+(-40.)*sin(rad(cnt)) dy_(0)=ypos(cnt)+(-30.)*sin(rad(cnt))-(-40.)*cos(rad(cnt)) dx_(1)=xpos(cnt)+( 30.)*cos(rad(cnt))+(-40.)*sin(rad(cnt)) dy_(1)=ypos(cnt)+( 30.)*sin(rad(cnt))-(-40.)*cos(rad(cnt)) dx_(2)=xpos(cnt)+( 30.)*cos(rad(cnt))+( 60.)*sin(rad(cnt)) dy_(2)=ypos(cnt)+( 30.)*sin(rad(cnt))-( 60.)*cos(rad(cnt)) dx_(3)=xpos(cnt)+(-30.)*cos(rad(cnt))+( 60.)*sin(rad(cnt)) dy_(3)=ypos(cnt)+(-30.)*sin(rad(cnt))-( 60.)*cos(rad(cnt)) repeat players if player!cnt{ ax_0=xpos(cnt)+(-30.)*cos(rad(cnt))+(-40.)*sin(rad(cnt)) ay_0=ypos(cnt)+(-30.)*sin(rad(cnt))-(-40.)*cos(rad(cnt)) ax_1=xpos(cnt)+( 30.)*cos(rad(cnt))+(-40.)*sin(rad(cnt)) ay_1=ypos(cnt)+( 30.)*sin(rad(cnt))-(-40.)*cos(rad(cnt)) ax_2=xpos(cnt)+( 30.)*cos(rad(cnt))+( 60.)*sin(rad(cnt)) ay_2=ypos(cnt)+( 30.)*sin(rad(cnt))-( 60.)*cos(rad(cnt)) ax_3=xpos(cnt)+(-30.)*cos(rad(cnt))+( 60.)*sin(rad(cnt)) ay_3=ypos(cnt)+(-30.)*sin(rad(cnt))-( 60.)*cos(rad(cnt)) //< repeat 4 p1=getouter( ax_0 , ay_0 , ax_1 , ay_1 , dx_(cnt) , dy_(cnt) ) p2=getouter( ax_1 , ay_1 , ax_2 , ay_2 , dx_(cnt) , dy_(cnt) ) p3=getouter( ax_2 , ay_2 , ax_3 , ay_3 , dx_(cnt) , dy_(cnt) ) p4=getouter( ax_3 , ay_3 , ax_0 , ay_0 , dx_(cnt) , dy_(cnt) ) if p1+p2+p3+p4=4{ hit(player)=1 break }else{ hit(player)=0 } loop //> if hit(player)=1{ //<ここに壁すり xc=-spd(player)*sin(-rad(player)) yc=-spd(player)*cos(-rad(player)) //>壁すり判定 break } } loop loop redraw 0 color:boxf repeat players player=cnt sx_0=xpos(cnt)+(-30.)*cos(rad(cnt))+(-40.)*sin(rad(cnt)) sy_0=ypos(cnt)+(-30.)*sin(rad(cnt))-(-40.)*cos(rad(cnt)) sx_1=xpos(cnt)+( 30.)*cos(rad(cnt))+(-40.)*sin(rad(cnt)) sy_1=ypos(cnt)+( 30.)*sin(rad(cnt))-(-40.)*cos(rad(cnt)) sx_2=xpos(cnt)+( 30.)*cos(rad(cnt))+( 60.)*sin(rad(cnt)) sy_2=ypos(cnt)+( 30.)*sin(rad(cnt))-( 60.)*cos(rad(cnt)) sx_3=xpos(cnt)+(-30.)*cos(rad(cnt))+( 60.)*sin(rad(cnt)) sy_3=ypos(cnt)+(-30.)*sin(rad(cnt))-( 60.)*cos(rad(cnt)) color 255,0,0 line sx_0,sy_0,sx_1,sy_1 mes 0 color 255,255,0 line sx_1,sy_1,sx_2,sy_2 mes 1 color 0,0,255 line sx_2,sy_2,sx_3,sy_3 mes 2 color 255,255,0 line sx_3,sy_3,sx_0,sy_0 mes 3 color 0,255,0 line 0,0,xpos(cnt),ypos(cnt) pos 0,cnt*18 mes strf("player "+cnt+" : hit "+hit(cnt)+"%8.2f , %8.2f",xpos(cnt),ypos(cnt)) loop redraw 1 await 1000/16 loop
上記のように矩形どうしの当たり判定はできるのですが、そこからがうまくできません…
あたった際に当たった相手の辺に合わせてずるように移動させたいです。
どのように処理すればいいか、ヒントだけでもいいのでご教示願います