extends StaticBody2D

const alarm = preload("res://Maps/Level1/Music/Alarm.wav")

func _on_area_2d_body_shape_entered(body_rid, body, body_shape_index, local_shape_index):
	if "can_move" in body:
		$CutsceneDetection.queue_free()
		body.can_move = false
		$Squeak.play()
		var tween = create_tween()
		#scale.y /= 2
		#position.y += 48
		
		await get_tree().create_timer(2).timeout
		#scale.y *= 2
		#position.y -= 48
		
		body.can_move = true
		$Sprite.queue_free()
		$Collider.queue_free()
		var video : VideoStreamPlayer = $Explosion
		video.play()
		#await video.finished
		var tilemap : TileMap = $"../TileMap"
		var player = $"../../Character"
		var sprite = player.find_child("Sprite")
		var light = player.find_child("LightSource")
		var vignette = Camera.find_child("Dark")
		var background = $"../ParallaxBackground/ParallaxLayer"
		tween = create_tween()
		tween.set_parallel(true)
		tween.set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_CUBIC)
		tween.tween_property(sprite, "self_modulate", Color8(100, 150, 255), 11)
		tween.tween_property(background, "modulate", Color8(25, 0, 0), 11)
		tween.tween_property(tilemap, "modulate", Color8(200, 0, 0), 11)
		tween.tween_property(light, "energy", .15, 11)
		tween.tween_property(vignette, "energy", 1.5, 11)
		tween.tween_property(vignette, "texture_scale", .5, 11)
		tween.tween_property(Camera, "zoom", Camera.zoom * 1.5, 11)
		tween.chain()
		tween.set_ease(Tween.EASE_OUT)
		tween.tween_property(Camera, "zoom", Camera.resetZoom(), 1)
		tween.tween_property(vignette, "texture_scale", 3 , 1)
		tween.tween_property(vignette, "energy", 0 , 2)
		tween.tween_property(light, "energy", 0 , 1)
		Music.stream = alarm
		Music.play()
		await tween.finished
		$"../Lava".enabled = true
		
		queue_free()

