summaryrefslogtreecommitdiff
path: root/scripts/soldier.gd
blob: d373237eae88f0f9a757ed94b171844ab34afb2c (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
extends CharacterBody2D

@export var worth : int = 5
@export var damage : int = 1
@export var speed : float = 50.0
@export var max_health : float = 30.0
var _health : float = max_health

func _process(delta):
	get_parent().set_progress(get_parent().get_progress() + speed * delta)
	if get_parent().get_progress_ratio() == 1:
		GameData.subtract_morale(damage)
		queue_free()

func deal_damage(tower_damage):
	_health -= tower_damage
	if _health <= 0:
		GameData.add_life(worth)
		queue_free()
	else:
		_update_color()

func _update_color():
	var ratio : float = _health / max_health
	var target_color = Color(1, ratio, ratio)

	$Sprite2D.modulate = target_color