Deltarune (Chapter 2) 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
        if (room == room_dw_city_big_1)
16
        {
17
            if (extflag == "tutViro")
18
            {
19
                frozennpc.x = 224;
20
                frozennpc.y = 72;
21
            }
22
            if (extflag == "leftOma")
23
            {
24
                frozennpc.x = 246;
25
                frozennpc.y = 440;
26
                frozennpc.sprite_index = spr_omawaroid_hurt;
27
            }
28
            if (extflag == "rightOma")
29
            {
30
                frozennpc.x = 606;
31
                frozennpc.y = 440;
32
                frozennpc.sprite_index = spr_omawaroid_hurt;
33
            }
34
        }
35
        if (room == room_dw_city_roadblock)
36
        {
37
            if (extflag == "tutViro")
38
            {
39
                frozennpc.x = 1000;
40
                frozennpc.y = 588;
41
            }
42
        }
43
        if (room == room_dw_city_big_2)
44
        {
45
            if (extflag == "viro")
46
            {
47
                frozennpc.x = 510;
48
                frozennpc.y = 196;
49
            }
50
            else
51
            {
52
                frozennpc.x = 600;
53
                frozennpc.y = 202;
54
            }
55
        }
56
        if (room == room_dw_city_big_3)
57
        {
58
            if (extflag == "viro")
59
            {
60
                frozennpc.x = 426;
61
                frozennpc.y = 1000;
62
            }
63
            else if (y < 300)
64
            {
65
                frozennpc.x = 1390;
66
                frozennpc.y = 92;
67
            }
68
            else
69
            {
70
                frozennpc.x = 1420;
71
                frozennpc.y = 694;
72
            }
73
        }
74
        if (room == room_dw_cyber_maze_queenscreen)
75
            frozennpc.y = 120;
76
        if (room == room_dw_mansion_single_pot)
77
        {
78
            frozennpc.x = 370;
79
            frozennpc.y = 140;
80
        }
81
        if (room == room_dw_city_cheesemaze && encounterflag == 566)
82
        {
83
            frozennpc.x = 1190;
84
            frozennpc.y = 622;
85
        }
86
        if (room == room_dw_mansion_potBalance)
87
        {
88
            frozennpc.x = 320;
89
            frozennpc.y = 600;
90
            frozennpc.sprite_index = spr_swatchling_hurt;
91
        }
92
        if (room == room_dw_city_queen_drunk)
93
        {
94
            frozennpc.x = 1240;
95
            frozennpc.y = 64;
96
            frozennpc.sprite_index = spr_tasque_hurt;
97
        }
98
        if (room == room_dw_city_traffic_1)
99
        {
100
            if (x > 1330)
101
            {
102
                frozennpc.x = 1644;
103
                frozennpc.y = 118;
104
                frozennpc.sprite_index = spr_tasque_hurt;
105
            }
106
            else
107
            {
108
                frozennpc.x = 852;
109
                frozennpc.y = 118;
110
                frozennpc.sprite_index = spr_omawaroid_hurt;
111
            }
112
        }
113
        if (room == room_dw_city_spamton_house)
114
        {
115
            if (x > 680)
116
            {
117
                frozennpc.x = 960;
118
                frozennpc.y = 118;
119
                frozennpc.sprite_index = spr_virovirokun_hurt;
120
            }
121
            else
122
            {
123
                frozennpc.x = 416;
124
                frozennpc.y = 116;
125
                frozennpc.sprite_index = spr_werewire_hurt;
126
            }
127
        }
128
    }
129
    init = 1;
130
}
131
scr_depth_alt
scr_depth_alt

function
scr_depth_alt()
{ depth = 100000 - ((y * 10) + ((sprite_height - sprite_yoffset) * 10)); }
();
132
targetx = (obj_mainchara.x + (obj_mainchara.sprite_width / 2)) - (sprite_width / 2);
133
targety = (obj_mainchara.bbox_bottom - sprite_height) + (sprite_get_yoffset(sprite_index) * image_yscale);
134
if (global.interact == 0 || global.interact == 4)
135
    frozen = 0;
136
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)
137
    frozen = 1;
138
else
139
    frozen = 0;
140
if (global.interact != 0 && global.interact != 4)
141
    frozen = 1;
142
if (frozen == 1 && ignorefreeze == 0)
143
{
144
    if (hadfrozen == 0)
145
    {
146
        remspeed = speed;
147
        speed = 0;
148
        hadfrozen = 1;
149
    }
150
}
151
if (frozen == 0)
152
{
153
    if (hadfrozen == 1)
154
    {
155
        if (speed == 0)
156
            speed = remspeed;
157
        hadfrozen = 0;
158
    }
159
    if (pacecon == 0)
160
    {
161
        pacetimer += 1;
162
        if (pacetype == 0)
163
        {
164
        }
165
        if (pacetype == 1)
166
        {
167
            if (pacetimer == 10)
168
                hspeed = 2;
169
            if (pacetimer == 34)
170
                hspeed = 0;
171
            if (pacetimer == 50)
172
                hspeed = -2;
173
            if (pacetimer == 74)
174
                hspeed = 0;
175
            if (pacetimer == 80)
176
                pacetimer = 0;
177
        }
178
        if (pacetype == 2)
179
        {
180
            hspeed = sin(pacetimer / 24) * 4;
181
            vspeed = cos(pacetimer / 24) * 4;
182
        }
183
        if (pacetype == 5)
184
        {
185
            if (pacetimer == 1)
186
                vspeed = 6;
187
            if (pacetimer == 25)
188
                vspeed = -6;
189
            if (y < ystart)
190
                pacetimer = 0;
191
        }
192
        if (pacetype == 6)
193
        {
194
            cancelwalk = 1;
195
            walk_index += 0.25;
196
        }
197
        if (pacetype == 7)
198
            hspeed = -sin(pacetimer / 30) * 10;
199
        if (pacetype == 7.1)
200
            hspeed = -sin(pacetimer / 30) * 10;
201
        if (pacetype == 7.5)
202
            hspeed = sin(pacetimer / 30) * 10;
203
        if (pacetype == 8)
204
            vspeed = -sin(pacetimer / 25) * 12.5;
205
        if (pacetype == 9)
206
        {
207
            if (float != 0)
208
                y = yy - (sin(pacetimer / 5) * float);
209
            hspeed = sin(pacetimer / (pacespeed * 30)) * (moveradius / 20);
210
            pacespeed = 0.8;
211
        }
212
        if (pacetype == 9.5)
213
        {
214
            if (float != 0)
215
                y = yy - sin(pacetimer / float);
216
            hspeed = 2 * (sin(pacetimer / 24) * (moveradius / 20));
217
        }
218
        if (pacetype == 10)
219
        {
220
            if (pacecon2 == 0)
221
            {
222
                if (vspeed > 0)
223
                    vspeed *= 0.9;
224
                if (vspeed <= 0.5 && pacecon2 == 0)
225
                    pacecon2 = 1;
226
            }
227
            if (pacecon2 == 1)
228
                move_towards_point(obj_mainchara.x, obj_mainchara.y, 4);
229
        }
230
        if (pacetype == 11)
231
        {
232
            cancelwalk = 1;
233
            image_speed = 0.25;
234
            if (pathSpeed == 0)
235
            {
236
                if (room == room_dw_city_big_2)
237
                    pathSpeed = 6;
238
                else if (room == room_dw_mansion_east_1f_a)
239
                    pathSpeed = 6;
240
                else if (room == room_dw_city_big_1)
241
                    pathSpeed = 6;
242
                else
243
                    pathSpeed = 6;
244
            }
245
            if (direction >= 136 && direction <= 225)
246
                facing = 0;
247
            if (direction >= 306 || direction <= 45)
248
                facing = 1;
249
        }
250
        if (pacetype == 12)
251
        {
252
            hspeed = -sin(pacetimer / 30) * 10;
253
            vspeed = (-sin(pacetimer / 12) * 12.5) / 10;
254
        }
255
        if (pacetype == 13)
256
        {
257
            t = (t + increment) % 360;
258
            shift = amplitude * dsin(t);
259
            y = yy + shift;
260
        }
261
        if (pacetype == 14)
262
        {
263
            var _c = dcos(rotation);
264
            var _s = dsin(rotation);
265
            x = xx + (_c * distance) + (_s * distance);
266
            y = yy + (-_s * distance) + (_c * distance);
267
            rotation += spd;
268
            if (rotation > 359)
269
                rotation -= 360;
270
            if (room == room_dw_cyber_maze_virokun)
271
            {
272
                if (rotation > 180)
273
                    facing = 1;
274
                else
275
                    facing = 0;
276
            }
277
        }
278
        if (pacetype == 15)
279
        {
280
            if (float != 0)
281
                y = yy - sin(pacetimer / float);
282
            t = (t + increment) % 360;
283
            shift = amplitude * dsin(t);
284
            x = xx + shift;
285
            vspeed = (-sin(pacetimer / 12) * 12.5) / 10;
286
        }
287
        if (pacetype == 16)
288
        {
289
            if (pacecon2 == 0)
290
            {
291
                hspeed *= 1.2;
292
                hspeed = clamp(hspeed, -12, 12);
293
                if (x <= 240)
294
                    pacecon2 = 0.1;
295
            }
296
            if (pacecon2 == 0.1)
297
            {
298
                hspeed *= 0.7;
299
                if (abs(hspeed) < 0.5)
300
                {
301
                    hspeed = 1;
302
                    pacecon2 = 1;
303
                }
304
            }
305
            if (pacecon2 == 1)
306
            {
307
                hspeed *= 1.2;
308
                hspeed = clamp(hspeed, -12, 12);
309
                if (x >= 860)
310
                    pacecon2 = 1.1;
311
            }
312
            if (pacecon2 == 1.1)
313
            {
314
                hspeed *= 0.7;
315
                if (abs(hspeed) < 0.5)
316
                {
317
                    hspeed = -1;
318
                    pacecon2 = 0;
319
                }
320
            }
321
        }
322
        if (pacetype == 17)
323
        {
324
            y = yy - sin(pacetimer / 5);
325
            x = xx - (sin(pacetimer / 20) * 10);
326
            if (x > xprevious)
327
                facing = 1;
328
            else
329
                facing = 0;
330
        }
331
        if (pacetype == 18)
332
            y = yy - sin(pacetimer / 5);
333
        if (pacetype == 19)
334
        {
335
            x = xx - (sin(pacetimer / 20) * 20);
336
            if (x > xprevious)
337
                facing = 1;
338
            else
339
                facing = 0;
340
        }
341
        if (pacetype == 20)
342
        {
343
            if (float != 0)
344
                y = yy - sin(pacetimer / float);
345
            image_speed = 0.25;
346
            cancelwalk = 1;
347
            if (pacecon2 == 0)
348
            {
349
                if (x < (xstart + moveradius))
350
                {
351
                    x += pacespeed;
352
                }
353
                else
354
                {
355
                    x = xstart + moveradius;
356
                    pacecon2 = 1;
357
                }
358
            }
359
            if (pacecon2 == 1)
360
            {
361
                if (x > (xstart - moveradius))
362
                {
363
                    x -= pacespeed;
364
                }
365
                else
366
                {
367
                    x = xstart - moveradius;
368
                    pacecon2 = 0;
369
                }
370
            }
371
            if (x > xprevious)
372
                facing = 1;
373
            else
374
                facing = 0;
375
        }
376
        if (pacetype == 21 || pacetype == 22)
377
        {
378
            if (paceinit == 0)
379
            {
380
                leftbound = 0;
381
                leftboundcheck = 0;
382
                while (leftboundcheck == 0)
383
                {
384
                    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)
385
                        leftboundcheck = 1;
386
                    else
387
                        leftbound++;
388
                }
389
                rightbound = 0;
390
                rightboundcheck = 0;
391
                while (rightboundcheck == 0)
392
                {
393
                    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)
394
                        rightboundcheck = 1;
395
                    else
396
                        rightbound++;
397
                }
398
                if (leftbound < rightbound)
399
                    moveradius = leftbound - 8;
400
                else
401
                    moveradius = rightbound - 8;
402
                siner = 0;
403
                pacesinspeed = moveradius / (pacespeed * 3);
404
                paceinit = 1;
405
            }
406
            siner++;
407
            if (pacetype == 21)
408
                x = xx - (sin(siner / pacesinspeed) * moveradius);
409
            if (pacetype == 22)
410
                x = xx + (sin(siner / pacesinspeed) * moveradius);
411
            if (x > xprevious)
412
                facing = 1;
413
            else
414
                facing = 0;
415
        }
416
        if (pacetype == 23)
417
        {
418
            y = yy - sin(pacetimer / 5);
419
            x = xx - (sin(pacetimer / 20) * moveradius);
420
            if (x > xprevious)
421
                facing = 1;
422
            else
423
                facing = 0;
424
        }
425
        if (pacetype == 24)
426
        {
427
            pacespeed = 25;
428
            y = yy + (sin(pacetimer / 20) * 10);
429
            x = xx - (sin(pacetimer / pacespeed) * moveradius);
430
            if (x > xprevious)
431
                facing = 1;
432
            else
433
                facing = 0;
434
        }
435
    }
436
    viewblocked = 0;
437
    viewpointx = ((bbox_left + bbox_right) / 2) + detectpointxoffset;
438
    viewpointy = bbox_bottom + detectpointyoffset;
439
    if (canAlertThroughWalls == 0)
440
    {
441
        mcx = (obj_mainchara.bbox_left + obj_mainchara.bbox_right) / 2;
442
        mcy = obj_mainchara.bbox_bottom;
443
        if (collision_line(viewpointx, viewpointy, mcx, mcy, obj_solidblock, 1, 1) > 0)
444
            viewblocked = 1;
445
        if (collision_line(viewpointx, viewpointy, mcx, mcy, obj_interactablesolid, 1, 0) > 0)
446
            viewblocked = 1;
447
        if (collision_line(viewpointx, viewpointy, mcx, mcy, obj_solidenemy, 1, 0) > 0)
448
            viewblocked = 1;
449
    }
450
    if (alerted == 0)
451
    {
452
        if (alerttype == 0)
453
        {
454
            if (point_distance(viewpointx, viewpointy, charaHeartX(), charaHeartY()) <= radius && blind == 0)
455
                alerted = 1;
456
        }
457
        if (alerttype == 1)
458
        {
459
            if (direction >= 45 && direction <= 135)
460
            {
461
                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)))
462
                    alerted = 1;
463
            }
464
            if (direction >= 225 && direction <= 315)
465
            {
466
                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)))
467
                    alerted = 1;
468
            }
469
            if ((direction >= 315 && direction <= 405) || (direction >= -45 && direction <= 45))
470
            {
471
                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))
472
                    alerted = 1;
473
            }
474
            if (direction >= 135 && direction <= 225)
475
            {
476
                if (point_in_rectangle(obj_mainchara.x + 20, obj_mainchara.y + 35, x - radius, (y + sprite_height) - radius, x + (sprite_width / 2), y + radius))
477
                    alerted = 1;
478
            }
479
        }
480
    }
481
    if (viewblocked == 1)
482
        alerted = 0;
483
    if (alerted == 1)
484
    {
485
        speed = 0;
486
        pacecon = 1;
487
        alerttimer = 0;
488
        alertcon = 1;
489
        if (pacetype == 11)
490
            path_end();
491
        if (alertskip == 0)
492
        {
493
            if (noAlertSound == 0)
494
                snd_play(snd_b);
495
            targalarm = 20;
496
            if (chasetype == 8)
497
                targalarm = 8;
498
            excl = instance_create(x + (sprite_width / 2), y - 20, obj_excblcon);
499
            excl.alarm[0] = targalarm;
500
            alarm[4]
 = targalarm;
gml_Object_obj_chaseenemy_Alarm_4.gml

alertcon += 1;
501
        }
502
        else
503
        {
504
            alertcon = 2;
505
        }
506
        alerted = 2;
507
    }
508
    if (alertcon == 2)
509
    {
510
        if (chasetype == -1)
511
        {
512
            alerttimer = 0;
513
            alertcon = 0;
514
            pacecon = 0;
515
        }
516
        if (chasetype == 0)
517
        {
518
            if (speed < 4)
519
                speed = 4;
520
            if (speed < 7)
521
                speed += 0.5;
522
            move_towards_point(targetx, targety, speed);
523
        }
524
        if (chasetype == 1)
525
        {
526
            if (alerttimer == 0)
527
                move_towards_point(targetx, targety, 10);
528
            alerttimer += 1;
529
            if (alerttimer >= 20)
530
                speed *= 0.75;
531
            if (alerttimer >= 25)
532
                speed = 0;
533
            if (alerttimer >= 27)
534
                alerttimer = 0;
535
        }
536
        if (chasetype == 2)
537
        {
538
            if (alerttimer == 0)
539
            {
540
                xnext = 0;
541
                ynext = 0;
542
                if (right_h())
543
                    xnext = 132;
544
                if (left_h())
545
                    xnext = -132;
546
                if (down_h())
547
                    ynext = 132;
548
                if (up_h())
549
                    ynext = -132;
550
                move_towards_point(targetx + xnext, targety + ynext, 10);
551
            }
552
            alerttimer += 1;
553
            if (alerttimer >= 20)
554
                speed *= 0.75;
555
            if (alerttimer >= 25)
556
                speed = 0;
557
            if (alerttimer >= 27)
558
                alerttimer = 0;
559
        }
560
        if (chasetype == 3)
561
        {
562
            if (speed < 2)
563
                speed = 2;
564
            if (speed < 4)
565
                speed += 0.5;
566
            move_towards_point(targetx, targety, speed);
567
        }
568
        if (chasetype == 4)
569
        {
570
            if (speed < 6)
571
                speed = 6;
572
            if (speed < 14)
573
                speed += 0.5;
574
            move_towards_point(targetx, targety, speed);
575
        }
576
        if (chasetype == 5)
577
        {
578
            hspeed += lengthdir_x(0.5, point_direction(x, y, targetx, targety));
579
            vspeed += lengthdir_y(0.5, point_direction(x, y, targetx, targety));
580
            if (speed < 4)
581
                speed = 4;
582
            if (speed < 7)
583
                speed += 0.5;
584
            if (speed >= 7)
585
                speed = 7;
586
            move_towards_point(targetx, targety, speed);
587
        }
588
        if (chasetype == 5.5)
589
        {
590
            hspeed += lengthdir_x(0.5, point_direction(x, y, targetx, targety));
591
            vspeed += lengthdir_y(0.5, point_direction(x, y, targetx, targety));
592
            if (speed < startchasespeed)
593
                speed = startchasespeed;
594
            if (speed != topchasespeed)
595
                speed = lerp(speed, topchasespeed, chaseaccel);
596
            move_towards_point(targetx, targety, speed);
597
        }
598
        if (chasetype == 6)
599
        {
600
            speed = 8;
601
            move_towards_point(targetx, targety, speed);
602
        }
603
        if (chasetype == 7)
604
        {
605
            if (speed == 0)
606
                speed = 6;
607
            if (speed < 10)
608
                speed *= 1.1;
609
            image_speed = 0.25;
610
            move_towards_point(targetx, targety, speed);
611
        }
612
        if (chasetype == 8)
613
        {
614
            mymidx = x + (sprite_width / 2);
615
            mymidy = y + ((bbox_bottom - y) / 2);
616
            if (point_distance(mymidx, mymidy, charaHeartX(), charaHeartY()) > 50)
617
                direction = point_direction(mymidx, mymidy, charaHeartX(), charaHeartY()) + 180;
618
            speed = 6;
619
        }
620
        if (chasetype == 9)
621
        {
622
            hspeed += lengthdir_x(0.5, point_direction(x, y, targetx, targety));
623
            vspeed += lengthdir_y(0.5, point_direction(x, y, targetx, targety));
624
            speed = clamp(speed, minspeed, maxspeed);
625
            move_towards_point(targetx, targety, speed);
626
        }
627
    }
628
    facetimer += 1;
629
    if (facetimer >= 10)
630
    {
631
        if (hspeed <= -0.2 && facing == 1)
632
        {
633
            facing = 0;
634
            facetimer = 0;
635
        }
636
        if (hspeed >= 0.2 && facing == 0)
637
        {
638
            facing = 1;
639
            facetimer = 0;
640
        }
641
    }
642
    if (cancelwalk == 0)
643
    {
644
        walk_index += (speed / 20);
645
        if (speed == 0)
646
            walk_index = 0;
647
    }
648
    else
649
    {
650
        walk_index = image_index;
651
    }
652
    if (test_release_bullet == 1)
653
    {
654
        test_release_bullet_timer++;
655
        if (test_release_bullet_timer > 20)
656
        {
657
            bullet = instance_create(x, y, obj_encounter_bullet);
658
            bullet.creator = id;
659
            with (bullet)
660
                move_towards_point(obj_mainchara.x + 20, obj_mainchara.y + 20, 4);
661
            test_release_bullet_timer = 0;
662
        }
663
    }
664
}
665
if (sprite_index == spr_werewire_hang_overworld)
666
{
667
    detectpointyoffset = -88;
668
    customhitbox = 1;
669
    hitx1 = -2;
670
    hitx2 = 66;
671
    hity1 = 42;
672
    hity2 = 130;
673
}
674
if (sprite_index == spr_virovirokun_idle)
675
    detectpointyoffset = -50;