Stomp fix

This commit is contained in:
Sagi Dayan 2020-11-26 23:27:58 -05:00
parent 03596b833e
commit 740d3c9dba
2 changed files with 15 additions and 11 deletions

View file

@ -140,7 +140,6 @@ position = Vector2( 104, 40 )
to_point = Vector2( 94, 0 ) to_point = Vector2( 94, 0 )
duration = 0.8 duration = 0.8
delay = 0.2 delay = 0.2
g = "UP_DOWN"
[node name="SpikeTrap" parent="Hazards" instance=ExtResource( 18 )] [node name="SpikeTrap" parent="Hazards" instance=ExtResource( 18 )]
position = Vector2( 383, 48 ) position = Vector2( 383, 48 )

View file

@ -7,18 +7,23 @@ export var duration := 2.0 setget set_duration
export var delay := .5 setget set_delay export var delay := .5 setget set_delay
export(String, "UP_DOWN", "LEFT_RIGHT") var g = "UP_DOWN" export(String, "UP_DOWN", "LEFT_RIGHT") var g = "UP_DOWN"
onready var tween = $Tween var sprite:Sprite
onready var sprite = $Sprite var tween:Tween
var _is_ready = false var _is_ready = false
func _ready() -> void: func _ready() -> void:
_is_ready = true; _is_ready = true
sprite = $Sprite
tween = $Tween
tween.repeat = true
start_motion() start_motion()
func _enter_tree() -> void:
if _is_ready: tween.resume_all()
func _on_DeathZone_body_entered(body:Node) -> void: func _on_DeathZone_body_entered(body:Node) -> void:
if body.name == "Player": if body.name == "Player":
body.die() body.die()
func set_to_position(val): func set_to_position(val):
print("set_to_position") print("set_to_position")
@ -35,14 +40,14 @@ func set_delay(val):
print("set_delay") print("set_delay")
delay = val delay = val
start_motion() start_motion()
func start_motion(): func start_motion():
if not _is_ready: return if not _is_ready: return
print("Stomp Start Motion") print("Stomp Start Motion")
sprite.position = Vector2.ZERO sprite.position = Vector2.ZERO
tween.stop_all() tween.stop_all()
tween.repeat = true tween.remove_all()
tween.interpolate_property(sprite, "position", Vector2.ZERO, to_point, duration, Tween.TRANS_LINEAR, Tween.EASE_IN, delay) print(tween.interpolate_property(sprite, "position", Vector2.ZERO, to_point, duration, Tween.TRANS_LINEAR, Tween.EASE_IN, delay))
tween.interpolate_property(sprite, "position", to_point, Vector2.ZERO, duration, Tween.TRANS_LINEAR, Tween.EASE_IN, duration+(delay*2)) print(tween.interpolate_property(sprite, "position", to_point, Vector2.ZERO, duration, Tween.TRANS_LINEAR, Tween.EASE_IN, duration+(delay*2)))
tween.start() print(tween.start())