Advertisement
PsichiX

WR-s01e01

Feb 29th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.03 KB | None | 0 0
  1. #define bar_int
  2.  
  3.  
  4. #define bar_ai
  5. var fp, lp, fpi, lpi, pr, av, prp, avp, dpl,
  6.     i, c, o, p, ii;
  7.  
  8. var pcsl = 100;
  9.  
  10. dpl = ds_priority_create();
  11. c = instance_number(obj_ball);
  12. if(c > 0)
  13. {
  14.     for(i = 0; i < c; ++i)
  15.     {
  16.         o = instance_find(obj_ball, i);
  17.         if(c > 1)
  18.             p = 2;
  19.         else
  20.             p = 3;
  21.         ds_priority_add(dpl, o, calculate_priority(o, pcsl, p));
  22.     }
  23. }
  24. c = instance_number(obj_bonus);
  25. if(c > 0)
  26. {
  27.     for(i = 0; i < c; ++i)
  28.     {
  29.         o = instance_find(obj_bonus, i);
  30.         ii = o.image_index;
  31.         if(ii == 0)
  32.             p = 3;
  33.         else if(ii == 4)
  34.             p = 2;
  35.         else if(ii == 3)
  36.         {
  37.             if(bar_width > room_width * 0.4)
  38.                 p = -2;
  39.             else if(bar_width > room_width * 0.2)
  40.                 p = -1;
  41.             else if(bar_width < room_width * 0.2)
  42.                 p = 1;
  43.             else if(bar_width < room_width * 0.1)
  44.                 p = 2;
  45.             else
  46.                 p = 0;
  47.         }
  48.         else if(ii == 2)
  49.         {
  50.             if(bar_width > room_width * 0.4)
  51.                 p = 2;
  52.             else if(bar_width > room_width * 0.2)
  53.                 p = 1;
  54.             else if(bar_width < room_width * 0.2)
  55.                 p = -1;
  56.             else if(bar_width < room_width * 0.1)
  57.                 p = -2;
  58.             else
  59.                 p = 0;
  60.         }
  61.         else
  62.             p = -1;
  63.         ds_priority_add(dpl, o, calculate_priority(o, pcsl, p));
  64.     }
  65. }
  66. if(ds_priority_size(dpl) > 0)
  67. {
  68.     fpi = ds_priority_find_max(dpl);
  69.     lpi = ds_priority_find_min(dpl);
  70.     fp = ds_priority_find_priority(dpl, fpi);
  71.     lp = ds_priority_find_priority(dpl, lpi);
  72.     if(fp > 0)
  73.     {
  74.         pr = fpi;
  75.         prp = fp;
  76.     }
  77.     else
  78.     {
  79.         pr = noone;
  80.         prp = 0;
  81.     }
  82.     if(lp < 0)
  83.     {
  84.         av = lpi;
  85.         avp = lp;
  86.     }
  87.     else
  88.     {
  89.         av = noone;
  90.         avp = 0;
  91.     }
  92. }
  93. else
  94. {
  95.     pr = noone;
  96.     av = noone;
  97. }
  98. ds_priority_destroy(dpl);
  99.  
  100. if(pr != noone && abs(prp) > abs(avp))
  101. {
  102.     if(pr.object_index == obj_ball)
  103.     {
  104.         if(pr.vspeed < 0)
  105.             x = pursuit_avoid(id, pr, av, 10);
  106.         else
  107.             x = bounce_ball_to_brick(pr, instance_nearest(pr.x, pr.y, obj_brick01));
  108.     }
  109.     else
  110.         x = pr.x;
  111. }
  112. else if(av != noone)
  113. {
  114.     if(pr != noone)
  115.         x = pursuit_avoid(id, pr, av, 10);
  116.     else
  117.         x = avoid(id, av, 10);
  118. }
  119.  
  120.  
  121. #define lines_intersect
  122. /// lines_intersect(x1,y1,x2,y2,x3,y3,x4,y4,segment)
  123. //
  124. //  Returns a vector multiplier (t) for an intersection on the
  125. //  first line. A value of (0 < t <= 1) indicates an intersection
  126. //  within the line segment, a value of 0 indicates no intersection,
  127. //  other values indicate an intersection beyond the endpoints.
  128. //
  129. //      x1,y1,x2,y2     1st line segment
  130. //      x3,y3,x4,y4     2nd line segment
  131. //      segment         If true, confine the test to the line segments.
  132. //
  133. //  By substituting the return value (t) into the parametric form
  134. //  of the first line, the point of intersection can be determined.
  135. //  eg. x = x1 + t * (x2 - x1)
  136. //      y = y1 + t * (y2 - y1)
  137. //
  138. /// GMLscripts.com/license
  139. {
  140.     var ua, ub, ud, ux, uy, vx, vy, wx, wy;
  141.     ua = 0;
  142.     ux = argument2 - argument0;
  143.     uy = argument3 - argument1;
  144.     vx = argument6 - argument4;
  145.     vy = argument7 - argument5;
  146.     wx = argument0 - argument4;
  147.     wy = argument1 - argument5;
  148.     ud = vy * ux - vx * uy;
  149.     if (ud != 0)
  150.     {
  151.         ua = (vx * wy - vy * wx) / ud;
  152.         if (argument8)
  153.         {
  154.             ub = (ux * wy - uy * wx) / ud;
  155.             if (ua < 0 || ua > 1 || ub < 0 || ub > 1) ua = 0;
  156.         }
  157.     }
  158.     return ua;
  159. }
  160.  
  161.  
  162. #define pursuit_avoid
  163. /// pursuit_avoid(inst, pursuit, avoid, separation)
  164.  
  165. if(argument0 == noone || argument1 == noone || argument2 == noone)
  166.     return 0;
  167.  
  168. var oi = argument0.object_index,
  169.     oa = argument2.object_index,
  170.     iw = 0,
  171.     iwh = 0,
  172.     axs = argument2.x,
  173.     axe = argument2.x,
  174.     ps = argument1.x - argument0.x,
  175.     as = argument2.x - argument0.x,
  176.     tx = argument1.x;
  177.  
  178. if(oi == obj_bar)
  179. {
  180.     iw = argument0.bar_width;
  181.     iwh = iw * 0.5;
  182. }
  183. if(oa == obj_bonus)
  184. {
  185.     axs = argument2.x - 20;
  186.     axe = argument2.x + 20;
  187. }
  188.  
  189. if(axs - argument3 < tx + iwh || axe + argument3 > tx - iwh)
  190. {
  191.     if(as < 1 || as > -1)
  192.         as = argument1.hspeed;
  193.     if(as >= 0 && axs - argument3 - iwh < iwh)
  194.         as = -1;
  195.     else if(as < 0 && axe + argument3 + iwh > room_width - iwh)
  196.         as = 1;
  197.     if(as > 0)
  198.         return axs - argument3 - iwh;
  199.     else if(as < 0)
  200.         return axe + argument3 + iwh;
  201.     else
  202.         return tx;
  203. }
  204. else
  205.     return tx;
  206.  
  207.  
  208. #define avoid
  209. /// avoid(inst, avoid, separation)
  210.  
  211. if(argument0 == noone || argument1 == noone)
  212.     return 0;
  213.  
  214. var oi = argument0.object_index,
  215.     oa = argument1.object_index,
  216.     iw = 0,
  217.     iwh = 0,
  218.     axs = argument1.x,
  219.     axe = argument1.x,
  220.     tx = argument0.x,
  221.     as = argument1.x - tx;
  222.  
  223. if(oi == obj_bar)
  224. {
  225.     iw = argument0.bar_width;
  226.     iwh = iw * 0.5;
  227. }
  228. if(oa == obj_bonus)
  229. {
  230.     axs = argument1.x - 20;
  231.     axe = argument1.x + 20;
  232. }
  233.  
  234. if(axs - argument2 < tx + iwh || axe + argument2 > tx - iwh)
  235. {
  236.     if(as < 1 || as > -1)
  237.         as = argument1.hspeed;
  238.     if(as >= 0 && axs - argument2 - iwh < iwh)
  239.         as = -1;
  240.     else if(as < 0 && axe + argument2 + iwh > room_width - iwh)
  241.         as = 1;
  242.     if(as > 0)
  243.         return axs - argument2 - iwh;
  244.     else if(as < 0)
  245.         return axe + argument2 + iwh;
  246.     else
  247.         return tx;
  248. }
  249. else
  250.     return tx;
  251.  
  252.  
  253. #define calculate_priority
  254. /// calculate_priority(inst, stepsLimit, multiplier)
  255.  
  256. var oi, ts, tx, ty, nx, ny, nl, sx, sy, sa;
  257.  
  258. var llf = max(room_width, room_height);
  259.  
  260. if(argument0 == noone || argument1 <= 0)
  261.     return 0;
  262. else
  263. {
  264.     oi = argument0.object_index;
  265.     if(oi == obj_ball)
  266.     {
  267.         if(argument0.vspeed < 0)
  268.             return 0;
  269.         else
  270.         {
  271.             ts = 0;
  272.             tx = argument0.x;
  273.             ty = argument0.y;
  274.             nl = argument0.speed;
  275.             nx = argument0.hspeed / nl;
  276.             ny = argument0.vspeed / nl;
  277.             while(ty < y && ts < argument1)
  278.             {
  279.                 tx += nx * nl;
  280.                 ty += ny * nl;
  281.                 if(tx < 10)
  282.                 {
  283.                     tx = 10;
  284.                     nx *= -1;
  285.                     nl += argument0.speed_inc;
  286.                 }
  287.                 else if(tx > room_width - 10)
  288.                 {
  289.                     tx = room_width - 10;
  290.                     nx *= -1;
  291.                     nl += argument0.speed_inc;
  292.                 }
  293.                 ++ts;
  294.             }
  295.             return (argument1 - ts) * argument2;
  296.         }
  297.     }
  298.     else if(oi == obj_bonus)
  299.     {
  300.         if(argument0.vspeed < 0)
  301.             return 0;
  302.         else
  303.         {
  304.             ts = 0;
  305.             tx = argument0.x;
  306.             ty = argument0.y;
  307.             sa = argument0.gravity;
  308.             sx = argument0.hspeed;
  309.             sy = argument0.vspeed;
  310.             while(ty < y && ts < argument1)
  311.             {
  312.                 tx += sx;
  313.                 ty += sy;
  314.                 if(tx < 10)
  315.                 {
  316.                     tx = 10;
  317.                     sx *= -1;
  318.                 }
  319.                 if(tx < 10)
  320.                 {
  321.                     tx = 10;
  322.                     sx *= -1;
  323.                 }
  324.                 sy += sa;
  325.                 nl = sx * sx + sy * sy;
  326.                 if(nl > 100)
  327.                 {
  328.                     nl = sqrt(nl);
  329.                     nx = sx / nl;
  330.                     ny = sy / nl;
  331.                     sx = nx * 10;
  332.                     sy = ny * 10;
  333.                 }
  334.                 ++ts;
  335.             }
  336.             return (argument1 - ts) * argument2;
  337.         }
  338.     }
  339.     else
  340.         return 0;
  341. }
  342.  
  343.  
  344. #define bounce_ball_to_brick
  345. /// bounce_ball_to_brick(ball, brick)
  346.  
  347. if(argument0 == noone || argument1 == noone)
  348.     return 0;
  349.  
  350. var bxs, bys, len, bxe, bye, ti, tx, ty, dx, dy, ptx, pty;
  351.  
  352. var b = argument0,
  353.     t = argument1,
  354.     llf = max(room_width, room_height),
  355.     pyo = 50,
  356.     phh = 8,
  357.     bhh = 10,
  358.     ptyo = phh + bhh,
  359.     thh = 24,
  360.     tyo = thh + bhh,
  361.     txo = 24,
  362.     pcsl = 100,
  363.     phw = bar_width * 0.5;
  364.  
  365. bxs = b.x;
  366. bys = b.y;
  367. len = b.speed;
  368. bxe = bxs + (b.hspeed * llf) / len;
  369. bye = bys + (b.vspeed * llf) / len;
  370. ti = lines_intersect(
  371.     bxs, bys, bxe, bye,
  372.     bxs - llf, y - ptyo, bxs + llf, y - ptyo,
  373.     false
  374. );
  375. if(ti < 0 || ti > 1)
  376.     return bxs;
  377. else
  378. {
  379.     tx = lerp(bxs, bxe, ti);
  380.     ty = lerp(bys, bye, ti);
  381.     dx = tx - t.x - txo;
  382.     dy = ty - t.y - tyo;
  383.     len = sqrt(dx * dx + dy * dy);
  384.     ptx = tx + (dx * llf) / len;
  385.     pty = ty + (dy * llf) / len;
  386.     ti = lines_intersect(
  387.         tx, ty, ptx, pty,
  388.         bxs - llf, y + pyo, bxs + llf, y + pyo,
  389.         false
  390.     );
  391.     if(ti < 0 || ti > 1)
  392.         return tx;
  393.     else
  394.         return lerp(tx, ptx, ti);
  395. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement