Deltarune (Chapter 3) script viewer

← back to main script listing

gml_Object_obj_caterpillar_board_Step_0

(view raw script w/o annotations or w/e)
1
if (i_ex(obj_board_controller))
2
    obj_board_controller.phase = 3;
3
wallcheck = 0;
4
nowx = x;
5
nowy = y;
6
bkx = 0;
7
bky = 0;
8
bkxy = 0;
9
aitimer++;
10
if ((aitimer % 8) == 0)
11
{
12
    var movedir = choose(0, 0, 0, 0, 0, 1, 2, 3, 4);
13
    switch (movedir)
14
    {
15
        case 0:
16
            press_l = 0;
17
            press_r = 0;
18
            press_d = 0;
19
            press_u = 0;
20
            nopress = 1;
21
            break;
22
        case 1:
23
            press_l = 1;
24
            press_r = 0;
25
            press_d = 0;
26
            press_u = 0;
27
            break;
28
        case 2:
29
            press_l = 0;
30
            press_r = 1;
31
            press_d = 0;
32
            press_u = 0;
33
            break;
34
        case 3:
35
            press_l = 0;
36
            press_r = 0;
37
            press_d = 1;
38
            press_u = 0;
39
            break;
40
        case 4:
41
            press_l = 0;
42
            press_r = 0;
43
            press_d = 0;
44
            press_u = 1;
45
            break;
46
    }
47
}
48
if (global.interact == 0 && canfreemove == 1)
49
{
50
    px = 0;
51
    py = 0;
52
    pressdir = -1;
53
    if (press_r == 1)
54
    {
55
        px = wspeed;
56
        pressdir = 1;
57
    }
58
    if (press_l == 1)
59
    {
60
        px = -wspeed;
61
        pressdir = 3;
62
    }
63
    if (press_d == 1)
64
    {
65
        py = wspeed;
66
        pressdir = 0;
67
    }
68
    if (press_u == 1)
69
    {
70
        py = -wspeed;
71
        pressdir = 2;
72
    }
73
    if (nopress == 1 && pressdir != -1)
74
        facing = pressdir;
75
    if (facing == 2)
76
    {
77
        if (press_d == 1)
78
            facing = 0;
79
        if (press_u == 0 && pressdir != -1)
80
            facing = pressdir;
81
    }
82
    if (facing == 0)
83
    {
84
        if (press_u == 1)
85
            facing = 2;
86
        if (press_d == 0 && pressdir != -1)
87
            facing = pressdir;
88
    }
89
    if (facing == 3)
90
    {
91
        if (press_r == 1)
92
            facing = 1;
93
        if (press_l == 0 && pressdir != -1)
94
            facing = pressdir;
95
    }
96
    if (facing == 1)
97
    {
98
        if (press_l == 1)
99
            facing = 3;
100
        if (press_r == 0 && pressdir != -1)
101
            facing = pressdir;
102
    }
103
    nopress = 0;
104
    xmeet = 0;
105
    ymeet = 0;
106
    xymeet = 0;
107
    if (place_meeting(x + px, y + py, obj_board_solid))
108
        xymeet = 1;
109
    if (place_meeting(x + px, y, obj_board_solid))
110
    {
111
        if (place_meeting(x + px, y, obj_board_solid))
112
        {
113
            for (g = wspeed; g > 0; g -= 1)
114
            {
115
                mvd = 0;
116
                if (press_d == 0 && !place_meeting(x + px, y - g, obj_board_solid))
117
                {
118
                    y -= g;
119
                    py = 0;
120
                    break;
121
                    mvd = 1;
122
                }
123
                if (press_u == 0 && mvd == 0 && !place_meeting(x + px, y + g, obj_board_solid))
124
                {
125
                    y += g;
126
                    py = 0;
127
                    break;
128
                }
129
            }
130
        }
131
        xmeet = 1;
132
        bkx = 0;
133
        if (px > 0)
134
        {
135
            for (i = px; i >= 0; i -= 1)
136
            {
137
                if (!place_meeting(x + i, y, obj_board_solid))
138
                {
139
                    px = i;
140
                    bkx = 1;
141
                    break;
142
                }
143
            }
144
        }
145
        if (px < 0)
146
        {
147
            for (i = px; i <= 0; i += 1)
148
            {
149
                if (!place_meeting(x + i, y, obj_board_solid))
150
                {
151
                    px = i;
152
                    bkx = 1;
153
                    break;
154
                }
155
            }
156
        }
157
        if (bkx == 0)
158
            px = 0;
159
    }
160
    if (place_meeting(x, y + py, obj_board_solid))
161
    {
162
        ymeet = 1;
163
        bky = 0;
164
        if (place_meeting(x, y + py, obj_board_solid))
165
        {
166
            for (g = wspeed; g > 0; g -= 1)
167
            {
168
                mvd = 0;
169
                if (press_r == 0 && !place_meeting(x - g, y + py, obj_board_solid))
170
                {
171
                    x -= g;
172
                    px = 0;
173
                    break;
174
                    mvd = 1;
175
                }
176
                if (mvd == 0 && press_l == 0 && !place_meeting(x + g, y + py, obj_board_solid))
177
                {
178
                    x += g;
179
                    px = 0;
180
                    break;
181
                }
182
            }
183
        }
184
        if (py > 0)
185
        {
186
            for (i = py; i >= 0; i -= 1)
187
            {
188
                if (!place_meeting(x, y + i, obj_board_solid))
189
                {
190
                    py = i;
191
                    bky = 1;
192
                    break;
193
                }
194
            }
195
        }
196
        if (py < 0)
197
        {
198
            for (i = py; i <= 0; i += 1)
199
            {
200
                if (!place_meeting(x, y + i, obj_board_solid))
201
                {
202
                    py = i;
203
                    bky = 1;
204
                    break;
205
                }
206
            }
207
        }
208
        if (bky == 0)
209
            py = 0;
210
    }
211
    if (place_meeting(x + px, y + py, obj_board_solid))
212
    {
213
        xymeet = 1;
214
        bkxy = 0;
215
        i = px;
216
        j = py;
217
        while (j != 0 || i != 0)
218
        {
219
            if (!place_meeting(x + i, y + j, obj_board_solid))
220
            {
221
                px = i;
222
                py = j;
223
                bkxy = 1;
224
                break;
225
            }
226
            if (abs(j) >= 1)
227
            {
228
                if (j > 0)
229
                    j -= 1;
230
                if (j < 0)
231
                    j += 1;
232
            }
233
            else
234
            {
235
                j = 0;
236
            }
237
            if (abs(i) >= 1)
238
            {
239
                if (i > 0)
240
                    i -= 1;
241
                if (i < 0)
242
                    i += 1;
243
            }
244
            else
245
            {
246
                i = 0;
247
            }
248
        }
249
        if (bkxy == 0)
250
        {
251
            px = 0;
252
            py = 0;
253
        }
254
    }
255
    x += px;
256
    y += py;
257
}
258
if (fun == 0)
259
{
260
    walk = 0;
261
    if (x != nowx && nopress == 0)
262
        walk = 1;
263
    if (y != nowy && nopress == 0)
264
        walk = 1;
265
    if (walk == 1)
266
        walkbuffer = 6;
267
    if (walkbuffer > 3)
268
    {
269
        walktimer += 1.5;
270
        if (walktimer >= 40)
271
            walktimer -= 40;
272
        if (walktimer < 10)
273
            image_index = 0;
274
        if (walktimer >= 10)
275
            image_index = 1;
276
        if (walktimer >= 20)
277
            image_index = 2;
278
        if (walktimer >= 30)
279
            image_index = 3;
280
    }
281
    if (walkbuffer <= 0 && fun == 0)
282
    {
283
        if (walktimer < 10)
284
            walktimer = 9.5;
285
        if (walktimer >= 10 && walktimer < 20)
286
            walktimer = 19.5;
287
        if (walktimer >= 20 && walktimer < 30)
288
            walktimer = 29.5;
289
        if (walktimer >= 30)
290
            walktimer = 39.5;
291
        image_index = 0;
292
    }
293
    walkbuffer -= 0.75;
294
    if (name == "susie")
295
    {
296
        if (facing == 0)
297
            sprite_index = spr_board_susie_walk_down;
298
        if (facing == 1)
299
            sprite_index = spr_board_susie_walk_right;
300
        if (facing == 2)
301
            sprite_index = spr_board_susie_walk_up;
302
        if (facing == 3)
303
            sprite_index = spr_board_susie_walk_left;
304
    }
305
    if (name == "ralsei")
306
    {
307
        if (facing == 0)
308
            sprite_index = spr_board_ralsei_walk_down;
309
        if (facing == 1)
310
            sprite_index = spr_board_ralsei_walk_right;
311
        if (facing == 2)
312
            sprite_index = spr_board_ralsei_walk_up;
313
        if (facing == 3)
314
            sprite_index = spr_board_ralsei_walk_left;
315
    }
316
}
317
if (button2_p() && sword == true && swordbuffer <= 0 && onebuffer <= 0 && global.interact == 0)
318
{
319
    swordbuffer = 8;
320
    swordfacing = facing;
321
    canfreemove = 0;
322
}
323
if (swordbuffer > 0)
324
{
325
    swordbuffer--;
326
    facing = swordfacing;
327
    if (facing == 0)
328
        sprite_index = spr_board_kris_strike_down;
329
    if (facing == 1)
330
        sprite_index = spr_board_kris_strike_right;
331
    if (facing == 2)
332
        sprite_index = spr_board_kris_strike_up;
333
    if (facing == 3)
334
        sprite_index = spr_board_kris_strike_left;
335
    if (swordbuffer == 7)
336
        image_index = 0;
337
    if (swordbuffer == 6)
338
        image_index = 0;
339
    if (swordbuffer == 5)
340
        image_index = 1;
341
    if (swordbuffer == 4)
342
        image_index = 1;
343
    if (swordbuffer == 3)
344
        image_index = 1;
345
    if (swordbuffer == 2)
346
        image_index = 2;
347
    if (swordbuffer == 1)
348
        image_index = 0;
349
    if (swordbuffer == 0)
350
        canfreemove = 1;
351
    if (swordbuffer == 5)
352
    {
353
        var swordhitbox = instance_create(x, y, obj_board_swordhitbox);
354
        swordhitbox.facing = facing;
355
        swordhitbox.swordlv = swordlv;
356
    }
357
}