Deltarune (Chapter 3) script viewer

← back to main script listing

gml_Object_obj_b3bs_chasekey_Step_0

(view raw script w/o annotations or w/e)
1
scr_depth_board
scr_depth_board

function
scr_depth_board()
{ depth = 1000000 - ((y * 10) + ((sprite_height - sprite_yoffset) * 10)); } function scr_board_depth() {
scr_depth_board();
}
();
2
sndbuff--;
3
stuckbuff--;
4
if (!grabbed)
5
{
6
    if (init == 0)
7
    {
8
        pointCount = instance_number(pointObj);
9
        for (var i = 0; i < pointCount; i++)
10
            myPoint[i] = instance_find(pointObj, i);
11
        init = 1;
12
    }
13
    if (moveCon == 0)
14
    {
15
        playerDistanceThreshold = 128;
16
        if (i_ex(playerObj))
17
        {
18
            if (point_distance(x, y, playerObj.x, playerObj.y) < playerDistanceThreshold)
19
                moveCon = 1;
20
        }
21
    }
22
    if (moveCon == 1 && i_ex(playerObj))
23
    {
24
        playerFurthestPoint = 0;
25
        var playerFurthestPointDistance = 0;
26
        meFurthestPoint = 0;
27
        var meFurthestPointDistance = 0;
28
        for (var i = 0; i < pointCount; i++)
29
        {
30
            var checkDist = point_distance(myPoint[i].x, myPoint[i].y, playerObj.x, playerObj.y);
31
            var checkDistMe = point_distance(myPoint[i].x, myPoint[i].y, x, y);
32
            if (checkDistMe < checkDist)
33
            {
34
                if (checkDist > playerFurthestPointDistance)
35
                {
36
                    playerFurthestPointDistance = checkDist;
37
                    playerFurthestPoint = i;
38
                }
39
            }
40
        }
41
        moveCon = 2;
42
        moveTimer = 0;
43
        samePlaceCount = 0;
44
        previousXPrevious = 9999;
45
        previousYPrevious = 9999;
46
    }
47
    if (moveCon == 2)
48
    {
49
        var xx = myPoint[playerFurthestPoint].x;
50
        var yy = myPoint[playerFurthestPoint].y;
51
        var mySpeed = 8;
52
        if (global.flag[1055 sword_route_progress] > 0)
53
            mySpeed = 6;
54
        if (stuckcount >= 2)
55
            mySpeed = 6;
56
        if (stuckcount >= 6)
57
            mySpeed = 4;
58
        if (point_distance(x, y, xx, yy) < (mySpeed + 2) || moveTimer > 32)
59
        {
60
            moveCon = 0;
61
        }
62
        else
63
        {
64
            var myDir = round(point_direction(x, y, xx, yy) / 90) * 90;
65
            for (var i = 0; i < 3; i++)
66
            {
67
                moveX[i] = lengthdir_x(mySpeed, (myDir - 90) + (90 * i));
68
                moveY[i] = lengthdir_y(mySpeed, (myDir - 90) + (90 * i));
69
                if (!place_meeting(x + moveX[i], y + moveY[i], solidObj))
70
                    canMove[i] = 1;
71
                else
72
                    canMove[i] = 0;
73
            }
74
            var finalMoveX = 0;
75
            var finalMoveY = 0;
76
            if (canMove[1] == 1)
77
            {
78
                finalMoveX = moveX[1];
79
                finalMoveY = moveY[1];
80
            }
81
            else if (moveClockwise == 1)
82
            {
83
                if (canMove[2])
84
                {
85
                    finalMoveX = moveX[2];
86
                    finalMoveY = moveY[2];
87
                }
88
                else
89
                {
90
                    moveClockwise = 0;
91
                }
92
            }
93
            else if (moveClockwise == 0)
94
            {
95
                if (canMove[0])
96
                {
97
                    finalMoveX = moveX[0];
98
                    finalMoveY = moveY[0];
99
                }
100
                else
101
                {
102
                    moveClockwise = 1;
103
                }
104
            }
105
            x += finalMoveX;
106
            y += finalMoveY;
107
            moveTimer++;
108
            if (moveTimer >= 0)
109
            {
110
                if (previousXPrevious == x && previousYPrevious == y)
111
                {
112
                    moveTimer = 999;
113
                    if (stuckbuff <= 0)
114
                    {
115
                        debug_print("stucks?");
116
                        stuckbuff = 30;
117
                        stuckcount++;
118
                        debug_message(stuckcount);
119
                    }
120
                    if (sndbuff <= 0)
121
                    {
122
                        snd_stop(snd_board_kill_ominous);
123
                        snd_play_x(snd_board_kill_ominous, 0.35, 1.4 + random(0.2));
124
                        sndcount++;
125
                        if (sndcount >= 3)
126
                        {
127
                            sndcount = 0;
128
                            sndbuff = 10;
129
                        }
130
                    }
131
                    x -= finalMoveX;
132
                    y -= finalMoveY;
133
                }
134
            }
135
            previousXPrevious = xprevious;
136
            previousYPrevious = yprevious;
137
        }
138
    }
139
    if (place_meeting(x, y, obj_board_swordhitbox))
140
    {
141
        instance_create(x, y, obj_board_enemydefeatsplash);
142
        global.flag[1255 sword_route_kills]++;
143
        instance_destroy();
144
    }
145
}