-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.gd
More file actions
88 lines (63 loc) · 2.34 KB
/
main.gd
File metadata and controls
88 lines (63 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
@tool
extends Node
const CODE_NOSMOOTHING := \
"""func _motion_no_smoothing() -> void:
velocity = _target_velocity()"""
const CODE_LERP := \
"""func _motion_lerp(delta: float) -> void:
velocity = velocity.lerp(
_target_velocity(), lerp_acceleration * delta
)"""
const CODE_MOVETO := \
"""func _motion_moveto(delta: float) -> void:
velocity = velocity.move_toward(
_target_velocity(), moveto_acceleration * delta
)"""
@onready var _path_2d := $Path/Path2D as Path2D
@onready var _line_2d := $Path/Line2D as Line2D
@onready var _actor := $Actor as Actor
@onready var _actor_start := $ActorStart as Node2D
@onready var _actor_trail := $ActorTrail as Line2D
@onready var _speed := %Speed as Label
@onready var _lerp_accel := %LerpAccel as Label
@onready var _move_to_accel := %MoveToAccel as Label
@onready var _current_motion_type := %CurrentMotionType as Label
@onready var _screenshot_toggle := %ScreenshotToggle as CheckBox
@onready var _code_text := %CodeText as RichTextLabel
var _screenshot_count := 0
func _ready() -> void:
_path_2d.curve.changed.connect(_path_changed)
if not Engine.is_editor_hint():
_speed.text = str(_actor.speed)
_lerp_accel.text = str(_actor.lerp_acceleration)
_move_to_accel.text = str(_actor.moveto_acceleration)
func _physics_process(_delta: float) -> void:
if not Engine.is_editor_hint():
_actor_trail.add_point(
_actor_trail.to_local(_actor.global_position)
)
func _place_actor_at_start() -> void:
_actor.global_position = _actor_start.global_position
_actor_trail.points = []
_set_motion_type()
func _set_motion_type() -> void:
var current_motion_type := _actor.motion_type as int
current_motion_type = (current_motion_type + 1) % 3
_actor.motion_type = current_motion_type as Actor.MotionType
match _actor.motion_type:
Actor.MotionType.LERP:
_current_motion_type.text = "lerp"
_code_text.text = CODE_LERP
Actor.MotionType.MOVETO:
_current_motion_type.text = "move_to"
_code_text.text = CODE_MOVETO
_:
_current_motion_type.text = "no smoothing"
_code_text.text = CODE_NOSMOOTHING
func _take_screenshot() -> void:
if _screenshot_toggle.button_pressed:
var img = get_viewport().get_texture().get_image()
img.save_png("res://screenshots/screenshot_%d.png" % _screenshot_count)
_screenshot_count += 1
func _path_changed() -> void:
_line_2d.points = _path_2d.curve.get_baked_points()