Deltarune (Chapter 5) script viewer

← back to main script listing

gml_Object_obj_chaseenemy_Step_0

(view raw script w/o annotations or w/e)
1
if (encounterflag > 0 && init == 0)
2
{
3
    if (global.flag[encounterflag] == 1)
4
        instance_destroy();
5
    if (global.flag[encounterflag] == 6)
6
    {
7
        if (frozensprite == 0)
8
            frozensprite = touchsprite;
9
        frozennpc = instance_create(x, y, obj_frozennpc);
10
        frozennpc.sprite_index = frozensprite;
11
        frozennpc.fresh = 1;
12
        instance_destroy();
13
        if (sprite_index == spr_werewire_hang_overworld)
14
            frozennpc.sprite_index = spr_werewire_hurt;
15
    }
16
    init = 1;
17
}
18
scr_depth_alt
scr_depth_alt

function
scr_depth_alt(arg0 = id, arg1 = 0)
{ with (arg0) depth = 100000 - ((y * 10) + ((sprite_height - sprite_yoffset) * 10) + (arg1 * 10)); }
();
19
if (i_ex(obj_mainchara))
20
{
21
    targetx = (obj_mainchara.x + (obj_mainchara.sprite_width / 2)) - (sprite_width / 2);
22
    targety = (obj_mainchara.bbox_bottom - sprite_height) + (sprite_get_yoffset(sprite_index) * image_yscale);
23
}
24
if (global.interact == 0 || global.interact == 4)
25
    frozen = 0;
26
if (
scr_outside_camera
scr_outside_camera

function
scr_outside_camera(arg0)
{ _offcamera = 0; rightx = x + sprite_width; leftx = x; bottomy = y + sprite_height; topy = y; if (x > (__view_get(e__VW.XView, 0) + __view_get(e__VW.WView, 0) + arg0)) _offcamera = 1; if (rightx < (__view_get(e__VW.XView, 0) - arg0)) _offcamera = 1; if (y > (__view_get(e__VW.YView, 0) + __view_get(e__VW.HView, 0) + arg0)) _offcamera = 1; if (bottomy < (__view_get(e__VW.YView, 0) - arg0)) _offcamera = 1; return _offcamera; } enum e__VW { XView, YView, WView, HView, Angle, HBorder, VBorder, HSpeed, VSpeed, Object, Visible, XPort, YPort, WPort, HPort, Camera, SurfaceID }
(200) && offscreen_frozen == 1)
27
    frozen = 1;
28
else
29
    frozen = 0;
30
if (global.interact != 0 && global.interact != 4)
31
    frozen = 1;
32
if (frozen == 1 && ignorefreeze == 0)
33
{
34
    if (hadfrozen == 0)
35
    {
36
        remspeed = speed;
37
        speed = 0;
38
        hadfrozen = 1;
39
    }
40
}
41
if (frozen == 0)
42
{
43
    if (hadfrozen == 1)
44
    {
45
        if (speed == 0)
46
            speed = remspeed;
47
        hadfrozen = 0;
48
    }
49
    if (pacecon == 0)
50
    {
51
        pacetimer += 1;
52
        if (pacetype == 0)
53
        {
54
        }
55
        if (pacetype == 1)
56
        {
57
            if (pacetimer == 10)
58
                hspeed = 2;
59
            if (pacetimer == 34)
60
                hspeed = 0;
61
            if (pacetimer == 50)
62
                hspeed = -2;
63
            if (pacetimer == 74)
64
                hspeed = 0;
65
            if (pacetimer == 80)
66
                pacetimer = 0;
67
        }
68
        if (pacetype == 2)
69
        {
70
            hspeed = sin(pacetimer / 24) * 4;
71
            vspeed = cos(pacetimer / 24) * 4;
72
        }
73
        if (pacetype == 5)
74
        {
75
            if (pacetimer == 1)
76
                vspeed = 6;
77
            if (pacetimer == 25)
78
                vspeed = -6;
79
            if (y < ystart)
80
                pacetimer = 0;
81
        }
82
        if (pacetype == 6)
83
        {
84
            cancelwalk = 1;
85
            walk_index += 0.25;
86
        }
87
        if (pacetype == 7)
88
            hspeed = -sin(pacetimer / 30) * 10;
89
        if (pacetype == 7.1)
90
            hspeed = -sin(pacetimer / 30) * 10;
91
        if (pacetype == 7.5)
92
            hspeed = sin(pacetimer / 30) * 10;
93
        if (pacetype == 8)
94
            vspeed = -sin(pacetimer / 25) * 12.5;
95
        if (pacetype == 9)
96
        {
97
            if (float != 0)
98
                y = yy - (sin(pacetimer / 5) * float);
99
            hspeed = sin(pacetimer / (pacespeed * 30)) * (moveradius / 20);
100
            pacespeed = 0.8;
101
        }
102
        if (pacetype == 9.5)
103
        {
104
            if (float != 0)
105
                y = yy - sin(pacetimer / float);
106
            hspeed = 2 * (sin(pacetimer / 24) * (moveradius / 20));
107
        }
108
        if (pacetype == 10)
109
        {
110
            if (pacecon2 == 0)
111
            {
112
                if (vspeed > 0)
113
                    vspeed *= 0.9;
114
                if (vspeed <= 0.5 && pacecon2 == 0)
115
                    pacecon2 = 1;
116
            }
117
            if (pacecon2 == 1)
118
                move_towards_point(obj_mainchara.x, obj_mainchara.y, 4);
119
        }
120
        if (pacetype == 11)
121
        {
122
            cancelwalk = 1;
123
            image_speed = 0.25;
124
            if (pathSpeed == 0)
125
                pathSpeed = 6;
126
            if (direction >= 136 && direction <= 225)
127
                facing = 0;
128
            if (direction >= 306 || direction <= 45)
129
                facing = 1;
130
        }
131
        if (pacetype == 12)
132
        {
133
            hspeed = -sin(pacetimer / 30) * 10;
134
            vspeed = (-sin(pacetimer / 12) * 12.5) / 10;
135
        }
136
        if (pacetype == 13)
137
        {
138
            t = (t + increment) % 360;
139
            shift = amplitude * dsin(t);
140
            y = yy + shift;
141
        }
142
        if (pacetype == 14)
143
        {
144
            var _c = dcos(rotation);
145
            var _s = dsin(rotation);
146
            x = xx + (_c * distance) + (_s * distance);
147
            y = yy + (-_s * distance) + (_c * distance);
148
            rotation += spd;
149
            if (rotation > 359)
150
                rotation -= 360;
151
        }
152
        if (pacetype == 15)
153
        {
154
            if (float != 0)
155
                y = yy - sin(pacetimer / float);
156
            t = (t + increment) % 360;
157
            shift = amplitude * dsin(t);
158
            x = xx + shift;
159
            vspeed = (-sin(pacetimer / 12) * 12.5) / 10;
160
        }
161
        if (pacetype == 16)
162
        {
163
            if (pacecon2 == 0)
164
            {
165
                hspeed *= 1.2;
166
                hspeed = clamp(hspeed, -12, 12);
167
                if (x <= 240)
168
                    pacecon2 = 0.1;
169
            }
170
            if (pacecon2 == 0.1)
171
            {
172
                hspeed *= 0.7;
173
                if (abs(hspeed) < 0.5)
174
                {
175
                    hspeed = 1;
176
                    pacecon2 = 1;
177
                }
178
            }
179
            if (pacecon2 == 1)
180
            {
181
                hspeed *= 1.2;
182
                hspeed = clamp(hspeed, -12, 12);
183
                if (x >= 860)
184
                    pacecon2 = 1.1;
185
            }
186
            if (pacecon2 == 1.1)
187
            {
188
                hspeed *= 0.7;
189
                if (abs(hspeed) < 0.5)
190
                {
191
                    hspeed = -1;
192
                    pacecon2 = 0;
193
                }
194
            }
195
        }
196
        if (pacetype == 17)
197
        {
198
            y = yy - sin(pacetimer / 5);
199
            x = xx - (sin(pacetimer / 20) * 10);
200
            if (x > xprevious)
201
                facing = 1;
202
            else
203
                facing = 0;
204
        }
205
        if (pacetype == 18)
206
            y = yy - sin(pacetimer / 5);
207
        if (pacetype == 19)
208
        {
209
            x = xx - (sin(pacetimer / 20) * 20);
210
            if (x > xprevious)
211
                facing = 1;
212
            else
213
                facing = 0;
214
        }
215
        if (pacetype == 20)
216
        {
217
            if (float != 0)
218
                y = yy - sin(pacetimer / float);
219
            image_speed = 0.25;
220
            cancelwalk = 1;
221
            if (pacecon2 == 0)
222
            {
223
                if (x < (xstart + moveradius))
224
                {
225
                    x += pacespeed;
226
                }
227
                else
228
                {
229
                    x = xstart + moveradius;
230
                    pacecon2 = 1;
231
                }
232
            }
233
            if (pacecon2 == 1)
234
            {
235
                if (x > (xstart - moveradius))
236
                {
237
                    x -= pacespeed;
238
                }
239
                else
240
                {
241
                    x = xstart - moveradius;
242
                    pacecon2 = 0;
243
                }
244
            }
245
            if (x > xprevious)
246
                facing = 1;
247
            else
248
                facing = 0;
249
        }
250
        if (pacetype == 21 || pacetype == 22)
251
        {
252
            if (paceinit == 0)
253
            {
254
                leftbound = 0;
255
                leftboundcheck = 0;
256
                while (leftboundcheck == 0)
257
                {
258
                    if (place_meeting(x - leftbound, y, obj_solidblock) || place_meeting(x - leftbound, y, obj_solidenemy) || place_meeting(x - leftbound, y, obj_solidenemy_2) || leftbound >= 480)
259
                    {
260
                        leftboundcheck = 1;
261
                        show_debug_message("leftbound:" + string(leftbound));
262
                    }
263
                    else
264
                    {
265
                        leftbound++;
266
                    }
267
                }
268
                rightbound = 0;
269
                rightboundcheck = 0;
270
                while (rightboundcheck == 0)
271
                {
272
                    if (place_meeting(x + rightbound, y, obj_solidblock) || place_meeting(x + rightbound, y, obj_solidenemy) || place_meeting(x + rightbound, y, obj_solidenemy_2) || rightbound >= 480)
273
                    {
274
                        rightboundcheck = 1;
275
                        show_debug_message("rightbound:" + string(rightbound));
276
                    }
277
                    else
278
                    {
279
                        rightbound++;
280
                    }
281
                }
282
                if (leftbound < rightbound)
283
                    moveradius = leftbound - 8;
284
                else
285
                    moveradius = rightbound - 8;
286
                show_debug_message("moveradius:" + string(moveradius));
287
                siner = 0;
288
                pacesinspeed = moveradius / (pacespeed * 3);
289
                paceinit = 1;
290
            }
291
            siner++;
292
            if (pacetype == 21)
293
                x = xx - (sin(siner / pacesinspeed) * moveradius);
294
            if (pacetype == 22)
295
                x = xx + (sin(siner / pacesinspeed) * moveradius);
296
            if (x > xprevious)
297
                facing = 1;
298
            else
299
                facing = 0;
300
        }
301
        if (pacetype == 23)
302
        {
303
            y = yy - sin(pacetimer / 5);
304
            x = xx - (sin(pacetimer / 20) * moveradius);
305
            if (x > xprevious)
306
                facing = 1;
307
            else
308
                facing = 0;
309
        }
310
        if (pacetype == 24)
311
        {
312
            pacespeed = 25;
313
            y = yy + (sin(pacetimer / 20) * 10);
314
            x = xx - (sin(pacetimer / pacespeed) * moveradius);
315
            if (x > xprevious)
316
                facing = 1;
317
            else
318
                facing = 0;
319
        }
320
        if (pacetype == 25)
321
        {
322
            var _paceangle = pacedir * 90;
323
            hspeed = lengthdir_x(pacespeed, _paceangle);
324
            vspeed = lengthdir_y(pacespeed, _paceangle);
325
            pacedistancewalked += pacespeed;
326
            if (pacedistancewalked >= pacedistance)
327
            {
328
                pacedistancewalked -= pacedistance;
329
                if (turnbehaviour == 0)
330
                {
331
                    if (pacedir < 2)
332
                        pacedir += 2;
333
                    else
334
                        pacedir -= 2;
335
                }
336
                if (turnbehaviour == 1)
337
                {
338
                    if (pacedir < 3)
339
                        pacedir++;
340
                    else
341
                        pacedir = 0;
342
                }
343
                if (turnbehaviour == 2)
344
                {
345
                    if (pacedir > 0)
346
                        pacedir--;
347
                    else
348
                        pacedir = 3;
349
                }
350
            }
351
            if (pacedir == 0)
352
                sprite_index = rsprite;
353
            if (pacedir == 1)
354
                sprite_index = usprite;
355
            if (pacedir == 2)
356
                sprite_index = lsprite;
357
            if (pacedir == 3)
358
                sprite_index = dsprite;
359
            detectpointxoffset = lengthdir_x(40, _paceangle);
360
            detectpointyoffset = lengthdir_y(40, _paceangle);
361
        }
362
    }
363
    viewblocked = 0;
364
    viewpointx = ((bbox_left + bbox_right) / 2) + detectpointxoffset;
365
    viewpointy = bbox_bottom + detectpointyoffset;
366
    if (canAlertThroughWalls == 0 && i_ex(obj_mainchara))
367
    {
368
        mcx = (obj_mainchara.bbox_left + obj_mainchara.bbox_right) / 2;
369
        mcy = obj_mainchara.bbox_bottom;
370
        if (collision_line(viewpointx, viewpointy, mcx, mcy, obj_solidblock, 1, 1) > 0)
371
            viewblocked = 1;
372
        if (collision_line(viewpointx, viewpointy, mcx, mcy, obj_interactablesolid, 1, 0) > 0)
373
            viewblocked = 1;
374
        if (collision_line(viewpointx, viewpointy, mcx, mcy, obj_solidenemy, 1, 0) > 0)
375
            viewblocked = 1;
376
    }
377
    if (alerted == 0 && i_ex(obj_mainchara))
378
    {
379
        if (alerttype == 0)
380
        {
381
            if (point_distance(viewpointx, viewpointy, charaHeartX(), charaHeartY()) <= radius && blind == 0)
382
                alerted = 1;
383
        }
384
        if (alerttype == 1)
385
        {
386
            if (direction >= 45 && direction <= 135)
387
            {
388
                if (point_in_rectangle(obj_mainchara.x + 20, obj_mainchara.y + 35, (x + sprite_width) - radius, y + (sprite_height / 2), x + radius, (y + (sprite_height / 2)) - ((radius * 3) / 4)))
389
                    alerted = 1;
390
            }
391
            if (direction >= 225 && direction <= 315)
392
            {
393
                if (point_in_rectangle(obj_mainchara.x + 20, obj_mainchara.y + 35, (x + sprite_width) - radius, y + (sprite_height / 2), x + radius, y + (sprite_height / 2) + ((radius * 3) / 4)))
394
                    alerted = 1;
395
            }
396
            if ((direction >= 315 && direction <= 405) || (direction >= -45 && direction <= 45))
397
            {
398
                if (point_in_rectangle(obj_mainchara.x + 20, obj_mainchara.y + 35, x + (sprite_width / 2), (y + sprite_height) - radius, x + sprite_width + radius, y + radius))
399
                    alerted = 1;
400
            }
401
            if (direction >= 135 && direction <= 225)
402
            {
403
                if (point_in_rectangle(obj_mainchara.x + 20, obj_mainchara.y + 35, x - radius, (y + sprite_height) - radius, x + (sprite_width / 2), y + radius))
404
                    alerted = 1;
405
            }
406
        }
407
    }
408
    if (viewblocked == 1)
409
        alerted = 0;
410
    if (alerted == 1)
411
    {
412
        speed = 0;
413
        pacecon = 1;
414
        alerttimer = 0;
415
        alertcon = 1;
416
        if (pacetype == 11)
417
            path_end();
418
        if (alertskip == 0)
419
        {
420
            if (noAlertSound == 0)
421
                snd_play(snd_b);
422
            targalarm = 20;
423
            if (chasetype == 8)
424
                targalarm = 8;
425
            excl = instance_create(x + (sprite_width / 2), y - 20, obj_excblcon);
426
            excl.alarm[0] = targalarm;
427
            alarm[4]
 = targalarm;
gml_Object_obj_chaseenemy_Alarm_4.gml

alertcon += 1;
428
        }
429
        else
430
        {
431
            alertcon = 2;
432
        }
433
        alerted = 2;
434
    }
435
    if (alertcon == 2)
436
    {
437
        if (chasetype == -1)
438
        {
439
            alerttimer = 0;
440
            alertcon = 0;
441
            pacecon = 0;
442
        }
443
        if (chasetype == 0)
444
        {
445
            if (speed < 4)
446
                speed = 4;
447
            if (speed < 7)
448
                speed += 0.5;
449
            move_towards_point(targetx, targety, speed);
450
        }
451
        if (chasetype == 1)
452
        {
453
            if (alerttimer == 0)
454
                move_towards_point(targetx, targety, 10);
455
            alerttimer += 1;
456
            if (alerttimer >= 20)
457
                speed *= 0.75;
458
            if (alerttimer >= 25)
459
                speed = 0;
460
            if (alerttimer >= 27)
461
                alerttimer = 0;
462
        }
463
        if (chasetype == 2)
464
        {
465
            if (alerttimer == 0)
466
            {
467
                xnext = 0;
468
                ynext = 0;
469
                if (right_h())
470
                    xnext = 132;
471
                if (left_h())
472
                    xnext = -132;
473
                if (down_h())
474
                    ynext = 132;
475
                if (up_h())
476
                    ynext = -132;
477
                move_towards_point(targetx + xnext, targety + ynext, 10);
478
            }
479
            alerttimer += 1;
480
            if (alerttimer >= 20)
481
                speed *= 0.75;
482
            if (alerttimer >= 25)
483
                speed = 0;
484
            if (alerttimer >= 27)
485
                alerttimer = 0;
486
        }
487
        if (chasetype == 3)
488
        {
489
            if (speed < 2)
490
                speed = 2;
491
            if (speed < 4)
492
                speed += 0.5;
493
            move_towards_point(targetx, targety, speed);
494
        }
495
        if (chasetype == 4)
496
        {
497
            if (speed < 6)
498
                speed = 6;
499
            if (speed < 14)
500
                speed += 0.5;
501
            move_towards_point(targetx, targety, speed);
502
        }
503
        if (chasetype == 5)
504
        {
505
            hspeed += lengthdir_x(0.5, point_direction(x, y, targetx, targety));
506
            vspeed += lengthdir_y(0.5, point_direction(x, y, targetx, targety));
507
            if (speed < 4)
508
                speed = 4;
509
            if (speed < 7)
510
                speed += 0.5;
511
            if (speed >= 7)
512
                speed = 7;
513
            move_towards_point(targetx, targety, speed);
514
        }
515
        if (chasetype == 5.5)
516
        {
517
            hspeed += lengthdir_x(0.5, point_direction(x, y, targetx, targety));
518
            vspeed += lengthdir_y(0.5, point_direction(x, y, targetx, targety));
519
            if (speed < startchasespeed)
520
                speed = startchasespeed;
521
            if (speed != topchasespeed)
522
                speed = lerp(speed, topchasespeed, chaseaccel);
523
            move_towards_point(targetx, targety, speed);
524
        }
525
        if (chasetype == 6)
526
        {
527
            speed = 8;
528
            move_towards_point(targetx, targety, speed);
529
        }
530
        if (chasetype == 7)
531
        {
532
            if (speed == 0)
533
                speed = 6;
534
            if (speed < 10)
535
                speed *= 1.1;
536
            image_speed = 0.25;
537
            move_towards_point(targetx, targety, speed);
538
        }
539
        if (chasetype == 8)
540
        {
541
            mymidx = x + (sprite_width / 2);
542
            mymidy = y + ((bbox_bottom - y) / 2);
543
            if (point_distance(mymidx, mymidy, charaHeartX(), charaHeartY()) > 50)
544
                direction = point_direction(mymidx, mymidy, charaHeartX(), charaHeartY()) + 180;
545
            speed = 6;
546
        }
547
        if (chasetype == 9)
548
        {
549
            hspeed += lengthdir_x(0.5, point_direction(x, y, targetx, targety));
550
            vspeed += lengthdir_y(0.5, point_direction(x, y, targetx, targety));
551
            speed = clamp(speed, minspeed, maxspeed);
552
            move_towards_point(targetx, targety, speed);
553
        }
554
        if (chasetype == 10)
555
        {
556
            speed = 0;
557
            if (point_distance(x, y, targetx, targety) > (radius * 1.25))
558
            {
559
                alerttimer = 0;
560
                alertcon = 0;
561
                pacecon = 0;
562
                alerted = 0;
563
            }
564
        }
565
        if (specialspritecase == "4direction")
566
        {
567
            var _cardinal = (floor(direction) + 45) div 90;
568
            if (_cardinal == 0 || _cardinal == 4)
569
                sprite_index = rsprite;
570
            if (_cardinal == 1)
571
                sprite_index = usprite;
572
            if (_cardinal == 2)
573
                sprite_index = lsprite;
574
            if (_cardinal == 3)
575
                sprite_index = dsprite;
576
        }
577
    }
578
    facetimer += 1;
579
    if (facetimer >= 10)
580
    {
581
        if (hspeed <= -0.2 && facing == 1)
582
        {
583
            facing = 0;
584
            facetimer = 0;
585
        }
586
        if (hspeed >= 0.2 && facing == 0)
587
        {
588
            facing = 1;
589
            facetimer = 0;
590
        }
591
    }
592
    if (cancelwalk == 0)
593
    {
594
        walk_index += (speed / 20);
595
        if (speed == 0)
596
            walk_index = 0;
597
    }
598
    else
599
    {
600
        walk_index = image_index;
601
    }
602
    if (test_release_bullet == 1)
603
    {
604
        test_release_bullet_timer++;
605
        if (test_release_bullet_timer > 20)
606
        {
607
            bullet = instance_create(x, y, obj_encounter_bullet);
608
            bullet.creator = id;
609
            with (bullet)
610
                move_towards_point(obj_mainchara.x + 20, obj_mainchara.y + 20, 4);
611
            test_release_bullet_timer = 0;
612
        }
613
    }
614
}
615
if (sprite_index == spr_werewire_hang_overworld)
616
{
617
    detectpointyoffset = -88;
618
    customhitbox = 1;
619
    hitx1 = -2;
620
    hitx2 = 66;
621
    hity1 = 42;
622
    hity2 = 130;
623
}
624
if (sprite_index == spr_virovirokun_idle)
625
    detectpointyoffset = -50;