Deltarune (Chapter 4) script viewer

← back to main script listing

gml_Object_obj_train_piece_parent_Other_10

(view raw script w/o annotations or w/e)
1
if (position_factor == 1)
2
{
3
    if (current_track.object_index == obj_traintrack_goal)
4
    {
5
        if (train_index == (controller.train_piece_num - 1))
6
            controller.reached_goal = true;
7
        with (obj_train_station)
8
        {
9
            if (heartontrain)
10
                heartontrain = false;
11
        }
12
        visible = false;
13
        exit;
14
    }
15
    dir = (current_track_exit_angle + (controller.reversing * 180)) % 360;
16
    image_index = dir div 90;
17
    var _trackstop = collision_point(x + lengthdir_x(10, current_track_exit_angle), y + lengthdir_y(10, current_track_exit_angle), obj_traintrack_stop, false, true);
18
    if (_trackstop != -4)
19
    {
20
        controller.active = false;
21
        controller.do_reverse = true;
22
        controller.reverse_active = true;
23
        exit;
24
    }
25
    var _track = collision_point(x + lengthdir_x(10, current_track_exit_angle), y + lengthdir_y(10, current_track_exit_angle), obj_traintrack_parent, false, true);
26
    var _found_piece = false;
27
    if (instance_exists(obj_train_icee))
28
    {
29
        if (place_meeting(x + lengthdir_x(10, current_track_exit_angle), y + lengthdir_y(10, current_track_exit_angle), obj_train_icee) && !obj_train_icee.can_pass)
30
        {
31
            if ((train_index == 0 && controller.reversing == false) || (train_index == (controller.train_piece_num - 1) && controller.reversing == true))
32
            {
33
                _track = -4;
34
                controller.reverse_active = true;
35
                controller.heartontrain = false;
36
                obj_homealone_heart.freeze = 0;
37
                with (obj_train_station)
38
                    heartontrain = false;
39
            }
40
        }
41
    }
42
    if (_track != -4 && _track.train_occupied == false)
43
    {
44
        var _required_angle = (current_track_exit_angle + 180) % 360;
45
        var _required_angle2 = current_track_exit_angle;
46
        if (_track.object_index == obj_traintrack_goal || _track.object_index == obj_traintrack_fourway || _track.entrance_a_angle == _required_angle || _track.entrance_b_angle == _required_angle || _track.entrance_a_angle == _required_angle2 || _track.entrance_b_angle == _required_angle2)
47
        {
48
            prev_x = x;
49
            prev_y = y;
50
            with (current_track)
51
                train_occupied = false;
52
            with (_track)
53
            {
54
                if (object_index != obj_traintrack_goal)
55
                    train_occupied = true;
56
            }
57
            current_track_entrance_angle = _required_angle;
58
            if (_track.object_index != obj_traintrack_fourway)
59
            {
60
                if (_track.entrance_a_angle == _required_angle)
61
                    current_track_exit_angle = _track.entrance_b_angle;
62
                else
63
                    current_track_exit_angle = _track.entrance_a_angle;
64
            }
65
            position_factor = 0;
66
            current_track = _track;
67
            _found_piece = true;
68
        }
69
    }
70
    if (!_found_piece)
71
    {
72
        if ((train_index == 0 && controller.reversing == false) || (train_index == (controller.train_piece_num - 1) && controller.reversing == true))
73
            controller.do_reverse = true;
74
    }
75
}
76
if (position_factor < 1)
77
{
78
    position_factor += (controller.train_speed / 10);
79
    position_factor = clamp(position_factor, 0, 1);
80
    x = lerp(prev_x, current_track.x + 5, position_factor);
81
    y = lerp(prev_y, current_track.y + 5, position_factor);
82
}