Deltarune (Chapter 5) script viewer

← back to main script listing

gml_GlobalScript_scr_plat_snap_to_ground

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

function
scr_plat_snap_to_ground()
{ var _ground = ground; if (!instance_exists(_ground)) exit; if (_ground.is_slope) { if (_ground.plattype == 0) { var _m; with (_ground) _m = (y2 - y1) / (x2 - x1); var _b = _ground.y1; var _floorX = bbox_right - _ground.x1; if (_ground.image_xscale < 0) _floorX = bbox_left - _ground.x1; floorY = (_m * _floorX) + _b; floorY = clamp(floorY, _ground.y2, _ground.y1); var _ydist = bbox_bottom_r + 2; var _newY = floorY - _ydist; var _solid = instance_place(x, _newY, obj_plat_block); if (!instance_exists(_solid)) y = _newY; } if (_ground.plattype == 1) { var _h; with (_ground) _h = y2 - y1; var _floorX = x - _ground.x1; floorY = _ground.y - (sin((pi * _floorX) / abs(_ground.x1 - _ground.x2)) * abs(_h)); var _newY = floorY - bbox_bottom_r; var _solid = instance_place(x, _newY, obj_plat_block); if (!instance_exists(_solid)) y = _newY; } } else { var _newY = y; var _offset = bbox_bottom_r; if (!ground.quicksand) { _newY = _ground.bbox_top - _offset - 1; if (_ground.is_entity) y = _ground.y - _ground.bbox_top_r - _offset - 1; } else { _newY = _ground.bbox_top - bbox_bottom_r - 1; } if (!place_meeting(x, _newY, obj_plat_block)) y = _newY; } }
()
2
{
3
    var _ground = ground;
4
    if (!instance_exists(_ground))
5
        exit;
6
    if (_ground.is_slope)
7
    {
8
        if (_ground.plattype == 0)
9
        {
10
            var _m;
11
            with (_ground)
12
                _m = (y2 - y1) / (x2 - x1);
13
            var _b = _ground.y1;
14
            var _floorX = bbox_right - _ground.x1;
15
            if (_ground.image_xscale < 0)
16
                _floorX = bbox_left - _ground.x1;
17
            floorY = (_m * _floorX) + _b;
18
            floorY = clamp(floorY, _ground.y2, _ground.y1);
19
            var _ydist = bbox_bottom_r + 2;
20
            var _newY = floorY - _ydist;
21
            var _solid = instance_place(x, _newY, obj_plat_block);
22
            if (!instance_exists(_solid))
23
                y = _newY;
24
        }
25
        if (_ground.plattype == 1)
26
        {
27
            var _h;
28
            with (_ground)
29
                _h = y2 - y1;
30
            var _floorX = x - _ground.x1;
31
            floorY = _ground.y - (sin((pi * _floorX) / abs(_ground.x1 - _ground.x2)) * abs(_h));
32
            var _newY = floorY - bbox_bottom_r;
33
            var _solid = instance_place(x, _newY, obj_plat_block);
34
            if (!instance_exists(_solid))
35
                y = _newY;
36
        }
37
    }
38
    else
39
    {
40
        var _newY = y;
41
        var _offset = bbox_bottom_r;
42
        if (!ground.quicksand)
43
        {
44
            _newY = _ground.bbox_top - _offset - 1;
45
            if (_ground.is_entity)
46
                y = _ground.y - _ground.bbox_top_r - _offset - 1;
47
        }
48
        else
49
        {
50
            _newY = _ground.bbox_top - bbox_bottom_r - 1;
51
        }
52
        if (!place_meeting(x, _newY, obj_plat_block))
53
            y = _newY;
54
    }
55
}