Deltarune (Chapter 3) 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
if (autodepth == 1)
19
    
scr_depth_alt
scr_depth_alt

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

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