57 lines
2.1 KiB
GDScript
57 lines
2.1 KiB
GDScript
extends Node2D
|
|
|
|
var enemy: CharacterBody2D
|
|
var _tier_label: Label
|
|
|
|
func _ready() -> void:
|
|
enemy = get_parent() as CharacterBody2D
|
|
top_level = true
|
|
z_index = 30
|
|
light_mask = 4
|
|
_tier_label = Label.new()
|
|
_tier_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
_tier_label.light_mask = 4
|
|
_tier_label.position = Vector2(-50, -23)
|
|
_tier_label.size = Vector2(100, 16)
|
|
_tier_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
_tier_label.add_theme_font_size_override("font_size", 11)
|
|
_tier_label.add_theme_color_override("font_outline_color", Color("08111d"))
|
|
_tier_label.add_theme_constant_override("outline_size", 3)
|
|
add_child(_tier_label)
|
|
_update_position()
|
|
_update_tier_label()
|
|
|
|
func _process(_delta: float) -> void:
|
|
_update_position()
|
|
_update_tier_label()
|
|
queue_redraw()
|
|
|
|
func _update_position() -> void:
|
|
global_position = enemy.global_position + Vector2(0, -enemy.get_visual_size() * 0.5 - 12.0)
|
|
|
|
func _tier_color() -> Color:
|
|
if bool(enemy.get("virus_controlled")):
|
|
return Color("c57dff")
|
|
return Color("ff76d6") if enemy.loot_tier == 2 else (Color("ffc785") if enemy.loot_tier == 1 else Color("ef5967"))
|
|
|
|
func _update_tier_label() -> void:
|
|
_tier_label.text = "BOSS" if enemy.loot_tier == 2 else ("ELITA" if enemy.loot_tier == 1 else "")
|
|
if bool(enemy.get("virus_controlled")):
|
|
_tier_label.text = "WIRUS"
|
|
_tier_label.add_theme_color_override("font_color", _tier_color())
|
|
|
|
func get_health_ratio() -> float:
|
|
return clampf(enemy.hull / maxf(enemy.max_hull, 0.001), 0.0, 1.0)
|
|
|
|
func _draw() -> void:
|
|
if not is_instance_valid(enemy) or enemy.hull <= 0.0:
|
|
return
|
|
var width := 72.0 if enemy.loot_tier == 2 else (56.0 if enemy.loot_tier == 1 else 44.0)
|
|
var background := Rect2(-width * 0.5, -3.0, width, 6.0)
|
|
draw_rect(background.grow(1.0), Color("08111dee"))
|
|
draw_rect(background, Color("39232bee"))
|
|
draw_rect(Rect2(-width * 0.5, 5.0, width, 3.0), Color("142a3d"))
|
|
draw_rect(Rect2(-width * 0.5, 5.0, width * clampf(enemy.shields / maxf(1.0, enemy.max_shields), 0.0, 1.0), 3.0), Color("67cfff"))
|
|
var color := _tier_color()
|
|
draw_rect(Rect2(background.position, Vector2(width * get_health_ratio(), 6.0)), color)
|