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

alertcon += 1;
383
        }
384
        else
385
        {
386
            alertcon = 2;
387
        }
388
        alerted = 2;
389
    }
390
    if (alertcon == 2)
391
    {
392
        if (chasetype == -1)
393
        {
394
            alerttimer = 0;
395
            alertcon = 0;
396
            pacecon = 0;
397
        }
398
        if (chasetype == 0)
399
        {
400
            if (speed < 4)
401
                speed = 4;
402
            if (speed < 7)
403
                speed += 0.5;
404
            move_towards_point(targetx, targety, speed);
405
        }
406
        if (chasetype == 1)
407
        {
408
            if (alerttimer == 0)
409
                move_towards_point(targetx, targety, 10);
410
            alerttimer += 1;
411
            if (alerttimer >= 20)
412
                speed *= 0.75;
413
            if (alerttimer >= 25)
414
                speed = 0;
415
            if (alerttimer >= 27)
416
                alerttimer = 0;
417
        }
418
        if (chasetype == 2)
419
        {
420
            if (alerttimer == 0)
421
            {
422
                xnext = 0;
423
                ynext = 0;
424
                if (right_h())
425
                    xnext = 132;
426
                if (left_h())
427
                    xnext = -132;
428
                if (down_h())
429
                    ynext = 132;
430
                if (up_h())
431
                    ynext = -132;
432
                move_towards_point(targetx + xnext, targety + ynext, 10);
433
            }
434
            alerttimer += 1;
435
            if (alerttimer >= 20)
436
                speed *= 0.75;
437
            if (alerttimer >= 25)
438
                speed = 0;
439
            if (alerttimer >= 27)
440
                alerttimer = 0;
441
        }
442
        if (chasetype == 3)
443
        {
444
            if (speed < 2)
445
                speed = 2;
446
            if (speed < 4)
447
                speed += 0.5;
448
            move_towards_point(targetx, targety, speed);
449
        }
450
        if (chasetype == 4)
451
        {
452
            if (speed < 6)
453
                speed = 6;
454
            if (speed < 14)
455
                speed += 0.5;
456
            move_towards_point(targetx, targety, speed);
457
        }
458
        if (chasetype == 5)
459
        {
460
            hspeed += lengthdir_x(0.5, point_direction(x, y, targetx, targety));
461
            vspeed += lengthdir_y(0.5, point_direction(x, y, targetx, targety));
462
            if (speed < 4)
463
                speed = 4;
464
            if (speed < 7)
465
                speed += 0.5;
466
            if (speed >= 7)
467
                speed = 7;
468
            move_towards_point(targetx, targety, speed);
469
        }
470
        if (chasetype == 5.5)
471
        {
472
            hspeed += lengthdir_x(0.5, point_direction(x, y, targetx, targety));
473
            vspeed += lengthdir_y(0.5, point_direction(x, y, targetx, targety));
474
            if (speed < startchasespeed)
475
                speed = startchasespeed;
476
            if (speed != topchasespeed)
477
                speed = lerp(speed, topchasespeed, chaseaccel);
478
            move_towards_point(targetx, targety, speed);
479
        }
480
        if (chasetype == 6)
481
        {
482
            speed = 8;
483
            move_towards_point(targetx, targety, speed);
484
        }
485
        if (chasetype == 7)
486
        {
487
            if (speed == 0)
488
                speed = 6;
489
            if (speed < 10)
490
                speed *= 1.1;
491
            image_speed = 0.25;
492
            move_towards_point(targetx, targety, speed);
493
        }
494
        if (chasetype == 8)
495
        {
496
            mymidx = x + (sprite_width / 2);
497
            mymidy = y + ((bbox_bottom - y) / 2);
498
            if (point_distance(mymidx, mymidy, charaHeartX(), charaHeartY()) > 50)
499
                direction = point_direction(mymidx, mymidy, charaHeartX(), charaHeartY()) + 180;
500
            speed = 6;
501
        }
502
        if (chasetype == 9)
503
        {
504
            hspeed += lengthdir_x(0.5, point_direction(x, y, targetx, targety));
505
            vspeed += lengthdir_y(0.5, point_direction(x, y, targetx, targety));
506
            speed = clamp(speed, minspeed, maxspeed);
507
            move_towards_point(targetx, targety, speed);
508
        }
509
    }
510
    facetimer += 1;
511
    if (facetimer >= 10)
512
    {
513
        if (hspeed <= -0.2 && facing == 1)
514
        {
515
            facing = 0;
516
            facetimer = 0;
517
        }
518
        if (hspeed >= 0.2 && facing == 0)
519
        {
520
            facing = 1;
521
            facetimer = 0;
522
        }
523
    }
524
    if (cancelwalk == 0)
525
    {
526
        walk_index += (speed / 20);
527
        if (speed == 0)
528
            walk_index = 0;
529
    }
530
    else
531
    {
532
        walk_index = image_index;
533
    }
534
    if (test_release_bullet == 1)
535
    {
536
        test_release_bullet_timer++;
537
        if (test_release_bullet_timer > 20)
538
        {
539
            bullet = instance_create(x, y, obj_encounter_bullet);
540
            bullet.creator = id;
541
            with (bullet)
542
                move_towards_point(obj_mainchara.x + 20, obj_mainchara.y + 20, 4);
543
            test_release_bullet_timer = 0;
544
        }
545
    }
546
}
547
if (sprite_index == spr_werewire_hang_overworld)
548
{
549
    detectpointyoffset = -88;
550
    customhitbox = 1;
551
    hitx1 = -2;
552
    hitx2 = 66;
553
    hity1 = 42;
554
    hity2 = 130;
555
}
556
if (sprite_index == spr_virovirokun_idle)
557
    detectpointyoffset = -50;