Deltarune (Chapter 2) 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
if (press_d == 0 && press_l == 0 && press_u == 0 && press_r == 0)
6
    nopress = 1;
7
press_l = 0;
8
press_r = 0;
9
press_d = 0;
10
press_u = 0;
11
bkx = 0;
12
bky = 0;
13
bkxy = 0;
14
jelly = 2;
15
if (!roomenterfreezeend)
16
{
17
    if (global.interact == 3)
18
    {
19
        if (global.flag[21 door_freeze_timer] > 0)
20
        {
21
            global.flag[21 door_freeze_timer]--;
22
        }
23
        else
24
        {
25
            roomenterfreezeend = 1;
26
            global.interact = 0;
27
            global.flag[21 door_freeze_timer] = -10;
28
        }
29
    }
30
}
31
if (global.interact == 0)
32
{
33
    if (button3_p() && threebuffer < 0)
34
    {
35
        if (global.flag[7 disable_menu?] == 0 && battlemode == 0 && swordmode == 0)
36
        {
37
            with (obj_darkcontroller)
38
                threebuffer = 2;
39
            with (obj_overworldc)
40
            {
41
                movenoise = 1;
42
                threebuffer = 2;
43
            }
44
            global.menuno = 0;
45
            global.interact = 5;
46
            threebuffer = 2;
47
            twobuffer = 2;
48
        }
49
    }
50
}
51
if (swordcon == 1)
52
{
53
    swordtimer++;
54
    if (swordtimer >= 15)
55
    {
56
        with (slashmarker)
57
            instance_destroy();
58
        swordcon = 0;
59
        swordsprite = rsprite;
60
        fun = 0;
61
        if (global.interact == 4)
62
            global.interact = 0;
63
        swordtimer = 0;
64
        image_speed = 0;
65
        image_index = 0;
66
        image_alpha = 1;
67
    }
68
}
69
if (global.interact == 0)
70
{
71
    if (global.flag[11 auto_run] == 1)
72
    {
73
        if (button2_h() && twobuffer < 0)
74
            run = 0;
75
        else
76
            run = 1;
77
    }
78
    else if (button2_h() && twobuffer < 0)
79
    {
80
        run = 1;
81
    }
82
    else
83
    {
84
        run = 0;
85
    }
86
    if (autorun > 0)
87
    {
88
        if (autorun == 1)
89
        {
90
            run = 1;
91
            runtimer = 200;
92
        }
93
        if (autorun == 2)
94
        {
95
            run = 1;
96
            runtimer = 50;
97
        }
98
    }
99
    if (run == 1)
100
    {
101
        if (darkmode == 0)
102
        {
103
            wspeed = bwspeed + 1;
104
            if (runtimer > 10)
105
                wspeed = bwspeed + 2;
106
            if (runtimer > 60)
107
                wspeed = bwspeed + 3;
108
        }
109
        if (darkmode == 1)
110
        {
111
            wspeed = bwspeed + 2;
112
            if (runtimer > 10)
113
                wspeed = bwspeed + 4;
114
            if (runtimer > 60)
115
                wspeed = bwspeed + 5;
116
        }
117
    }
118
    if (run == 0)
119
        wspeed = bwspeed;
120
    if (left_h())
121
        press_l = 1;
122
    if (right_h())
123
        press_r = 1;
124
    if (up_h())
125
        press_u = 1;
126
    if (down_h())
127
        press_d = 1;
128
    px = 0;
129
    py = 0;
130
    pressdir = -1;
131
    if (press_r == 1)
132
    {
133
        px = wspeed;
134
        pressdir = 1;
135
    }
136
    if (press_l == 1)
137
    {
138
        px = -wspeed;
139
        pressdir = 3;
140
    }
141
    if (press_d == 1)
142
    {
143
        py = wspeed;
144
        pressdir = 0;
145
    }
146
    if (press_u == 1)
147
    {
148
        py = -wspeed;
149
        pressdir = 2;
150
    }
151
    if (nopress == 1 && pressdir != -1)
152
        global.facing = pressdir;
153
    if (global.facing == 2)
154
    {
155
        if (press_d == 1)
156
            global.facing = 0;
157
        if (press_u == 0 && pressdir != -1)
158
            global.facing = pressdir;
159
    }
160
    if (global.facing == 0)
161
    {
162
        if (press_u == 1)
163
            global.facing = 2;
164
        if (press_d == 0 && pressdir != -1)
165
            global.facing = pressdir;
166
    }
167
    if (global.facing == 3)
168
    {
169
        if (press_r == 1)
170
            global.facing = 1;
171
        if (press_l == 0 && pressdir != -1)
172
            global.facing = pressdir;
173
    }
174
    if (global.facing == 1)
175
    {
176
        if (press_l == 1)
177
            global.facing = 3;
178
        if (press_r == 0 && pressdir != -1)
179
            global.facing = pressdir;
180
    }
181
    if (press_r == 1)
182
        swordfacing = 1;
183
    if (press_l == 1)
184
        swordfacing = -1;
185
    if (swordmode == 1)
186
    {
187
        if (button1_p() && swordcon == 0 && global.interact == 0)
188
        {
189
            global.interact = 4;
190
            swordsprite = rsprite;
191
            slashmarker = 
scr_dark_marker
scr_dark_marker

function
scr_dark_marker(arg0, arg1, arg2)
{ thismarker = instance_create(arg0, arg1, obj_marker); with (thismarker) { sprite_index = arg2; image_speed = 0; image_xscale = 2; image_yscale = 2; } return thismarker; }
(x, y, rsprite);
192
            slashmarker.depth = depth;
193
            slashmarker.image_speed = 1;
194
            if (swordfacing == -1)
195
            {
196
                slashmarker.x += sprite_width;
197
                slashmarker.image_xscale = -image_xscale;
198
            }
199
            image_alpha = 0;
200
            fun = 1;
201
            snd_play(snd_laz_c);
202
            image_index = 0;
203
            image_speed = 0.5;
204
            swordtimer = 0;
205
            swordcon = 1;
206
            press_l = 0;
207
            press_r = 0;
208
            press_u = 0;
209
            press_d = 0;
210
            swordhitbox = instance_create(slashmarker.x, slashmarker.y, obj_swordhitbox);
211
            swordhitbox.image_xscale = slashmarker.image_xscale;
212
            swordhitbox.image_yscale = image_yscale;
213
        }
214
    }
215
    nopress = 0;
216
    xmeet = 0;
217
    ymeet = 0;
218
    xymeet = 0;
219
    if (place_meeting(x + px, y + py, obj_solidblock))
220
        xymeet = 1;
221
    if (place_meeting(x + px, y, obj_solidblock))
222
    {
223
        if (place_meeting(x + px, y, obj_solidblock))
224
        {
225
            for (g = wspeed; g > 0; g -= 1)
226
            {
227
                mvd = 0;
228
                if (press_d == 0 && !place_meeting(x + px, y - g, obj_solidblock))
229
                {
230
                    y -= g;
231
                    py = 0;
232
                    break;
233
                    mvd = 1;
234
                }
235
                if (press_u == 0 && mvd == 0 && !place_meeting(x + px, y + g, obj_solidblock))
236
                {
237
                    y += g;
238
                    py = 0;
239
                    break;
240
                }
241
            }
242
        }
243
        xmeet = 1;
244
        bkx = 0;
245
        if (px > 0)
246
        {
247
            for (i = px; i >= 0; i -= 1)
248
            {
249
                if (!place_meeting(x + i, y, obj_solidblock))
250
                {
251
                    px = i;
252
                    bkx = 1;
253
                    break;
254
                }
255
            }
256
        }
257
        if (px < 0)
258
        {
259
            for (i = px; i <= 0; i += 1)
260
            {
261
                if (!place_meeting(x + i, y, obj_solidblock))
262
                {
263
                    px = i;
264
                    bkx = 1;
265
                    break;
266
                }
267
            }
268
        }
269
        if (bkx == 0)
270
            px = 0;
271
    }
272
    if (place_meeting(x, y + py, obj_solidblock))
273
    {
274
        ymeet = 1;
275
        bky = 0;
276
        if (place_meeting(x, y + py, obj_solidblock))
277
        {
278
            for (g = wspeed; g > 0; g -= 1)
279
            {
280
                mvd = 0;
281
                if (press_r == 0 && !place_meeting(x - g, y + py, obj_solidblock))
282
                {
283
                    x -= g;
284
                    px = 0;
285
                    break;
286
                    mvd = 1;
287
                }
288
                if (mvd == 0 && press_l == 0 && !place_meeting(x + g, y + py, obj_solidblock))
289
                {
290
                    x += g;
291
                    px = 0;
292
                    break;
293
                }
294
            }
295
        }
296
        if (py > 0)
297
        {
298
            for (i = py; i >= 0; i -= 1)
299
            {
300
                if (!place_meeting(x, y + i, obj_solidblock))
301
                {
302
                    py = i;
303
                    bky = 1;
304
                    break;
305
                }
306
            }
307
        }
308
        if (py < 0)
309
        {
310
            for (i = py; i <= 0; i += 1)
311
            {
312
                if (!place_meeting(x, y + i, obj_solidblock))
313
                {
314
                    py = i;
315
                    bky = 1;
316
                    break;
317
                }
318
            }
319
        }
320
        if (bky == 0)
321
            py = 0;
322
    }
323
    if (place_meeting(x + px, y + py, obj_solidblock))
324
    {
325
        xymeet = 1;
326
        bkxy = 0;
327
        i = px;
328
        j = py;
329
        while (j != 0 || i != 0)
330
        {
331
            if (!place_meeting(x + i, y + j, obj_solidblock))
332
            {
333
                px = i;
334
                py = j;
335
                bkxy = 1;
336
                break;
337
            }
338
            if (abs(j) >= 1)
339
            {
340
                if (j > 0)
341
                    j -= 1;
342
                if (j < 0)
343
                    j += 1;
344
            }
345
            else
346
            {
347
                j = 0;
348
            }
349
            if (abs(i) >= 1)
350
            {
351
                if (i > 0)
352
                    i -= 1;
353
                if (i < 0)
354
                    i += 1;
355
            }
356
            else
357
            {
358
                i = 0;
359
            }
360
        }
361
        if (bkxy == 0)
362
        {
363
            px = 0;
364
            py = 0;
365
        }
366
    }
367
    runmove = 0;
368
    if (run == 1 && xmeet == 0 && ymeet == 0 && xymeet == 0)
369
    {
370
        if (abs(px) > 0 || abs(py) > 0)
371
        {
372
            runmove = 1;
373
            runtimer += 1;
374
            runcounter += 1;
375
        }
376
        else
377
        {
378
            runtimer = 0;
379
        }
380
    }
381
    else
382
    {
383
        runtimer = 0;
384
    }
385
    x += px;
386
    y += py;
387
}
388
if (fun == 0)
389
{
390
    walk = 0;
391
    if (x != nowx && nopress == 0)
392
        walk = 1;
393
    if (y != nowy && nopress == 0)
394
        walk = 1;
395
    if (walk == 1)
396
        walkbuffer = 6;
397
    if (walkbuffer > 3 && fun == 0)
398
    {
399
        walktimer += 1.5;
400
        if (runmove == 1)
401
            walktimer += 1.5;
402
        if (walktimer >= 40)
403
            walktimer -= 40;
404
        if (walktimer < 10)
405
            image_index = 0;
406
        if (walktimer >= 10)
407
            image_index = 1;
408
        if (walktimer >= 20)
409
            image_index = 2;
410
        if (walktimer >= 30)
411
            image_index = 3;
412
    }
413
    if (walkbuffer <= 0 && fun == 0)
414
    {
415
        if (walktimer < 10)
416
            walktimer = 9.5;
417
        if (walktimer >= 10 && walktimer < 20)
418
            walktimer = 19.5;
419
        if (walktimer >= 20 && walktimer < 30)
420
            walktimer = 29.5;
421
        if (walktimer >= 30)
422
            walktimer = 39.5;
423
        image_index = 0;
424
    }
425
    walkbuffer -= 0.75;
426
}
427
if (fun == 0)
428
{
429
    if (global.facing == 0)
430
        sprite_index = dsprite;
431
    if (global.facing == 1)
432
        sprite_index = rsprite;
433
    if (global.facing == 2)
434
        sprite_index = usprite;
435
    if (global.facing == 3)
436
        sprite_index = lsprite;
437
}
438
if (stepping == 1 && fun == 0)
439
{
440
    if (image_index == 1 && stepped == 0)
441
    {
442
        if (global.flag[31 disable_loud_steps] == 0)
443
            snd_play(snd_step1);
444
        stepped = 1;
445
    }
446
    if (image_index == 0 || image_index == 2)
447
        stepped = 0;
448
    if (image_index == 3 && stepped == 0)
449
    {
450
        stepped = 1;
451
        if (global.flag[31 disable_loud_steps] == 0)
452
            snd_play(snd_step2);
453
    }
454
}
455
if (onebuffer < 0)
456
{
457
    if (global.interact == 0)
458
    {
459
        if (button1_p())
460
        {
461
            thisinteract = 0;
462
            d = global.darkzone + 1;
463
            if (global.facing == 1)
464
            {
465
                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))
466
                    thisinteract = 1;
467
                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))
468
                    thisinteract = 2;
469
            }
470
            if (thisinteract > 0)
471
            {
472
                if (thisinteract == 1)
473
                    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);
474
                if (thisinteract == 2)
475
                    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);
476
                if (interactedobject != -4)
477
                {
478
                    with (interactedobject)
479
                        facing = 3;
480
                    with (interactedobject)
481
                        
scr_interact
scr_interact

function
scr_interact()
{ myinteract = 1; event_user(0); }
();
482
                }
483
            }
484
            thisinteract = 0;
485
            if (global.facing == 3)
486
            {
487
                if (collision_rectangle(x + (sprite_width / 2), y + (6 * d) + (sprite_height / 2), x - (13 * d), y + sprite_height, obj_interactable, false, true))
488
                    thisinteract = 1;
489
                if (collision_rectangle(x + (sprite_width / 2), y + (6 * d) + (sprite_height / 2), x - (13 * d), y + sprite_height, obj_interactablesolid, false, true))
490
                    thisinteract = 2;
491
            }
492
            if (thisinteract > 0)
493
            {
494
                if (thisinteract == 1)
495
                    interactedobject = collision_rectangle(x + (sprite_width / 2), y + (6 * d) + (sprite_height / 2), x - (13 * d), y + sprite_height, obj_interactable, false, true);
496
                if (thisinteract == 2)
497
                    interactedobject = collision_rectangle(x + (sprite_width / 2), y + (6 * d) + (sprite_height / 2), x - (13 * d), y + sprite_height, obj_interactablesolid, false, true);
498
                if (interactedobject != -4)
499
                {
500
                    with (interactedobject)
501
                        facing = 1;
502
                    with (interactedobject)
503
                        
scr_interact
scr_interact

function
scr_interact()
{ myinteract = 1; event_user(0); }
();
504
                }
505
            }
506
            thisinteract = 0;
507
            if (global.facing == 0)
508
            {
509
                if (collision_rectangle(x + (4 * d), y + (28 * d), (x + sprite_width) - (4 * d), y + sprite_height + (15 * d), obj_interactable, false, true))
510
                    thisinteract = 1;
511
                if (collision_rectangle(x + (4 * d), y + (28 * d), (x + sprite_width) - (4 * d), y + sprite_height + (15 * d), obj_interactablesolid, false, true))
512
                    thisinteract = 2;
513
            }
514
            if (thisinteract > 0)
515
            {
516
                if (thisinteract == 1)
517
                    interactedobject = collision_rectangle(x + (4 * d), y + (28 * d), (x + sprite_width) - (4 * d), y + sprite_height + (15 * d), obj_interactable, false, true);
518
                if (thisinteract == 2)
519
                    interactedobject = collision_rectangle(x + (4 * d), y + (28 * d), (x + sprite_width) - (4 * d), y + sprite_height + (15 * d), obj_interactablesolid, false, true);
520
                if (interactedobject != -4)
521
                {
522
                    with (interactedobject)
523
                        facing = 2;
524
                    with (interactedobject)
525
                        
scr_interact
scr_interact

function
scr_interact()
{ myinteract = 1; event_user(0); }
();
526
                }
527
            }
528
            thisinteract = 0;
529
            if (global.facing == 2)
530
            {
531
                if (collision_rectangle(x + 3, (y + sprite_height) - (5 * d), (x + sprite_width) - (5 * d), y + (5 * d), obj_interactable, false, true))
532
                    thisinteract = 1;
533
                if (collision_rectangle(x + 3, (y + sprite_height) - (5 * d), (x + sprite_width) - (5 * d), y + (5 * d), obj_interactablesolid, false, true))
534
                    thisinteract = 2;
535
            }
536
            if (thisinteract > 0)
537
            {
538
                if (thisinteract == 1)
539
                    interactedobject = collision_rectangle(x + (3 * d), (y + sprite_height) - (5 * d), (x + sprite_width) - (5 * d), y + (5 * d), obj_interactable, false, true);
540
                if (thisinteract == 2)
541
                    interactedobject = collision_rectangle(x + (3 * d), (y + sprite_height) - (5 * d), (x + sprite_width) - (5 * d), y + (5 * d), obj_interactablesolid, false, true);
542
                if (interactedobject != -4)
543
                {
544
                    with (interactedobject)
545
                        facing = 0;
546
                    with (interactedobject)
547
                        
scr_interact
scr_interact

function
scr_interact()
{ myinteract = 1; event_user(0); }
();
548
                }
549
            }
550
        }
551
    }
552
}
553
onebuffer -= 1;
554
twobuffer -= 1;
555
threebuffer -= 1;
556
with (collision_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom, obj_doorparent, 0, 0))
557
    event_user(9);
558
if (battlemode == 1)
559
{
560
    global.inv -= 1;
561
    if (global.inv < 0)
562
    {
563
        with (collision_rectangle(x + 12, y + 40, x + 27, y + 49, obj_overworldbulletparent, 1, 0))
564
            event_user(5);
565
        with (collision_line(x + 12, y + 49, x + 19, y + 57, obj_overworldbulletparent, 1, 0))
566
            event_user(5);
567
        with (collision_line(x + 26, y + 49, x + 19, y + 57, obj_overworldbulletparent, 1, 0))
568
            event_user(5);
569
    }
570
}
571
if (
scr_debug
scr_debug

function
scr_debug()
{ return 0; }
())
572
{
573
    if (keyboard_check_pressed(vk_insert))
574
        room_goto_next();
575
    if (keyboard_check_pressed(vk_delete))
576
        room_goto_previous();
577
    if (keyboard_check_pressed(vk_home))
578
    {
579
        if (keyboard_check(ord("1")))
580
        {
581
            room_goto(room_dw_cyber_intro_1 );
582
            global.darkzone = 1;
583
        }
584
        if (keyboard_check(ord("2")))
585
        {
586
            room_goto(room_krisroom );
587
            global.plot = 0;
588
            global.darkzone = 0;
589
        }
590
        if (keyboard_check(ord("3")))
591
        {
592
            room_goto(room_dw_castle_area_1 );
593
            global.plot = 7;
594
            global.darkzone = 1;
595
        }
596
        if (keyboard_check(ord("7")))
597
            room_goto(room_legend_neo );
598
        if (keyboard_check(ord("8")))
599
        {
600
            room_goto(room_battletest );
601
            global.darkzone = 1;
602
        }
603
        if (keyboard_check(ord("9")))
604
        {
605
            room_goto(room_bullettest );
606
            global.darkzone = 1;
607
        }
608
    }
609
}