Files
Text-based/objects/enemies/enemy.gd

43 lines
1.2 KiB
GDScript3
Raw Permalink Normal View History

2025-10-16 05:26:03 +13:00
class_name Enemy
extends Node2D
@export var damage:int = 1
@export var max_health:int = 10
@export var speed:int = 10
@export var accuracy:int = 100
@export var max_money:int = 10
@export var level:int = 1
@export var level_multiplier:float = 1.2
@export var health_label:RichTextLabel
@export var animation_player:AnimationPlayer
var min_money:int = 1
var health:int = 0:
set(value):
health = value
if health != max_health:
if health_label != null:
if health <= round(max_health / 4):
health_label.text = "[color=red]" + str(health) + "[/color]" + " / " + str(max_health)
elif health <= round(max_health / 2):
health_label.text = "[color=yellow]" + str(health) + "[/color]" + " / " + str(max_health)
else:
health_label.text = str(health) + " / " + str(max_health)
if animation_player != null:
animation_player.play("hurt")
else:
health_label.text = str(health) + " / " + str(max_health)
func _ready() -> void:
if level > 1:
for i in range(level):
damage = round(damage * level_multiplier)
max_health = round(max_health * level_multiplier)
speed = round(speed * level_multiplier)
min_money = round(min_money * level_multiplier)
max_money = round(max_money * level_multiplier)
health = max_health