Deltarune (Chapter 2) script viewer

← back to main script listing

gml_Object_obj_swatchling_cannonball_Step_0

(view raw script w/o annotations or w/e)
1
if (!heart_found && instance_exists(obj_heart))
2
{
3
    if (instance_exists(obj_heart))
4
    {
5
        nexttarget = obj_heart.x;
6
        heart_found = true;
7
    }
8
}
9
if (phase == 0)
10
{
11
    active = 0;
12
    if (trackplayer == 0)
13
    {
14
        if (instance_exists(obj_heart))
15
        {
16
            nexttarget = obj_heart.x;
17
            heart_found = true;
18
        }
19
    }
20
    defaultdepth = depth;
21
    depth = obj_growtangle.depth + 1;
22
    phase++;
23
    hspeed = -7;
24
    if (ystart > obj_growtangle.y)
25
        hspeed = -4;
26
    gravity = -0.5;
27
}
28
else if (phase == 1)
29
{
30
    if (image_xscale > 0.5)
31
        image_xscale -= 0.02;
32
    if (image_yscale > 0.5)
33
        image_yscale -= 0.02;
34
    if (y < jumppeak)
35
    {
36
        gravity = 0.5;
37
    }
38
    else if (vspeed <= -6)
39
    {
40
        gravity = 0;
41
        vspeed = -6;
42
    }
43
    else if (y > jumppeak)
44
    {
45
        gravity = -0.5;
46
    }
47
    if (((heart_found && trackplayer == 0 && x <= (obj_heart.x + 50)) || (trackplayer != 0 && x <= (nexttarget + 50))) && y < (obj_growtangle.y - 80))
48
    {
49
        phase++;
50
        hspeed++;
51
        sprite_index = spr_swatchling_blue_cannonball;
52
        image_xscale = 0.5;
53
        image_yscale = 0.5;
54
        active = 1;
55
        gravity = 0.5 / bouncepower;
56
        bouncespecial = 1;
57
    }
58
}
59
else if (phase == 2)
60
{
61
    if (depth > obj_growtangle.depth && vspeed >= 0)
62
    {
63
        depth = defaultdepth;
64
        defaultdepth = global.monsterinstance[creator].depth;
65
    }
66
    image_angle += currentrotation;
67
    if ((y + vspeed) > bouncepoint)
68
    {
69
        bouncespecial = 0;
70
        y = bouncepoint;
71
        randomdirection = random(45);
72
        if (obj_swatchling_battle_controller.yellow_count > 0)
73
        {
74
            with (obj_swatchling_platter)
75
            {
76
                if (timer < 0)
77
                    timer = 0;
78
                opened = true;
79
            }
80
        }
81
        else if (spawnbullets)
82
        {
83
            for (i = 0; i < 4; i++)
84
            {
85
                d = 
scr_childbullet
scr_childbullet

function
scr_childbullet()
{ var __child = instance_create(argument[0], argument[1], argument[2]); var __parent = (argument_count == 4) ? argument[3] : id; if (__parent.damage != -1) __child.damage = __parent.damage; if (__parent.grazepoints != -1) __child.grazepoints = __parent.grazepoints; if (__parent.timepoints != -1) __child.timepoints = __parent.timepoints; if (__parent.inv != -1) __child.inv = __parent.inv; if (__parent.target != -1) __child.target = __parent.target; if (__parent.grazed != -1) __child.grazed = __parent.grazed; if (__parent.grazetimer != -1) __child.grazetimer = __parent.grazetimer; __child.element = __parent.element; return __child; }
(x, y + 10, obj_swatchling_cannonball_bullet);
86
                d.grazepoints = childgraze;
87
                d.sprite_index = spr_swatchling_bluestar;
88
                d.speed = 5;
89
                d.direction = randomdirection;
90
                randomdirection += 90;
91
            }
92
        }
93
        var airtime = sqrt((2 * (y - jumppeak)) / gravity) + sqrt((2 * (ystart - jumppeak)) / gravity);
94
        if ((airtime + 20) > global.turntimer)
95
        {
96
            phase++;
97
            vspeed = -sqrt(gravity * 2 * (y - jumppeak));
98
            hspeed = (xstart - x) / airtime;
99
            currentrotation = image_angle % 360;
100
            nexttarget = x;
101
            if (global.turntimer < airtime)
102
                global.turntimer = airtime;
103
        }
104
        else
105
        {
106
            vspeed = -(10 + random(3)) * bouncepower;
107
            if (trackplayer == 0)
108
                nexttarget = obj_heart.x;
109
            else
110
                nexttarget = (obj_growtangle.x - (obj_growtangle.sprite_width / 2)) + random(obj_growtangle.sprite_width);
111
            var arctime = (-vspeed / gravity) * 2;
112
            hspeed = (nexttarget - x) / arctime;
113
            currentrotation = ((random(4) * 90) / arctime) * -sign(hspeed);
114
        }
115
    }
116
    if (bouncespecial == 1 && hspeed < -1)
117
        hspeed++;
118
}
119
else if (phase == 3)
120
{
121
    image_angle = lerp(currentrotation, -360, (x - nexttarget) / (xstart - nexttarget));
122
    if (x > (xstart - 30) && depth != defaultdepth)
123
        depth = defaultdepth;
124
    if (vspeed > 0 && animindex == 0)
125
    {
126
        sprite_index = spr_swatchling_blue_cannonball_prepare;
127
        var _smokeangle = irandom(90);
128
        for (i = 0; i < 4; i++)
129
        {
130
            var _smoke = instance_create(x, y, obj_animation_dx);
131
            _smoke.image_angle = (i * 90) + _smokeangle;
132
            _smoke.sprite_index = spr_swatchling_steam;
133
            _smoke.depth = depth - 1;
134
            _smoke.image_xscale = 3;
135
            _smoke.image_yscale = 3;
136
        }
137
        image_xscale = 1;
138
        image_yscale = 1;
139
        active = 0;
140
        image_index = 3;
141
        image_speed = 0;
142
        animindex = 1;
143
    }
144
    if ((x + hspeed) >= xstart || (animindex == 1 && (y + vspeed) > ystart))
145
    {
146
        speed = 0;
147
        gravity = 0;
148
        x = xstart;
149
        y = ystart;
150
        phase++;
151
        image_angle = 0;
152
        image_index = 0;
153
    }
154
}
155
else if (phase == 4)
156
{
157
    instance_destroy();
158
}