brackeys-12/water_level.gd

43 lines
1 KiB
GDScript3
Raw Permalink Normal View History

2024-09-14 03:00:13 +00:00
extends TileMapLayer
var movement_tween
var last_level = 0
@export var level: int
func _ready() -> void:
Triggerer.listen("flood_level", _on_flood_level)
func _on_flood_level(data):
var value = int(data.value)
var oldvalue = last_level
2024-09-14 21:02:18 +00:00
if value < level and visible:
2024-09-14 03:00:13 +00:00
if movement_tween:
movement_tween.kill()
movement_tween = create_tween()
2024-09-14 21:02:18 +00:00
movement_tween.set_ease(Tween.EASE_OUT)
movement_tween.set_trans(Tween.TRANS_BACK)
movement_tween.tween_interval(((oldvalue - level)) * 0.1)
movement_tween.tween_property(self, "position:y", 8, 0.1)
2024-09-14 03:00:13 +00:00
movement_tween.tween_callback(func():
visible = false
)
2024-09-14 21:02:18 +00:00
elif value >= level and not visible:
2024-09-14 03:00:13 +00:00
if movement_tween:
movement_tween.kill()
movement_tween = create_tween()
2024-09-14 21:02:18 +00:00
movement_tween.set_ease(Tween.EASE_OUT)
movement_tween.set_trans(Tween.TRANS_BACK)
movement_tween.tween_interval((level - oldvalue) * 0.1)
2024-09-14 03:00:13 +00:00
movement_tween.tween_callback(func():
position.y = 8
visible = true
)
2024-09-14 21:02:18 +00:00
movement_tween.tween_property(self, "position:y", 0, 0.1)
2024-09-14 03:00:13 +00:00
last_level = value