Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define bar_int
- #define bar_ai
- var fp, lp, fpi, lpi, pr, av, prp, avp, dpl,
- i, c, o, p, ii;
- var pcsl = 100;
- dpl = ds_priority_create();
- c = instance_number(obj_ball);
- if(c > 0)
- {
- for(i = 0; i < c; ++i)
- {
- o = instance_find(obj_ball, i);
- if(c > 1)
- p = 2;
- else
- p = 3;
- ds_priority_add(dpl, o, calculate_priority(o, pcsl, p));
- }
- }
- c = instance_number(obj_bonus);
- if(c > 0)
- {
- for(i = 0; i < c; ++i)
- {
- o = instance_find(obj_bonus, i);
- ii = o.image_index;
- if(ii == 0)
- p = 3;
- else if(ii == 4)
- p = 2;
- else if(ii == 3)
- {
- if(bar_width > room_width * 0.4)
- p = -2;
- else if(bar_width > room_width * 0.2)
- p = -1;
- else if(bar_width < room_width * 0.2)
- p = 1;
- else if(bar_width < room_width * 0.1)
- p = 2;
- else
- p = 0;
- }
- else if(ii == 2)
- {
- if(bar_width > room_width * 0.4)
- p = 2;
- else if(bar_width > room_width * 0.2)
- p = 1;
- else if(bar_width < room_width * 0.2)
- p = -1;
- else if(bar_width < room_width * 0.1)
- p = -2;
- else
- p = 0;
- }
- else
- p = -1;
- ds_priority_add(dpl, o, calculate_priority(o, pcsl, p));
- }
- }
- if(ds_priority_size(dpl) > 0)
- {
- fpi = ds_priority_find_max(dpl);
- lpi = ds_priority_find_min(dpl);
- fp = ds_priority_find_priority(dpl, fpi);
- lp = ds_priority_find_priority(dpl, lpi);
- if(fp > 0)
- {
- pr = fpi;
- prp = fp;
- }
- else
- {
- pr = noone;
- prp = 0;
- }
- if(lp < 0)
- {
- av = lpi;
- avp = lp;
- }
- else
- {
- av = noone;
- avp = 0;
- }
- }
- else
- {
- pr = noone;
- av = noone;
- }
- ds_priority_destroy(dpl);
- if(pr != noone && abs(prp) > abs(avp))
- {
- if(pr.object_index == obj_ball)
- {
- if(pr.vspeed < 0)
- x = pursuit_avoid(id, pr, av, 10);
- else
- x = bounce_ball_to_brick(pr, instance_nearest(pr.x, pr.y, obj_brick01));
- }
- else
- x = pr.x;
- }
- else if(av != noone)
- {
- if(pr != noone)
- x = pursuit_avoid(id, pr, av, 10);
- else
- x = avoid(id, av, 10);
- }
- #define lines_intersect
- /// lines_intersect(x1,y1,x2,y2,x3,y3,x4,y4,segment)
- //
- // Returns a vector multiplier (t) for an intersection on the
- // first line. A value of (0 < t <= 1) indicates an intersection
- // within the line segment, a value of 0 indicates no intersection,
- // other values indicate an intersection beyond the endpoints.
- //
- // x1,y1,x2,y2 1st line segment
- // x3,y3,x4,y4 2nd line segment
- // segment If true, confine the test to the line segments.
- //
- // By substituting the return value (t) into the parametric form
- // of the first line, the point of intersection can be determined.
- // eg. x = x1 + t * (x2 - x1)
- // y = y1 + t * (y2 - y1)
- //
- /// GMLscripts.com/license
- {
- var ua, ub, ud, ux, uy, vx, vy, wx, wy;
- ua = 0;
- ux = argument2 - argument0;
- uy = argument3 - argument1;
- vx = argument6 - argument4;
- vy = argument7 - argument5;
- wx = argument0 - argument4;
- wy = argument1 - argument5;
- ud = vy * ux - vx * uy;
- if (ud != 0)
- {
- ua = (vx * wy - vy * wx) / ud;
- if (argument8)
- {
- ub = (ux * wy - uy * wx) / ud;
- if (ua < 0 || ua > 1 || ub < 0 || ub > 1) ua = 0;
- }
- }
- return ua;
- }
- #define pursuit_avoid
- /// pursuit_avoid(inst, pursuit, avoid, separation)
- if(argument0 == noone || argument1 == noone || argument2 == noone)
- return 0;
- var oi = argument0.object_index,
- oa = argument2.object_index,
- iw = 0,
- iwh = 0,
- axs = argument2.x,
- axe = argument2.x,
- ps = argument1.x - argument0.x,
- as = argument2.x - argument0.x,
- tx = argument1.x;
- if(oi == obj_bar)
- {
- iw = argument0.bar_width;
- iwh = iw * 0.5;
- }
- if(oa == obj_bonus)
- {
- axs = argument2.x - 20;
- axe = argument2.x + 20;
- }
- if(axs - argument3 < tx + iwh || axe + argument3 > tx - iwh)
- {
- if(as < 1 || as > -1)
- as = argument1.hspeed;
- if(as >= 0 && axs - argument3 - iwh < iwh)
- as = -1;
- else if(as < 0 && axe + argument3 + iwh > room_width - iwh)
- as = 1;
- if(as > 0)
- return axs - argument3 - iwh;
- else if(as < 0)
- return axe + argument3 + iwh;
- else
- return tx;
- }
- else
- return tx;
- #define avoid
- /// avoid(inst, avoid, separation)
- if(argument0 == noone || argument1 == noone)
- return 0;
- var oi = argument0.object_index,
- oa = argument1.object_index,
- iw = 0,
- iwh = 0,
- axs = argument1.x,
- axe = argument1.x,
- tx = argument0.x,
- as = argument1.x - tx;
- if(oi == obj_bar)
- {
- iw = argument0.bar_width;
- iwh = iw * 0.5;
- }
- if(oa == obj_bonus)
- {
- axs = argument1.x - 20;
- axe = argument1.x + 20;
- }
- if(axs - argument2 < tx + iwh || axe + argument2 > tx - iwh)
- {
- if(as < 1 || as > -1)
- as = argument1.hspeed;
- if(as >= 0 && axs - argument2 - iwh < iwh)
- as = -1;
- else if(as < 0 && axe + argument2 + iwh > room_width - iwh)
- as = 1;
- if(as > 0)
- return axs - argument2 - iwh;
- else if(as < 0)
- return axe + argument2 + iwh;
- else
- return tx;
- }
- else
- return tx;
- #define calculate_priority
- /// calculate_priority(inst, stepsLimit, multiplier)
- var oi, ts, tx, ty, nx, ny, nl, sx, sy, sa;
- var llf = max(room_width, room_height);
- if(argument0 == noone || argument1 <= 0)
- return 0;
- else
- {
- oi = argument0.object_index;
- if(oi == obj_ball)
- {
- if(argument0.vspeed < 0)
- return 0;
- else
- {
- ts = 0;
- tx = argument0.x;
- ty = argument0.y;
- nl = argument0.speed;
- nx = argument0.hspeed / nl;
- ny = argument0.vspeed / nl;
- while(ty < y && ts < argument1)
- {
- tx += nx * nl;
- ty += ny * nl;
- if(tx < 10)
- {
- tx = 10;
- nx *= -1;
- nl += argument0.speed_inc;
- }
- else if(tx > room_width - 10)
- {
- tx = room_width - 10;
- nx *= -1;
- nl += argument0.speed_inc;
- }
- ++ts;
- }
- return (argument1 - ts) * argument2;
- }
- }
- else if(oi == obj_bonus)
- {
- if(argument0.vspeed < 0)
- return 0;
- else
- {
- ts = 0;
- tx = argument0.x;
- ty = argument0.y;
- sa = argument0.gravity;
- sx = argument0.hspeed;
- sy = argument0.vspeed;
- while(ty < y && ts < argument1)
- {
- tx += sx;
- ty += sy;
- if(tx < 10)
- {
- tx = 10;
- sx *= -1;
- }
- if(tx < 10)
- {
- tx = 10;
- sx *= -1;
- }
- sy += sa;
- nl = sx * sx + sy * sy;
- if(nl > 100)
- {
- nl = sqrt(nl);
- nx = sx / nl;
- ny = sy / nl;
- sx = nx * 10;
- sy = ny * 10;
- }
- ++ts;
- }
- return (argument1 - ts) * argument2;
- }
- }
- else
- return 0;
- }
- #define bounce_ball_to_brick
- /// bounce_ball_to_brick(ball, brick)
- if(argument0 == noone || argument1 == noone)
- return 0;
- var bxs, bys, len, bxe, bye, ti, tx, ty, dx, dy, ptx, pty;
- var b = argument0,
- t = argument1,
- llf = max(room_width, room_height),
- pyo = 50,
- phh = 8,
- bhh = 10,
- ptyo = phh + bhh,
- thh = 24,
- tyo = thh + bhh,
- txo = 24,
- pcsl = 100,
- phw = bar_width * 0.5;
- bxs = b.x;
- bys = b.y;
- len = b.speed;
- bxe = bxs + (b.hspeed * llf) / len;
- bye = bys + (b.vspeed * llf) / len;
- ti = lines_intersect(
- bxs, bys, bxe, bye,
- bxs - llf, y - ptyo, bxs + llf, y - ptyo,
- false
- );
- if(ti < 0 || ti > 1)
- return bxs;
- else
- {
- tx = lerp(bxs, bxe, ti);
- ty = lerp(bys, bye, ti);
- dx = tx - t.x - txo;
- dy = ty - t.y - tyo;
- len = sqrt(dx * dx + dy * dy);
- ptx = tx + (dx * llf) / len;
- pty = ty + (dy * llf) / len;
- ti = lines_intersect(
- tx, ty, ptx, pty,
- bxs - llf, y + pyo, bxs + llf, y + pyo,
- false
- );
- if(ti < 0 || ti > 1)
- return tx;
- else
- return lerp(tx, ptx, ti);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement