Deltarune (Chapter 4) script viewer

← back to main script listing

gml_GlobalScript_distance_to_object_bbox

(view raw script w/o annotations or w/e)
1
function distance_to_object_bbox(arg0 = id, arg1, arg2 = 0)
2
{
3
    var point1x = arg0.bbox_left + ((arg0.bbox_right - arg0.bbox_left) / 2);
4
    var point1y = arg0.bbox_top + ((arg0.bbox_bottom - arg0.bbox_top) / 2);
5
    var point2x = arg1.bbox_left + ((arg1.bbox_right - arg1.bbox_left) / 2);
6
    var point2y = arg1.bbox_top + ((arg1.bbox_bottom - arg1.bbox_top) / 2);
7
    if (arg2)
8
    {
9
        if (
scr_debug
scr_debug

function
scr_debug()
{ if (global.debug == 1) return 1; }
())
10
        {
11
            var memcol = draw_get_color();
12
            var memalpha = draw_get_alpha();
13
            draw_set_color(c_red);
14
            draw_set_alpha(0.8);
15
            draw_line(point1x, point1y, point2x, point2y);
16
            ossafe_fill_rectangle(arg0.bbox_left, arg0.bbox_top, arg0.bbox_right + 1, arg0.bbox_bottom + 1, 0);
17
            ossafe_fill_rectangle(arg1.bbox_left, arg1.bbox_top, arg1.bbox_right + 1, arg1.bbox_bottom + 1, 0);
18
            draw_set_color(memcol);
19
            draw_set_alpha(memalpha);
20
        }
21
    }
22
    return point_distance(point1x, point1y, point2x, point2y);
23
}
24
25
function direction_to_object_bbox(arg0 = id, arg1, arg2 = false, arg3 = 0)
26
{
27
    var point1x = arg0.bbox_left + ((arg0.bbox_right - arg0.bbox_left) / 2);
28
    var point1y = arg0.bbox_top + ((arg0.bbox_bottom - arg0.bbox_top) / 2);
29
    var point2x = arg1.bbox_left + ((arg1.bbox_right - arg1.bbox_left) / 2);
30
    var point2y = arg1.bbox_top + ((arg1.bbox_bottom - arg1.bbox_top) / 2);
31
    if (arg3)
32
    {
33
        if (
scr_debug
scr_debug

function
scr_debug()
{ if (global.debug == 1) return 1; }
())
34
        {
35
            var memcol = draw_get_color();
36
            var memalpha = draw_get_alpha();
37
            draw_set_color(c_red);
38
            draw_set_alpha(0.8);
39
            draw_line(point1x, point1y, point2x, point2y);
40
            ossafe_fill_rectangle(arg0.bbox_left, arg0.bbox_top, arg0.bbox_right + 1, arg0.bbox_bottom + 1, 0);
41
            ossafe_fill_rectangle(arg1.bbox_left, arg1.bbox_top, arg1.bbox_right + 1, arg1.bbox_bottom + 1, 0);
42
            draw_set_color(memcol);
43
            draw_set_alpha(memalpha);
44
        }
45
    }
46
    var dir = point_direction(point1x, point1y, point2x, point2y);
47
    if (arg2)
48
    {
49
        dir += 90;
50
        if (dir > 360)
51
            dir -= 360;
52
        dir = round(dir / 90);
53
        if (dir == 4)
54
            dir = 0;
55
    }
56
    return dir;
57
}