Deltarune (Chapter 1) script viewer

← back to main script listing

gml_Object_obj_mainchara_Step_0

(view raw script w/o annotations or w/e)
1
scr_depth
scr_depth

function
scr_depth()
{ depth = 100000 - ((y * 10) + (sprite_height * 10)); }
();
2
wallcheck = 0;
3
nowx = x;
4
nowy = y;
5
var nopress = 0;
6
if (press_d == 0 && press_l == 0 && press_u == 0 && press_r == 0)
7
    nopress = 1;
8
press_l = 0;
9
press_r = 0;
10
press_d = 0;
11
press_u = 0;
12
bkx = 0;
13
bky = 0;
14
bkxy = 0;
15
jelly = 2;
16
if (global.interact == 0)
17
{
18
    if (button3_p() && threebuffer < 0)
19
    {
20
        if (global.flag[7 disable_menu?] == 0 && battlemode == 0)
21
        {
22
            with (obj_darkcontroller)
23
                threebuffer = 2;
24
            with (obj_overworldc)
25
            {
26
                movenoise = 1;
27
                threebuffer = 2;
28
            }
29
            global.menuno = 0;
30
            global.interact = 5;
31
            threebuffer = 2;
32
            twobuffer = 2;
33
        }
34
    }
35
    if (global.flag[11 auto_run] == 1)
36
    {
37
        if (button2_h() && twobuffer < 0)
38
            run = 0;
39
        else
40
            run = 1;
41
    }
42
    else if (button2_h() && twobuffer < 0)
43
    {
44
        run = 1;
45
    }
46
    else
47
    {
48
        run = 0;
49
    }
50
    if (autorun > 0)
51
    {
52
        if (autorun == 1)
53
        {
54
            run = 1;
55
            runtimer = 200;
56
        }
57
        if (autorun == 2)
58
        {
59
            run = 1;
60
            runtimer = 50;
61
        }
62
    }
63
    if (run == 1)
64
    {
65
        if (darkmode == 0)
66
        {
67
            wspeed = bwspeed + 1;
68
            if (runtimer > 10)
69
                wspeed = bwspeed + 2;
70
            if (runtimer > 60)
71
                wspeed = bwspeed + 3;
72
        }
73
        if (darkmode == 1)
74
        {
75
            wspeed = bwspeed + 2;
76
            if (runtimer > 10)
77
                wspeed = bwspeed + 4;
78
            if (runtimer > 60)
79
                wspeed = bwspeed + 5;
80
        }
81
    }
82
    if (run == 0)
83
        wspeed = bwspeed;
84
    if (left_h())
85
        press_l = 1;
86
    if (right_h())
87
        press_r = 1;
88
    if (up_h())
89
        press_u = 1;
90
    if (down_h())
91
        press_d = 1;
92
    px = 0;
93
    py = 0;
94
    pressdir = -1;
95
    if (press_r == 1)
96
    {
97
        px = wspeed;
98
        pressdir = 1;
99
    }
100
    if (press_l == 1)
101
    {
102
        px = -wspeed;
103
        pressdir = 3;
104
    }
105
    if (press_d == 1)
106
    {
107
        py = wspeed;
108
        pressdir = 0;
109
    }
110
    if (press_u == 1)
111
    {
112
        py = -wspeed;
113
        pressdir = 2;
114
    }
115
    if (nopress == 1 && pressdir != -1)
116
        global.facing = pressdir;
117
    if (global.facing == 2)
118
    {
119
        if (press_d == 1)
120
            global.facing = 0;
121
        if (press_u == 0 && pressdir != -1)
122
            global.facing = pressdir;
123
    }
124
    if (global.facing == 0)
125
    {
126
        if (press_u == 1)
127
            global.facing = 2;
128
        if (press_d == 0 && pressdir != -1)
129
            global.facing = pressdir;
130
    }
131
    if (global.facing == 3)
132
    {
133
        if (press_r == 1)
134
            global.facing = 1;
135
        if (press_l == 0 && pressdir != -1)
136
            global.facing = pressdir;
137
    }
138
    if (global.facing == 1)
139
    {
140
        if (press_l == 1)
141
            global.facing = 3;
142
        if (press_r == 0 && pressdir != -1)
143
            global.facing = pressdir;
144
    }
145
    nopress = 0;
146
    xmeet = 0;
147
    ymeet = 0;
148
    xymeet = 0;
149
    if (place_meeting(x + px, y, obj_solidblock))
150
    {
151
        for (var g = wspeed; g > 0; g -= 1)
152
        {
153
            var mvd = 0;
154
            if (press_d == 0 && !place_meeting(x + px, y - g, obj_solidblock))
155
            {
156
                y -= g;
157
                py = 0;
158
                break;
159
            }
160
            else
161
            {
162
                mvd = 1;
163
            }
164
            if (press_u == 0 && mvd == 0 && !place_meeting(x + px, y + g, obj_solidblock))
165
            {
166
                y += g;
167
                py = 0;
168
                break;
169
            }
170
        }
171
        xmeet = 1;
172
        bkx = 0;
173
        if (px > 0)
174
        {
175
            for (var i = px; i >= 0; i -= 1)
176
            {
177
                if (!place_meeting(x + i, y, obj_solidblock))
178
                {
179
                    px = i;
180
                    bkx = 1;
181
                    break;
182
                }
183
            }
184
        }
185
        if (px < 0)
186
        {
187
            for (var i = px; i <= 0; i += 1)
188
            {
189
                if (!place_meeting(x + i, y, obj_solidblock))
190
                {
191
                    px = i;
192
                    bkx = 1;
193
                    break;
194
                }
195
            }
196
        }
197
        if (bkx == 0)
198
            px = 0;
199
    }
200
    else if (place_meeting(x, y + py, obj_solidblock))
201
    {
202
        ymeet = 1;
203
        bky = 0;
204
        for (var g = wspeed; g > 0; g -= 1)
205
        {
206
            var mvd = 0;
207
            if (press_r == 0 && !place_meeting(x - g, y + py, obj_solidblock))
208
            {
209
                x -= g;
210
                px = 0;
211
                break;
212
            }
213
            else
214
            {
215
                mvd = 1;
216
            }
217
            if (mvd == 0 && press_l == 0 && !place_meeting(x + g, y + py, obj_solidblock))
218
            {
219
                x += g;
220
                px = 0;
221
                break;
222
            }
223
        }
224
        if (py > 0)
225
        {
226
            for (var i = py; i >= 0; i -= 1)
227
            {
228
                if (!place_meeting(x, y + i, obj_solidblock))
229
                {
230
                    py = i;
231
                    bky = 1;
232
                    break;
233
                }
234
            }
235
        }
236
        if (py < 0)
237
        {
238
            for (var i = py; i <= 0; i += 1)
239
            {
240
                if (!place_meeting(x, y + i, obj_solidblock))
241
                {
242
                    py = i;
243
                    bky = 1;
244
                    break;
245
                }
246
            }
247
        }
248
        if (bky == 0)
249
            py = 0;
250
    }
251
    if (place_meeting(x + px, y + py, obj_solidblock))
252
    {
253
        xymeet = 1;
254
        bkxy = 0;
255
        var i = px;
256
        var j = py;
257
        while (j != 0 || i != 0)
258
        {
259
            if (!place_meeting(x + i, y + j, obj_solidblock))
260
            {
261
                px = i;
262
                py = j;
263
                bkxy = 1;
264
                break;
265
            }
266
            if (abs(j) >= 1)
267
            {
268
                if (j > 0)
269
                    j -= 1;
270
                if (j < 0)
271
                    j += 1;
272
            }
273
            else
274
            {
275
                j = 0;
276
            }
277
            if (abs(i) >= 1)
278
            {
279
                if (i > 0)
280
                    i -= 1;
281
                if (i < 0)
282
                    i += 1;
283
            }
284
            else
285
            {
286
                i = 0;
287
            }
288
        }
289
        if (bkxy == 0)
290
        {
291
            px = 0;
292
            py = 0;
293
        }
294
    }
295
    runmove = 0;
296
    if (run == 1 && xmeet == 0 && ymeet == 0 && xymeet == 0)
297
    {
298
        if (abs(px) > 0 || abs(py) > 0)
299
        {
300
            runmove = 1;
301
            runtimer += 1;
302
        }
303
        else
304
        {
305
            runtimer = 0;
306
        }
307
    }
308
    else
309
    {
310
        runtimer = 0;
311
    }
312
    x += px;
313
    y += py;
314
}
315
walk = 0;
316
if (x != nowx && nopress == 0)
317
    walk = 1;
318
if (y != nowy && nopress == 0)
319
    walk = 1;
320
if (walk == 1)
321
    walkbuffer = 6;
322
if (walkbuffer > 3 && fun == 0)
323
{
324
    walktimer += 1.5;
325
    if (runmove == 1)
326
        walktimer += 1.5;
327
    if (walktimer >= 40)
328
        walktimer -= 40;
329
    if (walktimer < 10)
330
        image_index = 0;
331
    if (walktimer >= 10)
332
        image_index = 1;
333
    if (walktimer >= 20)
334
        image_index = 2;
335
    if (walktimer >= 30)
336
        image_index = 3;
337
}
338
else if (walkbuffer <= 0 && fun == 0)
339
{
340
    if (walktimer < 10)
341
        walktimer = 9.5;
342
    if (walktimer >= 10 && walktimer < 20)
343
        walktimer = 19.5;
344
    if (walktimer >= 20 && walktimer < 30)
345
        walktimer = 29.5;
346
    if (walktimer >= 30)
347
        walktimer = 39.5;
348
    image_index = 0;
349
}
350
walkbuffer -= 0.75;
351
if (fun == 0)
352
{
353
    if (global.facing == 0)
354
        sprite_index = dsprite;
355
    if (global.facing == 1)
356
        sprite_index = rsprite;
357
    if (global.facing == 2)
358
        sprite_index = usprite;
359
    if (global.facing == 3)
360
        sprite_index = lsprite;
361
}
362
if (stepping == 1)
363
{
364
    if (image_index == 1 && stepped == 0)
365
    {
366
        if (global.flag[31 disable_loud_steps] == 0)
367
        {
368
            snd_play(snd_step1);
369
            stepped = 1;
370
        }
371
    }
372
    else if (image_index == 0 || image_index == 2)
373
    {
374
        stepped = 0;
375
    }
376
    else if (image_index == 3 && stepped == 0)
377
    {
378
        stepped = 1;
379
        if (global.flag[31 disable_loud_steps] == 0)
380
            snd_play(snd_step2);
381
    }
382
}
383
if (onebuffer < 0)
384
{
385
    if (global.interact == 0)
386
    {
387
        if (button1_p())
388
        {
389
            thisinteract = 0;
390
            d = global.darkzone + 1;
391
            if (global.facing == 1)
392
            {
393
                if (collision_rectangle(x + (sprite_width / 2), y + (6 * d) + (sprite_height / 2), x + sprite_width + (13 * d), y + sprite_height, obj_interactable, false, true))
394
                    thisinteract = 1;
395
                if (collision_rectangle(x + (sprite_width / 2), y + (6 * d) + (sprite_height / 2), x + sprite_width + (13 * d), y + sprite_height, obj_interactablesolid, false, true))
396
                    thisinteract = 2;
397
            }
398
            if (thisinteract > 0)
399
            {
400
                if (thisinteract == 1)
401
                    interactedobject = collision_rectangle(x + (sprite_width / 2), y + (6 * d) + (sprite_height / 2), x + sprite_width + (13 * d), y + sprite_height, obj_interactable, false, true);
402
                if (thisinteract == 2)
403
                    interactedobject = collision_rectangle(x + (sprite_width / 2), y + (6 * d) + (sprite_height / 2), x + sprite_width + (13 * d), y + sprite_height, obj_interactablesolid, false, true);
404
                if (interactedobject != -4)
405
                {
406
                    with (interactedobject)
407
                        facing = 3;
408
                    with (interactedobject)
409
                        
scr_interact
scr_interact

function
scr_interact()
{ myinteract = 1; event_user(0); }
();
410
                }
411
            }
412
            thisinteract = 0;
413
            if (global.facing == 3)
414
            {
415
                if (collision_rectangle(x + (sprite_width / 2), y + (6 * d) + (sprite_height / 2), x - (13 * d), y + sprite_height, obj_interactable, false, true))
416
                    thisinteract = 1;
417
                if (collision_rectangle(x + (sprite_width / 2), y + (6 * d) + (sprite_height / 2), x - (13 * d), y + sprite_height, obj_interactablesolid, false, true))
418
                    thisinteract = 2;
419
            }
420
            if (thisinteract > 0)
421
            {
422
                if (thisinteract == 1)
423
                    interactedobject = collision_rectangle(x + (sprite_width / 2), y + (6 * d) + (sprite_height / 2), x - (13 * d), y + sprite_height, obj_interactable, false, true);
424
                if (thisinteract == 2)
425
                    interactedobject = collision_rectangle(x + (sprite_width / 2), y + (6 * d) + (sprite_height / 2), x - (13 * d), y + sprite_height, obj_interactablesolid, false, true);
426
                if (interactedobject != -4)
427
                {
428
                    with (interactedobject)
429
                        facing = 1;
430
                    with (interactedobject)
431
                        
scr_interact
scr_interact

function
scr_interact()
{ myinteract = 1; event_user(0); }
();
432
                }
433
            }
434
            thisinteract = 0;
435
            if (global.facing == 0)
436
            {
437
                if (collision_rectangle(x + (4 * d), y + (28 * d), (x + sprite_width) - (4 * d), y + sprite_height + (15 * d), obj_interactable, false, true))
438
                    thisinteract = 1;
439
                if (collision_rectangle(x + (4 * d), y + (28 * d), (x + sprite_width) - (4 * d), y + sprite_height + (15 * d), obj_interactablesolid, false, true))
440
                    thisinteract = 2;
441
            }
442
            if (thisinteract > 0)
443
            {
444
                if (thisinteract == 1)
445
                    interactedobject = collision_rectangle(x + (4 * d), y + (28 * d), (x + sprite_width) - (4 * d), y + sprite_height + (15 * d), obj_interactable, false, true);
446
                if (thisinteract == 2)
447
                    interactedobject = collision_rectangle(x + (4 * d), y + (28 * d), (x + sprite_width) - (4 * d), y + sprite_height + (15 * d), obj_interactablesolid, false, true);
448
                if (interactedobject != -4)
449
                {
450
                    with (interactedobject)
451
                        facing = 2;
452
                    with (interactedobject)
453
                        
scr_interact
scr_interact

function
scr_interact()
{ myinteract = 1; event_user(0); }
();
454
                }
455
            }
456
            thisinteract = 0;
457
            if (global.facing == 2)
458
            {
459
                if (collision_rectangle(x + 3, (y + sprite_height) - (5 * d), (x + sprite_width) - (5 * d), y + (5 * d), obj_interactable, false, true))
460
                    thisinteract = 1;
461
                if (collision_rectangle(x + 3, (y + sprite_height) - (5 * d), (x + sprite_width) - (5 * d), y + (5 * d), obj_interactablesolid, false, true))
462
                    thisinteract = 2;
463
            }
464
            if (thisinteract > 0)
465
            {
466
                if (thisinteract == 1)
467
                    interactedobject = collision_rectangle(x + (3 * d), (y + sprite_height) - (5 * d), (x + sprite_width) - (5 * d), y + (5 * d), obj_interactable, false, true);
468
                if (thisinteract == 2)
469
                    interactedobject = collision_rectangle(x + (3 * d), (y + sprite_height) - (5 * d), (x + sprite_width) - (5 * d), y + (5 * d), obj_interactablesolid, false, true);
470
                if (interactedobject != -4)
471
                {
472
                    with (interactedobject)
473
                        facing = 0;
474
                    with (interactedobject)
475
                        
scr_interact
scr_interact

function
scr_interact()
{ myinteract = 1; event_user(0); }
();
476
                }
477
            }
478
        }
479
    }
480
}
481
onebuffer -= 1;
482
twobuffer -= 1;
483
threebuffer -= 1;
484
with (collision_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom, obj_doorparent, 0, 0))
485
    event_user(9);
486
if (battlemode == 1)
487
{
488
    global.inv -= 1;
489
    if (global.inv < 0 && global.interact != 3)
490
    {
491
        with (collision_rectangle(x + 12, y + 40, x + 27, y + 49, obj_overworldbulletparent, 1, 0))
492
            event_user(5);
493
        with (collision_line(x + 12, y + 49, x + 19, y + 57, obj_overworldbulletparent, 1, 0))
494
            event_user(5);
495
        with (collision_line(x + 26, y + 49, x + 19, y + 57, obj_overworldbulletparent, 1, 0))
496
            event_user(5);
497
    }
498
}