;=========================================================== ; 2008/08/11 ; 蟲 0.2 ; Centipede(センチピード) ? ; GAM-22 ;=========================================================== ;----------------------------------------------------------- ; 定数 ;----------------------------------------------------------- #const body_len 10; 蟲の長さ #const body_len2 body_len-1 #const buf_win 1; バッファ πh = 1.57079632; 円周率の半分 #define debug 0; デバックモード /*---------------------------------------------------------- ; パラメータ省略 ------------------------------------------------------------ 1. color 0,0,0 → color 2. var(2,0) → var(2) ;----------------------------------------------------------- ; 数学計算 ;----------------------------------------------------------- 1. 内積 = ax*bx + ay*by 2. ベクトル(x,y) +1/2π = (-y,x) */ ;----------------------------------------------------------- ; 部品描画 ;----------------------------------------------------------- buffer buf_win color : boxf color 48,48,48 ;------------------------------------------------------- ; Aパーツ(頭 胸 足) ;------------------------------------------------------- // 形状生成 circle 1,3, 12,32 circle 20,3, 31,32 circle 0,0, 32,30 // グラデーション加工 color repeat 16 gmode 5, 32,32, cnt*cnt+10 pos 47+cnt/4, 16+cnt/4 grotate buf_win, 0,0, 0, 32-cnt,32-cnt loop ;------------------------------------------------------- ; Bパーツ ;------------------------------------------------------- /*v1 = 125,125,150,100 v2 = 0,0,100,100 gsquare -12, v1, v2*/ ;----------------------------------------------------------- ; 初期化 ;----------------------------------------------------------- randomize ddim i_body_x, 100,10 ddim i_body_y, 100,10 ddim i_body_r, 100,10 gosub *i_born gsel 0, 1 *main ;----------------------------------------------------------- ; main - AI ;----------------------------------------------------------- repeat i_max // rcnt rcnt = cnt // 頭移動 i_body_r(rcnt) += i_snake(rcnt) i_body_x(rcnt) += cos(i_body_r(rcnt)-πh) i_body_y(rcnt) += sin(i_body_r(rcnt)-πh) // 体移動(っていうか引っ張る) repeat body_len2, 1 i_body_r(rcnt,cnt) = atan( i_body_y(rcnt,cnt)-i_body_y(rcnt,cnt-1), i_body_x(rcnt,cnt)-i_body_x(rcnt,cnt-1)) -πh i_body_x(rcnt,cnt) = i_body_x(rcnt,cnt-1) + cos(i_body_r(rcnt,cnt)+πh)*8 i_body_y(rcnt,cnt) = i_body_y(rcnt,cnt-1) + sin(i_body_r(rcnt,cnt)+πh)*8 loop // ターゲット(マウス)接近 i_target(rcnt) = atan(i_body_y(rcnt)-mousey, i_body_x(rcnt)-mousex) -πh #if debug color 0,0,255 #endif repeat i_max // 仲間から100dot以内なら、回避 x = i_body_x(cnt) -i_body_x(rcnt) y = i_body_y(cnt) -i_body_y(rcnt) if x*x+y*y<=1000 & rcnt!cnt { i_target(rcnt) = atan(y,x) -πh #if debug color 255 #endif } loop #if debug line i_body_x(rcnt),i_body_y(rcnt), i_body_x(rcnt)+cos(i_target(rcnt)-πh)*50, i_body_y(rcnt)+sin(i_target(rcnt)-πh)*50 #endif // 目標追従 if cos(i_body_r.rcnt)*cos(i_target.rcnt)+sin(i_body_r.rcnt)*sin(i_target.rcnt) <= 0.5 {; 蛇行タイミング i_snake(rcnt) = -0.05 + 0.1*(-sin(i_body_r.rcnt)*cos(i_target.rcnt) + cos(i_body_r.rcnt)*sin(i_target.rcnt)>=0); 蛇行角度 } loop ;----------------------------------------------------------- ; main - draw ;----------------------------------------------------------- redraw 0 // 背景 color : boxf // 蟲 repeat i_max rcnt = cnt repeat body_len pos i_body_x(rcnt,cnt), i_body_y(rcnt,cnt) w = 17+(-0.2*(3-cnt)*(4-cnt)) h = 10 r = i_body_r(rcnt,cnt) gosub *draw_A loop loop // wait redraw ;----------------------------------------------------------- ; main - end ;----------------------------------------------------------- // wait await 22 // var mcnt++ if (mcnt\20) :else: gosub*i_born // back goto *main *draw_A gmode 2, 32,32 grotate buf_win, 32,0, r, w,h return *i_born // 虫生成 if i_max>=99 : return i_snake(i_max) = 0.05 i_target(i_max) = 0.0 i_body_x(i_max) = 1.0*rnd(640) i_body_y(i_max) = 480.0*rnd(2) i_body_r(i_max) = atan(i_body_y(i_max)-240, i_body_x(i_max)-320) -πh repeat body_len2, 1 i_body_x(i_max,cnt) = i_body_x(i_max) i_body_y(i_max,cnt) = i_body_y(i_max) i_body_r(i_max,cnt) = i_body_r(i_max) loop i_max++ return