52 lines
1.3 KiB
GDScript
52 lines
1.3 KiB
GDScript
extends KinematicBody2D
|
|
|
|
var fall = false
|
|
export var fall_speed = 0.5
|
|
onready var startpos = position
|
|
onready var fall_timer = $FallTimer
|
|
onready var refresh_timer = $RefreshTimer
|
|
onready var crush_area = $CrushArea
|
|
onready var collision_shape = $CollisionShape2D
|
|
onready var anims = $AnimationPlayer
|
|
|
|
func _physics_process(delta):
|
|
#Fall
|
|
if fall:
|
|
position.y += fall_speed
|
|
#Crush the player
|
|
for area in crush_area.get_overlapping_areas():
|
|
if area.is_in_group("player"):
|
|
var player = area.get_parent()
|
|
if player.is_on_floor():
|
|
player.die()
|
|
#Play animation when disappearing
|
|
if !refresh_timer.is_stopped() && refresh_timer.get_time_left() <= 0.6:
|
|
anims.play("disappear")
|
|
|
|
func _on_Area2D_area_entered(area):
|
|
if area.is_in_group("player"):
|
|
fall_timer.start()
|
|
|
|
|
|
func _on_VisibilityNotifier2D_screen_exited():
|
|
position = startpos
|
|
fall = false
|
|
refresh_timer.stop()
|
|
anims.play("disappear", -1, -1.0, true)
|
|
|
|
func _on_RefreshTimer_timeout():
|
|
collision_shape.disabled = true # disable collision
|
|
# re-enable collision and set position at end of frame
|
|
call_deferred("set_position", startpos)
|
|
collision_shape.call_deferred("set_disabled", false)
|
|
fall = false
|
|
anims.play("idle")
|
|
anims.play("disappear", -1, -1.0, true)
|
|
|
|
func _on_FallTimer_timeout():
|
|
fall = true
|
|
refresh_timer.start()
|
|
|
|
|
|
#func _on_Area2D_area_exited(area):
|
|
# fall_timer.stop()
|