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