Deltarune (Chapter 3) 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
    init = 1;
13
}
14
if (interpolate == true)
15
{
16
    interpolate = false;
17
    if (i_ex(daddy))
18
    {
19
        var xpos = daddy.x;
20
        var ypos = daddy.y;
21
        for (var i = 0; i < memory; i += 1)
22
        {
23
            remx[i] = x;
24
            remy[i] = y;
25
            facing[i] = 0;
26
        }
27
        remx[0] = xpos;
28
        remy[0] = ypos;
29
        for (var _iaia = targetdist; _iaia > 0; _iaia -= 1)
30
        {
31
            remx[_iaia] = lerp(xpos, x, _iaia / targetdist);
32
            remy[_iaia] = lerp(ypos, y, _iaia / targetdist);
33
        }
34
    }
35
}
36
if (!ignoredepth)
37
    
scr_depth_alt
scr_depth_alt

function
scr_depth_alt()
{ depth = 100000 - ((y * 10) + ((sprite_height - sprite_yoffset) * 10)); }
();
38
nowx = x;
39
nowy = y;
40
moved = 0;
41
walk = 0;
42
runmove = 0;
43
slided = 0;
44
if (daddy.x != remx[0] || daddy.y != remy[0])
45
    moved = 1;
46
if (moved == 1 && follow == 1 && i_ex(daddy))
47
{
48
    for (var i = memory; i > 0; i--)
49
    {
50
        remx[i] = remx[i - 1];
51
        remy[i] = remy[i - 1];
52
    }
53
    remx[0] = daddy.x;
54
    remy[0] = daddy.y;
55
    x = remx[targetdist] - halign;
56
    y = remy[targetdist] - valign;
57
    if (abs(remx[targetdist + 1] - remx[targetdist]) > 4)
58
        runmove = 1;
59
    if (abs(remy[targetdist + 1] - remy[targetdist]) > 4)
60
        runmove = 1;
61
}
62
var walkanimspeed = 0.25;
63
var animdist = 1;
64
if (abs(point_distance(x, y, nowx, nowy)) > animdist)
65
{
66
    resetanim = 0;
67
    image_index += walkanimspeed;
68
    dir = point_direction(x, y, nowx, nowy) - 180;
69
    if (dir < 0)
70
        dir += 360;
71
    if (dir > 360)
72
        dir -= 360;
73
    facing = 0;
74
    if (dir >= 315 || dir <= 45)
75
        facing = 1;
76
    if (dir > 45 && dir < 135)
77
        facing = 2;
78
    if (dir >= 135 && dir <= 225)
79
        facing = 3;
80
}
81
else
82
{
83
    resetanim++;
84
    if (resetanim >= resetanimtarget)
85
        image_index = 0;
86
}
87
if (fun == 0)
88
{
89
    if (allowdown)
90
    {
91
        if (facing == 0)
92
            sprite_index = dsprite;
93
    }
94
    if (allowright)
95
    {
96
        if (facing == 1)
97
            sprite_index = rsprite;
98
    }
99
    if (allowup)
100
    {
101
        if (facing == 2)
102
            sprite_index = usprite;
103
    }
104
    if (allowleft)
105
    {
106
        if (facing == 3)
107
            sprite_index = lsprite;
108
    }
109
    if (flip)
110
    {
111
        if (facing == 3)
112
        {
113
            sprite_index = rsprite;
114
            image_xscale = -2;
115
        }
116
    }
117
    if (facing == 1)
118
    {
119
        sprite_index = rsprite;
120
        image_xscale = 2;
121
    }
122
}