39 lines
841 B
GDScript3
39 lines
841 B
GDScript3
|
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
|
||
|
|
||
|
if value < level:
|
||
|
if movement_tween:
|
||
|
movement_tween.kill()
|
||
|
|
||
|
movement_tween = create_tween()
|
||
|
movement_tween.tween_interval(((oldvalue - level)) * 0.5)
|
||
|
movement_tween.tween_property(self, "position:y", 8, 0.5)
|
||
|
movement_tween.tween_callback(func():
|
||
|
visible = false
|
||
|
)
|
||
|
else:
|
||
|
if movement_tween:
|
||
|
movement_tween.kill()
|
||
|
|
||
|
movement_tween = create_tween()
|
||
|
movement_tween.tween_interval((level - oldvalue) * 0.5)
|
||
|
movement_tween.tween_callback(func():
|
||
|
position.y = 8
|
||
|
visible = true
|
||
|
)
|
||
|
movement_tween.tween_property(self, "position:y", 0, 0.5)
|
||
|
|
||
|
last_level = value
|