-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMoving Platform.gd
43 lines (30 loc) · 1.03 KB
/
Moving Platform.gd
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
extends Node2D
const IDLE = 0.5
export (String) var source
export (bool) var active = false
var moveTo
export (int) var dist
export (bool) var vertical
export var speed = 3.0
onready var platform = $Platform
onready var tween = $Tween
# Called when the node enters the scene tree for the first time.
func _ready():
get_parent().get_node(source).connect(str("repair_signal"), self, "on_repaired")
vertical = false
moveTo = Vector2.RIGHT * dist
func _process(delta):
if active:
_init_platform()
active = false
if vertical:
moveTo = Vector2.UP * dist
func _init_platform():
var duration = moveTo.length() / float(speed * 32) # Literal value is tile size
tween.interpolate_property(platform, "position", Vector2.ZERO, moveTo, duration, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT, IDLE)
tween.interpolate_property(platform, "position", moveTo, Vector2.ZERO, duration, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT, duration + IDLE * 2)
tween.start()
func on_repaired():
active = !active
func _on_Tween_tween_all_completed():
_init_platform()