Deltarune (Chapter 4) script viewer

← back to main script listing

gml_Object_obj_caterpillar_generic_Step_2

(view raw script w/o annotations or w/e)
1
if (!init)
2
{
3
    if (!variable_instance_exists(id, "dsprite"))
4
        dsprite = sprite_index;
5
    if (!variable_instance_exists(id, "rsprite"))
6
        rsprite = sprite_index;
7
    if (!variable_instance_exists(id, "usprite"))
8
        usprite = sprite_index;
9
    if (!variable_instance_exists(id, "lsprite"))
10
        lsprite = sprite_index;
11
    sprite_index = dsprite;
12
    if (memory != 75)
13
    {
14
        for (var i = 0; i < memory; i += 1)
15
        {
16
            remx[i] = daddy.x;
17
            remy[i] = daddy.y;
18
            sliding[i] = 0;
19
            special[i] = 0;
20
        }
21
    }
22
    init = 1;
23
}
24
if (interpolate == true)
25
{
26
    interpolate = false;
27
    if (i_ex(daddy))
28
    {
29
        var xpos = daddy.x;
30
        var ypos = daddy.y;
31
        for (var i = 0; i < memory; i += 1)
32
        {
33
            remx[i] = x;
34
            remy[i] = y;
35
            facing[i] = 0;
36
        }
37
        remx[0] = xpos;
38
        remy[0] = ypos;
39
        for (var _iaia = targetdist; _iaia > 0; _iaia -= 1)
40
        {
41
            remx[_iaia] = lerp(xpos, x, _iaia / targetdist);
42
            remy[_iaia] = lerp(ypos, y, _iaia / targetdist);
43
        }
44
    }
45
}
46
if (!ignoredepth)
47
    
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)); }
(undefined, depthyoff);
48
nowx = x;
49
nowy = y;
50
moved = 0;
51
walk = 0;
52
runmove = 0;
53
slided = 0;
54
if (daddy.x != remx[0] || daddy.y != remy[0])
55
    moved = 1;
56
if (moved == 1 && follow == 1 && i_ex(daddy))
57
{
58
    for (var i = memory; i > 0; i--)
59
    {
60
        remx[i] = remx[i - 1];
61
        remy[i] = remy[i - 1];
62
    }
63
    remx[0] = daddy.x;
64
    remy[0] = daddy.y;
65
    x = remx[targetdist] - halign;
66
    y = remy[targetdist] - valign;
67
    if (abs(remx[targetdist + 1] - remx[targetdist]) > 4)
68
        runmove = 1;
69
    if (abs(remy[targetdist + 1] - remy[targetdist]) > 4)
70
        runmove = 1;
71
}
72
var walkanimspeed = 0.25;
73
var animdist = 1;
74
if (abs(point_distance(x, y, nowx, nowy)) > animdist)
75
{
76
    resetanim = 0;
77
    image_index += walkanimspeed;
78
    dir = point_direction(x, y, nowx, nowy) - 180;
79
    if (dir < 0)
80
        dir += 360;
81
    if (dir > 360)
82
        dir -= 360;
83
    facing = 0;
84
    if (dir >= 315 || dir <= 45)
85
        facing = 1;
86
    if (dir > 45 && dir < 135)
87
        facing = 2;
88
    if (dir >= 135 && dir <= 225)
89
        facing = 3;
90
}
91
else
92
{
93
    resetanim++;
94
    if (resetanim >= resetanimtarget)
95
        image_index = 0;
96
}
97
if (fun == 0)
98
{
99
    if (allowdown)
100
    {
101
        if (facing == 0)
102
            sprite_index = dsprite;
103
    }
104
    if (allowright)
105
    {
106
        if (facing == 1)
107
            sprite_index = rsprite;
108
    }
109
    if (allowup)
110
    {
111
        if (facing == 2)
112
            sprite_index = usprite;
113
    }
114
    if (allowleft)
115
    {
116
        if (facing == 3)
117
            sprite_index = lsprite;
118
    }
119
    if (!allowdown)
120
    {
121
        if (facing == 0)
122
        {
123
            if (sprite_index == usprite)
124
            {
125
                if (downfavor == "left")
126
                    sprite_index = lsprite;
127
                if (downfavor == "right")
128
                    sprite_index = rsprite;
129
                if (downfavor == "up")
130
                    sprite_index = usprite;
131
            }
132
        }
133
    }
134
    if (!allowup)
135
    {
136
        if (facing == 0)
137
        {
138
            if (sprite_index == dsprite)
139
            {
140
                if (upfavor == "left")
141
                    sprite_index = lsprite;
142
                if (upfavor == "right")
143
                    sprite_index = rsprite;
144
                if (upfavor == "down")
145
                    sprite_index = dsprite;
146
            }
147
        }
148
    }
149
    if (flip)
150
    {
151
        if (facing == 3)
152
        {
153
            sprite_index = rsprite;
154
            image_xscale = -2;
155
        }
156
    }
157
    if (facing == 1)
158
    {
159
        sprite_index = rsprite;
160
        image_xscale = 2;
161
    }
162
}