Deltarune (Chapter 4) script viewer

← back to main script listing

gml_Object_obj_train_santa_Step_0

(view raw script w/o annotations or w/e)
1
if (state == "init")
2
{
3
    if (position == 0)
4
    {
5
        var _tower_height = 5;
6
        for (var i = 1; i < _tower_height; i++)
7
        {
8
            var _santa = instance_create_depth(x, y - (i * 10), depth, obj_train_santa);
9
            _santa.position = i;
10
        }
11
    }
12
    state = "tower";
13
    image_alpha = 2;
14
}
15
else if (state == "tower")
16
{
17
    x = xstart + (sin((current_time / 100) + position) * 2);
18
    if (position == 0)
19
    {
20
        var _ground_y = y;
21
        if (place_meeting(x, y, obj_train_piece_parent))
22
        {
23
            snd_play(snd_impact);
24
            snd_play(snd_fall);
25
            snd_play_pitch(snd_santa_laugh, random_range(1, 1.5));
26
            with (obj_train_santa)
27
            {
28
                state = "falling";
29
                hspeed = (position % 2) ? 0.7 : 1.5;
30
                ground_y = _ground_y;
31
                vspeed = -5;
32
                gravity = 0.5;
33
            }
34
        }
35
    }
36
}
37
else if (state == "falling")
38
{
39
    y = min(y, ground_y);
40
    if (y >= ground_y && vspeed > 0)
41
    {
42
        if (vspeed < 0.5)
43
        {
44
            hspeed = 0;
45
            gravity = 0;
46
            vspeed = 0;
47
            snd_play_pitch(snd_santa_laugh_low_energy, 1);
48
        }
49
        else
50
        {
51
            snd_play_pitch(snd_santa_laugh, random_range(1, 1.5));
52
            vspeed = -vspeed * 0.7;
53
        }
54
    }
55
    image_alpha -= 0.02;
56
    if (image_alpha < 0)
57
        instance_destroy();
58
}
59
image_angle -= (hspeed * 10);