@@ -17,57 +17,67 @@ const OPTION_MOVE_KINEMATIC_STOP_ON_SLOPE = "Move Options/Use stop on slope (Kin
1717
1818export (Vector2 ) var _initial_velocity = Vector2 .ZERO
1919export (Vector2 ) var _constant_velocity = Vector2 .ZERO
20+ export (float ) var _motion_speed = 400.0
21+ export (float ) var _gravity_force = 50.0
22+ export (float ) var _jump_force = 1000.0
2023export (float ) var _snap_distance = 0.0
2124export (float ) var _floor_max_angle = 45.0
2225export (E_BodyType ) var _body_type = 0
2326
27+ onready var options = $ Options
28+
2429var _use_snap = true
2530var _use_stop_on_slope = true
2631
32+ var _body_parent = null
2733var _rigid_body_template = null
2834var _kinematic_body_template = null
2935var _kinematic_body_ray_template = null
3036var _moving_body = null
3137
3238
3339func _ready ():
34- $ Options .connect ("option_selected" , self , "_on_option_selected" )
35- $ Options .connect ("option_changed" , self , "_on_option_changed" )
40+ options .connect ("option_selected" , self , "_on_option_selected" )
41+ options .connect ("option_changed" , self , "_on_option_changed" )
3642
3743 _rigid_body_template = find_node ("RigidBody2D" )
3844 if _rigid_body_template :
39- remove_child (_rigid_body_template )
45+ _body_parent = _rigid_body_template .get_parent ()
46+ _body_parent .remove_child (_rigid_body_template )
4047 var enabled = _body_type == E_BodyType .RIGID_BODY
41- $ Options .add_menu_item (OPTION_OBJECT_TYPE_RIGIDBODY , true , enabled , true )
48+ options .add_menu_item (OPTION_OBJECT_TYPE_RIGIDBODY , true , enabled , true )
4249
4350 _kinematic_body_template = find_node ("KinematicBody2D" )
4451 if _kinematic_body_template :
45- remove_child (_kinematic_body_template )
52+ _body_parent = _kinematic_body_template .get_parent ()
53+ _body_parent .remove_child (_kinematic_body_template )
4654 var enabled = _body_type == E_BodyType .KINEMATIC_BODY
47- $ Options .add_menu_item (OPTION_OBJECT_TYPE_KINEMATIC , true , enabled , true )
55+ options .add_menu_item (OPTION_OBJECT_TYPE_KINEMATIC , true , enabled , true )
4856
4957 _kinematic_body_ray_template = find_node ("KinematicBodyRay2D" )
5058 if _kinematic_body_ray_template :
51- remove_child (_kinematic_body_ray_template )
59+ _body_parent = _kinematic_body_ray_template .get_parent ()
60+ _body_parent .remove_child (_kinematic_body_ray_template )
5261 var enabled = _body_type == E_BodyType .KINEMATIC_BODY_RAY_SHAPE
53- $ Options .add_menu_item (OPTION_OBJECT_TYPE_KINEMATIC_RAYSHAPE , true , enabled , true )
62+ options .add_menu_item (OPTION_OBJECT_TYPE_KINEMATIC_RAYSHAPE , true , enabled , true )
5463
55- $ Options .add_menu_item (OPTION_MOVE_KINEMATIC_SNAP , true , _use_snap )
56- $ Options .add_menu_item (OPTION_MOVE_KINEMATIC_STOP_ON_SLOPE , true , _use_stop_on_slope )
64+ options .add_menu_item (OPTION_MOVE_KINEMATIC_SNAP , true , _use_snap )
65+ options .add_menu_item (OPTION_MOVE_KINEMATIC_STOP_ON_SLOPE , true , _use_stop_on_slope )
5766
5867 _start_test ()
5968
6069
6170func _process (_delta ):
71+ var label_floor = $ LabelFloor
6272 if _moving_body :
6373 if _moving_body .is_on_floor ():
64- $ LabelFloor .text = "ON FLOOR"
65- $ LabelFloor .self_modulate = Color .green
74+ label_floor .text = "ON FLOOR"
75+ label_floor .self_modulate = Color .green
6676 else :
67- $ LabelFloor .text = "OFF FLOOR"
68- $ LabelFloor .self_modulate = Color .red
77+ label_floor .text = "OFF FLOOR"
78+ label_floor .self_modulate = Color .red
6979 else :
70- $ LabelFloor .visible = false
80+ label_floor .visible = false
7181
7282
7383func _input (event ):
@@ -118,7 +128,7 @@ func _on_option_changed(option, checked):
118128
119129func _start_test ():
120130 if _moving_body :
121- remove_child (_moving_body )
131+ _body_parent . remove_child (_moving_body )
122132 _moving_body .queue_free ()
123133 _moving_body = null
124134
@@ -135,11 +145,15 @@ func _start_test():
135145
136146 test_label += template .name
137147 _moving_body = template .duplicate ()
138- add_child (_moving_body )
148+ _body_parent . add_child (_moving_body )
139149
140150 _moving_body ._initial_velocity = _initial_velocity
141151 _moving_body ._constant_velocity = _constant_velocity
142152
153+ _moving_body ._motion_speed = _motion_speed
154+ _moving_body ._gravity_force = _gravity_force
155+ _moving_body ._jump_force = _jump_force
156+
143157 if _moving_body is KinematicBody2D :
144158 if _use_snap :
145159 _moving_body ._snap = Vector2 (0 , _snap_distance )
0 commit comments