summaryrefslogtreecommitdiff
path: root/dicaprio.gd
blob: fa298b7fa59ada8f0d673e77865a5f34c39f8e55 (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
extends Area2D

@onready var player: Node2D = get_node("../Player")
@export var speed = 2.0
@export var life = 3.0


func type() -> String: return "dicaprio"


func _physics_process(_delta: float) -> void:
	$Glitch.position = Vector2(randf_range(-16, 16), randf_range(-16, 16))
	$Glitch.modulate.r = randi() % 2
	$Glitch.modulate.g = randi() % 2
	$Glitch.modulate.b = randi() % 2
	position += (player.position - position).normalized() * speed


func _on_area_entered(area: Area2D) -> void:
	match area.type():
		"arrow":
			area.damage(self)
		"dicaprio":
			position -= (area.position - position).normalized() * speed * 2


func damage(x: float) -> void:
	life -= x
	if life <= 0:
		Globals.spawn_primogem(position)
		queue_free()