summaryrefslogtreecommitdiff
path: root/air_shot.gd
blob: ba2688d95c82afcb3f2c4d0f947bb8c474bbe143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
extends Area2D


signal hit(node: Node2D)
signal end_of_life

var tween: Tween

@export var direction: float


func _ready() -> void:
	$Sound.play()
	$Sprite2D.flip_h = direction < 0
	
	tween = get_tree().create_tween()
	tween.tween_property(
		self,
		"global_position",
		global_position + Vector2(sign(direction) * 64, 0),
		0.3
	).set_ease(Tween.EASE_OUT)
	tween.tween_callback(func():
		end_of_life.emit()
	)


func _on_area_entered(area: Area2D) -> void:
	tween.stop()
	hit.emit(area)

func _on_body_entered(body: Node2D) -> void:
	tween.stop()
	hit.emit(body)