| 1 |
function scr_walk_npc_solidscr_walk_npc_solidfunction scr_walk_npc_solid(arg0, arg1, arg2, arg3, arg4, arg5, arg6)
{
is_walking = true;
actor_speed = arg2;
condition_1 = false;
if (no_loop_destination == false)
{
var destination_x = abs(x - arg0);
var destination_y = abs(y - arg1);
var axis_override = arg4;
if (axis_override == "x" || axis_override == "y")
{
walk_axis = axis_override;
}
else
{
var result = sign(destination_x - destination_y);
switch (result)
{
case 1:
walk_axis = "x";
break;
case -1:
walk_axis = "y";
break;
default:
walk_axis = "y";
}
}
actor_speed_x = sign(arg0 - x) * actor_speed;
actor_speed_y = sign(arg1 - y) * actor_speed;
no_loop_destination = true;
}
if (x == arg0 && y == arg1)
{
no_loop_destination = false;
npc_walking = false;
if (arg5 != "nothing")
npc_direction = arg5;
image_speed = 0;
image_index = 0;
exit;
}
switch (walk_axis)
{
case "x":
x_previous = x;
x += actor_speed_x;
if (abs(arg0 - x) < actor_speed && place_free(arg0, y) && !place_meeting(arg0, y, arg6))
x = arg0;
if (place_free(x, y) && !place_meeting(x, y, arg6) && x_previous != arg0)
{
npc_walking = true;
image_speed = arg3;
if (actor_speed_x == -actor_speed)
npc_direction = "left";
else if (actor_speed_x == actor_speed)
npc_direction = "right";
}
if (!place_free(x, y) || place_meeting(x, y, arg6) || x_previous == arg0)
{
x = x_previous;
walk_axis = "y";
exit;
}
actor_speed_y = sign(arg1 - y) * actor_speed;
i = x + actor_speed_x;
j = y;
if (abs(arg0 - i) < actor_speed)
i = arg0;
while (j != arg1)
{
j += actor_speed_y;
if (abs(arg1 - j) < actor_speed)
j = arg1;
if (!place_free(i, j) || place_meeting(i, j, arg6))
{
condition_1 = true;
break;
}
}
if (condition_1 == true)
{
while (i != arg0)
{
i += actor_speed_x;
j = y;
if (abs(arg0 - i) < actor_speed)
i = arg0;
while (j != arg1)
{
j += actor_speed_y;
if (abs(arg1 - j) < actor_speed)
j = arg1;
if (i == arg0 && j == arg1)
exit;
else if (!place_free(i, j) || place_meeting(i, j, arg6))
break;
else if (j == arg1)
exit;
}
... (arg0, arg1, arg2, arg3, arg4, arg5, arg6) |
| 2 |
{ |
| 3 |
is_walking = true; |
| 4 |
actor_speed = arg2; |
| 5 |
condition_1 = false; |
| 6 |
if (no_loop_destination == false) |
| 7 |
{ |
| 8 |
var destination_x = abs(x - arg0); |
| 9 |
var destination_y = abs(y - arg1); |
| 10 |
var axis_override = arg4; |
| 11 |
if (axis_override == "x" || axis_override == "y") |
| 12 |
{ |
| 13 |
walk_axis = axis_override; |
| 14 |
} |
| 15 |
else |
| 16 |
{ |
| 17 |
var result = sign(destination_x - destination_y); |
| 18 |
switch (result) |
| 19 |
{ |
| 20 |
case 1: |
| 21 |
walk_axis = "x"; |
| 22 |
break; |
| 23 |
case -1: |
| 24 |
walk_axis = "y"; |
| 25 |
break; |
| 26 |
default: |
| 27 |
walk_axis = "y"; |
| 28 |
} |
| 29 |
} |
| 30 |
actor_speed_x = sign(arg0 - x) * actor_speed; |
| 31 |
actor_speed_y = sign(arg1 - y) * actor_speed; |
| 32 |
no_loop_destination = true; |
| 33 |
} |
| 34 |
if (x == arg0 && y == arg1) |
| 35 |
{ |
| 36 |
no_loop_destination = false; |
| 37 |
npc_walking = false; |
| 38 |
if (arg5 != "nothing") |
| 39 |
npc_direction = arg5; |
| 40 |
image_speed = 0; |
| 41 |
image_index = 0; |
| 42 |
exit; |
| 43 |
} |
| 44 |
switch (walk_axis) |
| 45 |
{ |
| 46 |
case "x": |
| 47 |
x_previous = x; |
| 48 |
x += actor_speed_x; |
| 49 |
if (abs(arg0 - x) < actor_speed && place_free(arg0, y) && !place_meeting(arg0, y, arg6)) |
| 50 |
x = arg0; |
| 51 |
if (place_free(x, y) && !place_meeting(x, y, arg6) && x_previous != arg0) |
| 52 |
{ |
| 53 |
npc_walking = true; |
| 54 |
image_speed = arg3; |
| 55 |
if (actor_speed_x == -actor_speed) |
| 56 |
npc_direction = "left"; |
| 57 |
else if (actor_speed_x == actor_speed) |
| 58 |
npc_direction = "right"; |
| 59 |
} |
| 60 |
if (!place_free(x, y) || place_meeting(x, y, arg6) || x_previous == arg0) |
| 61 |
{ |
| 62 |
x = x_previous; |
| 63 |
walk_axis = "y"; |
| 64 |
exit; |
| 65 |
} |
| 66 |
actor_speed_y = sign(arg1 - y) * actor_speed; |
| 67 |
i = x + actor_speed_x; |
| 68 |
j = y; |
| 69 |
if (abs(arg0 - i) < actor_speed) |
| 70 |
i = arg0; |
| 71 |
while (j != arg1) |
| 72 |
{ |
| 73 |
j += actor_speed_y; |
| 74 |
if (abs(arg1 - j) < actor_speed) |
| 75 |
j = arg1; |
| 76 |
if (!place_free(i, j) || place_meeting(i, j, arg6)) |
| 77 |
{ |
| 78 |
condition_1 = true; |
| 79 |
break; |
| 80 |
} |
| 81 |
} |
| 82 |
if (condition_1 == true) |
| 83 |
{ |
| 84 |
while (i != arg0) |
| 85 |
{ |
| 86 |
i += actor_speed_x; |
| 87 |
j = y; |
| 88 |
if (abs(arg0 - i) < actor_speed) |
| 89 |
i = arg0; |
| 90 |
while (j != arg1) |
| 91 |
{ |
| 92 |
j += actor_speed_y; |
| 93 |
if (abs(arg1 - j) < actor_speed) |
| 94 |
j = arg1; |
| 95 |
if (i == arg0 && j == arg1) |
| 96 |
exit; |
| 97 |
else if (!place_free(i, j) || place_meeting(i, j, arg6)) |
| 98 |
break; |
| 99 |
else if (j == arg1) |
| 100 |
exit; |
| 101 |
} |
| 102 |
} |
| 103 |
walk_axis = "y"; |
| 104 |
exit; |
| 105 |
} |
| 106 |
break; |
| 107 |
case "y": |
| 108 |
y_previous = y; |
| 109 |
y += actor_speed_y; |
| 110 |
if (abs(arg1 - y) < actor_speed && place_free(x, arg1) && !place_meeting(x, arg1, arg6)) |
| 111 |
y = arg1; |
| 112 |
if (place_free(x, y) && !place_meeting(x, y, arg6) && y_previous != arg1) |
| 113 |
{ |
| 114 |
npc_walking = true; |
| 115 |
image_speed = arg3; |
| 116 |
if (actor_speed_y == -actor_speed) |
| 117 |
npc_direction = "up"; |
| 118 |
else if (actor_speed_y == actor_speed) |
| 119 |
npc_direction = "down"; |
| 120 |
} |
| 121 |
if (!place_free(x, y) || place_meeting(x, y, arg6) || y_previous == arg1) |
| 122 |
{ |
| 123 |
y = y_previous; |
| 124 |
walk_axis = "x"; |
| 125 |
exit; |
| 126 |
} |
| 127 |
actor_speed_x = sign(arg0 - x) * actor_speed; |
| 128 |
i = x; |
| 129 |
j = y + actor_speed_y; |
| 130 |
if (abs(arg1 - j) < actor_speed) |
| 131 |
j = arg1; |
| 132 |
while (i != arg0) |
| 133 |
{ |
| 134 |
i += actor_speed_x; |
| 135 |
if (abs(arg0 - i) < actor_speed) |
| 136 |
i = arg0; |
| 137 |
if (!place_free(i, j) || place_meeting(i, j, arg6)) |
| 138 |
{ |
| 139 |
condition_1 = true; |
| 140 |
break; |
| 141 |
} |
| 142 |
} |
| 143 |
if (condition_1 == true) |
| 144 |
{ |
| 145 |
while (j != arg1) |
| 146 |
{ |
| 147 |
i = x; |
| 148 |
j += actor_speed_y; |
| 149 |
if (abs(arg1 - j) < actor_speed) |
| 150 |
j = arg1; |
| 151 |
while (i != arg0) |
| 152 |
{ |
| 153 |
i += actor_speed_x; |
| 154 |
if (abs(arg0 - i) < actor_speed) |
| 155 |
i = arg0; |
| 156 |
if (i == arg0 && j == arg1) |
| 157 |
exit; |
| 158 |
else if (!place_free(i, j) || place_meeting(i, j, arg6)) |
| 159 |
break; |
| 160 |
else if (i == arg0) |
| 161 |
exit; |
| 162 |
} |
| 163 |
} |
| 164 |
walk_axis = "x"; |
| 165 |
exit; |
| 166 |
} |
| 167 |
break; |
| 168 |
} |
| 169 |
if (x == arg0 && y == arg1) |
| 170 |
{ |
| 171 |
no_loop_destination = false; |
| 172 |
npc_walking = false; |
| 173 |
is_walking = false; |
| 174 |
if (arg5 != "nothing") |
| 175 |
npc_direction = arg5; |
| 176 |
image_speed = 0; |
| 177 |
image_index = 0; |
| 178 |
return true; |
| 179 |
} |
| 180 |
} |