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