summaryrefslogtreecommitdiff
path: root/stage/player_unit.gd
blob: ca3565aa9cf334017f71855139e2c2791cac9f31 (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
35
36
37
38
39
40
class_name PlayerUnit
extends Node2D


@export var direction: Corner = CORNER_BOTTOM_RIGHT
@export var max_hp := 0
@export var current_team: String

var current_hp := 0:
	set(value):
		current_hp = value
		$Label.text = str(value)


func _ready() -> void:
	current_hp = max_hp
	$Label.visible = false
	
	var grid_selector := get_tree().get_first_node_in_group("grid_selector") as GridSelector
	grid_selector.hover_enter.connect(func(node: Node2D):
		$Label.visible = node == self
	)
	grid_selector.hover_exit.connect(func():
		$Label.visible = false
	)


func _process(_delta: float) -> void:
	if direction == CORNER_TOP_LEFT:
		$AnimatedSprite2D.play("top_left")
		$AnimatedSprite2D.flip_h = false
	elif direction == CORNER_TOP_RIGHT:
		$AnimatedSprite2D.play("top_left")
		$AnimatedSprite2D.flip_h = true
	elif direction == CORNER_BOTTOM_LEFT:
		$AnimatedSprite2D.play("bottom_right")
		$AnimatedSprite2D.flip_h = true
	elif direction == CORNER_TOP_LEFT:
		$AnimatedSprite2D.play("bottom_right")
		$AnimatedSprite2D.flip_h = false