Deltarune (Chapter 4) script viewer

← back to main script listing

gml_Object_obj_spearshot_Step_0

(view raw script w/o annotations or w/e)
1
if (!i_ex(obj_heart) || !i_ex(obj_spearblocker) || global.turntimer < 1)
2
{
3
    instance_destroy();
4
    exit;
5
}
6
if (!i_ex(obj_heart))
7
{
8
    instance_destroy();
9
    exit;
10
}
11
if (frozentimer > 0)
12
{
13
    frozentimer--;
14
    exit;
15
}
16
if (bouncespear > 0)
17
{
18
    if (bouncespearcon == 0)
19
    {
20
        sprite_index = spr_bounce_shell_idle;
21
        if (bouncespear == 2)
22
        {
23
            if (bouncespeardir == 0)
24
                sprite_index = spr_bounce_shell_idle;
25
            else
26
                sprite_index = spr_bounce_shell_idle;
27
        }
28
        image_xscale = 1.5;
29
        image_yscale = 1.5;
30
        savedir = direction;
31
        bouncespearcon = -1;
32
        testcon = 0;
33
    }
34
    if (bouncespearcon == 1)
35
    {
36
        image_index++;
37
        bouncespeartimer++;
38
        if (bouncespeartimer == 5)
39
        {
40
            bouncespearcon = 2;
41
            fakespeed = -20;
42
            grav = 1.2;
43
            if (bouncespear == 1)
44
                sprite_index = spr_bounce_shell_idle;
45
            if (bouncespear == 2)
46
            {
47
                if (sprite_index != spr_bounce_shell_hit_center)
48
                {
49
                    image_index = 1;
50
                    sprite_index = spr_bounce_shell_hit_center;
51
                    if (direction == 270)
52
                        y -= 16;
53
                    if (direction == 180)
54
                        x -= 16;
55
                    if (direction == 90)
56
                        y += 16;
57
                    if (direction == 0)
58
                        x += 16;
59
                }
60
                fakespeed = -17;
61
                grav = 1;
62
                if (hitstopbounce == 1)
63
                {
64
                    fakespeed = -19;
65
                    grav = 1.25;
66
                }
67
                if (fastbounce == 1)
68
                {
69
                    fakespeed = -38;
70
                    grav = 6;
71
                }
72
            }
73
            if (slowbounce == 1)
74
            {
75
                fakespeed = -10;
76
                grav = 0.35;
77
            }
78
            if (slowbounce == 2)
79
            {
80
                fakespeed = -10;
81
                grav = 0.25;
82
            }
83
            if (slowbounce == 3)
84
            {
85
                fakespeed = -10;
86
                grav = 0.2;
87
            }
88
            if (slowbounce == 4)
89
            {
90
                fakespeed = -11;
91
                grav = 0.24;
92
            }
93
            bouncespeartimer = 0;
94
        }
95
        else
96
        {
97
            exit;
98
        }
99
    }
100
    else
101
    {
102
        hurtsquish = false;
103
    }
104
    if (bouncespearcon == 2)
105
    {
106
        x3++;
107
        if (bouncespear == 1)
108
        {
109
            x = round(obj_spearblocker.x + lengthdir_x(len, direction + 180));
110
            y = round(obj_spearblocker.y + lengthdir_y(len, direction + 180));
111
        }
112
        if (bouncespear == 2)
113
        {
114
            bouncespeartimer++;
115
            fakespeed += grav;
116
            len -= fakespeed;
117
            var duration = 34;
118
            if (hitstopbounce == 1)
119
                duration = 30;
120
            if (fastbounce == 1)
121
                duration = 12;
122
            if (slowbounce == 1)
123
            {
124
                duration = 60;
125
                if (hitstopbounce == 1)
126
                    duration = 54;
127
            }
128
            if (slowbounce == 2)
129
            {
130
                duration = 80;
131
                if (hitstopbounce == 1)
132
                    duration = 74;
133
            }
134
            if (slowbounce == 3)
135
            {
136
                duration = 100;
137
                if (hitstopbounce == 1)
138
                    duration = 94;
139
            }
140
            if (slowbounce == 4)
141
            {
142
                duration = 110;
143
                if (hitstopbounce == 1)
144
                    duration = 104;
145
            }
146
            duration += testcon;
147
            spinindex = (bouncespeartimer / duration) * 14.5;
148
            var _savedir;
149
            if (bouncespeardir == 0)
150
            {
151
                _savedir = savedir + 270;
152
                if (bouncespeartimer <= duration)
153
                    _savedir = lerp(savedir + 180, savedir + 270, bouncespeartimer / duration);
154
                direction = savedir + 90;
155
            }
156
            if (bouncespeardir == 180)
157
            {
158
                _savedir = savedir + 90;
159
                if (bouncespeartimer <= duration)
160
                    _savedir = lerp(savedir + 180, savedir + 90, bouncespeartimer / duration);
161
                direction = savedir - 90;
162
            }
163
            x = obj_spearblocker.x + lengthdir_x(len, _savedir);
164
            y = obj_spearblocker.y + lengthdir_y(len, _savedir);
165
        }
166
    }
167
}
168
if (fadespear == 1)
169
{
170
    image_alpha += 0.1;
171
    fadespeartimer++;
172
    if (fadespeartimer == 1)
173
    {
174
        savedir = direction;
175
        savex = x;
176
        savey = y;
177
        type = choose(0, 1);
178
    }
179
    if (image_angle == 0)
180
    {
181
        if (type == 1)
182
            y = lerp(savey + fadespeardist, savey, fadespeartimer / fadespeartimermax);
183
        else
184
            y = lerp(savey - fadespeardist, savey, fadespeartimer / fadespeartimermax);
185
    }
186
    if (image_angle == 90)
187
    {
188
        if (type == 1)
189
            x = lerp(savex + fadespeardist, savex, fadespeartimer / fadespeartimermax);
190
        else
191
            x = lerp(savex - fadespeardist, savex, fadespeartimer / fadespeartimermax);
192
    }
193
    if (image_angle == 180)
194
    {
195
        if (type == 1)
196
            y = lerp(savey + fadespeardist, savey, fadespeartimer / fadespeartimermax);
197
        else
198
            y = lerp(savey - fadespeardist, savey, fadespeartimer / fadespeartimermax);
199
    }
200
    if (image_angle == 270)
201
    {
202
        if (type == 1)
203
            x = lerp(savex + fadespeardist, savex, fadespeartimer / fadespeartimermax);
204
        else
205
            x = lerp(savex - fadespeardist, savex, fadespeartimer / fadespeartimermax);
206
    }
207
    if (fadespeartimer == fadespeartimermax)
208
    {
209
        speed = 0;
210
        direction = savedir;
211
        fakespeed = fadespeed;
212
        fadespeartimer = 0;
213
        fadespear = 0;
214
        init = 1;
215
    }
216
    exit;
217
}
218
if (fadespear == 3)
219
{
220
    if (image_alpha == 0)
221
        savedir = direction;
222
    image_alpha = lerp(image_alpha, 1.8, 0.16);
223
    fadespeartimer++;
224
    if (fadespeartimer == 1)
225
        fakespeed = -0.5;
226
    if (fadespeartimer == 20)
227
        fakespeed = 0;
228
    if (fadespeartimer == (fadewaitmax - 12))
229
    {
230
        snd_play_pitch(snd_bell_bounce_short, 1.3);
231
        sprite_index = spr_spear_arrow_highlight;
232
        flashalpha = 1;
233
    }
234
    if (fadespeartimer == fadewaitmax)
235
    {
236
        fakespeed = 15;
237
        init = 1;
238
    }
239
    if (fadespeartimer < fadewaitmax)
240
    {
241
        len -= fakespeed;
242
        x = obj_spearblocker.x + lengthdir_x(len, direction + 180);
243
        y = obj_spearblocker.y + lengthdir_y(len, direction + 180);
244
        exit;
245
    }
246
}
247
if (fadespear == 4)
248
{
249
    image_alpha += 0.1;
250
    fadespeartimer++;
251
    if (fadespeartimer == 1)
252
        fakespeed = -0.5;
253
    if (fadespeartimer == 20)
254
        fakespeed = 0;
255
    if (fadespeartimer == (fadewaitmax - 12))
256
    {
257
        snd_play_pitch(snd_bell_bounce_short, 1.3);
258
        sprite_index = spr_spear_arrow_highlight;
259
        flashalpha = 1;
260
    }
261
    if (fadespeartimer == fadewaitmax)
262
    {
263
        fakespeed = 15;
264
        init = 1;
265
    }
266
    if (fadespeartimer < fadewaitmax)
267
    {
268
        if (len < 190)
269
            direction++;
270
        else
271
            direction--;
272
        len -= fakespeed;
273
        x = obj_spearblocker.x + lengthdir_x(len, direction + 180);
274
        y = obj_spearblocker.y + lengthdir_y(len, direction + 180);
275
        exit;
276
    }
277
}
278
var rotateradius = 90;
279
if (giant || redhammer)
280
    rotateradius = 70;
281
var _a = 0;
282
if (bouncespearcon == 2 && bouncespear == 2)
283
    _a = 1;
284
if ((special == 0 || (special != 0 && len > rotateradius)) && _a == 0)
285
{
286
    fakespeed += grav;
287
    len -= fakespeed;
288
}
289
if (special != 0 && len <= rotateradius)
290
{
291
    len = rotateradius;
292
    var _special = special;
293
    if (_special == 360)
294
        _special = 0;
295
    repeat (20)
296
    {
297
        var _dir = direction - _special;
298
        var _angledifference = _dir;
299
        if (abs(_dir) > 180)
300
        {
301
            if (direction > _special)
302
                _angledifference = -1 * ((360 - direction) + _special);
303
            else
304
                _angledifference = (360 - _special) + direction;
305
        }
306
        if (direction == _special)
307
        {
308
        }
309
        else if (_angledifference > 2)
310
        {
311
            direction -= 1;
312
        }
313
        else if (_angledifference < 2)
314
        {
315
            direction += 1;
316
        }
317
        else
318
        {
319
            direction = _special;
320
        }
321
        if (direction > 360)
322
            direction -= 360;
323
        if (direction < 0)
324
            direction += 360;
325
        if (_special == direction)
326
            special = 0;
327
    }
328
}
329
if (redhammer != 0)
330
{
331
    if (i_ex(obj_spearblocker))
332
    {
333
        spearblockerx = obj_spearblocker.x;
334
        spearblockery = obj_spearblocker.y;
335
    }
336
    x1 = spearblockerx + lengthdir_x(len, direction + 180);
337
    y1 = spearblockery + lengthdir_y(len, direction + 180);
338
}
339
else if (i_ex(obj_spearblocker))
340
{
341
    x1 = obj_spearblocker.x + lengthdir_x(len, direction + 180);
342
    y1 = obj_spearblocker.y + lengthdir_y(len, direction + 180);
343
}
344
if (init == 0)
345
{
346
    init = 1;
347
    dir2 = direction + 90;
348
    len2 = len + 50;
349
}
350
if (timer < 25 && swingaround == true)
351
{
352
    timer++;
353
    dir2 = lerp(dir2, direction + 180, timer / 25);
354
    len2 = lerp(len2, len, timer / 25);
355
    x = obj_spearblocker.x + lengthdir_x(len2, dir2);
356
    y = obj_spearblocker.y + lengthdir_y(len2, dir2);
357
}
358
else if (bouncespearcon != 2)
359
{
360
    x = x1;
361
    y = y1;
362
}
363
if (len < 50)
364
    event_user(0);