sword holster, health
This commit is contained in:
@@ -20,6 +20,8 @@ var _toggle_btn: Button
|
||||
var _spawner: Node
|
||||
var _player: Node = null
|
||||
var _cd_overlays: Array[ColorRect] = []
|
||||
var _health_segments: Array[ColorRect] = []
|
||||
var _health_connected: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -27,6 +29,7 @@ func _ready() -> void:
|
||||
process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
_build_controls_panel()
|
||||
_build_ability_bar()
|
||||
_build_health_bar()
|
||||
_find_spawner.call_deferred()
|
||||
|
||||
|
||||
@@ -36,6 +39,10 @@ func _process(_delta: float) -> void:
|
||||
if not players.is_empty():
|
||||
_player = players[0]
|
||||
return
|
||||
if not _health_connected:
|
||||
_health_connected = true
|
||||
_player.health_changed.connect(_on_health_changed)
|
||||
_on_health_changed(_player.health)
|
||||
for i: int in _cd_overlays.size():
|
||||
var fraction: float = _player.call(&"ability_cooldown_fraction", i)
|
||||
var ov := _cd_overlays[i]
|
||||
@@ -68,6 +75,57 @@ func _on_reset_pressed() -> void:
|
||||
_spawner.reset_spawn()
|
||||
|
||||
|
||||
func _build_health_bar() -> void:
|
||||
var bar := HBoxContainer.new()
|
||||
bar.add_theme_constant_override("separation", 4)
|
||||
bar.anchor_left = 0.5
|
||||
bar.anchor_right = 0.5
|
||||
bar.anchor_top = 0.0
|
||||
bar.anchor_bottom = 0.0
|
||||
bar.grow_horizontal = Control.GROW_DIRECTION_BOTH
|
||||
bar.offset_left = -90.0
|
||||
bar.offset_top = 16.0
|
||||
bar.offset_bottom = 16.0
|
||||
add_child(bar)
|
||||
|
||||
var bg_style := StyleBoxFlat.new()
|
||||
bg_style.bg_color = _BG
|
||||
bg_style.corner_radius_top_left = 4
|
||||
bg_style.corner_radius_top_right = 4
|
||||
bg_style.corner_radius_bottom_left = 4
|
||||
bg_style.corner_radius_bottom_right = 4
|
||||
bg_style.border_width_left = 1
|
||||
bg_style.border_width_right = 1
|
||||
bg_style.border_width_top = 1
|
||||
bg_style.border_width_bottom = 1
|
||||
bg_style.border_color = _BORDER
|
||||
bg_style.content_margin_left = 6.0
|
||||
bg_style.content_margin_right = 6.0
|
||||
bg_style.content_margin_top = 6.0
|
||||
bg_style.content_margin_bottom = 6.0
|
||||
|
||||
var panel := PanelContainer.new()
|
||||
panel.add_theme_stylebox_override("panel", bg_style)
|
||||
bar.add_child(panel)
|
||||
|
||||
var inner := HBoxContainer.new()
|
||||
inner.add_theme_constant_override("separation", 3)
|
||||
panel.add_child(inner)
|
||||
|
||||
for i: int in 10:
|
||||
var seg := ColorRect.new()
|
||||
seg.custom_minimum_size = Vector2(14.0, 14.0)
|
||||
seg.color = Color(0.72, 0.08, 0.08)
|
||||
inner.add_child(seg)
|
||||
_health_segments.append(seg)
|
||||
|
||||
|
||||
func _on_health_changed(new_health: int) -> void:
|
||||
for i: int in _health_segments.size():
|
||||
_health_segments[i].color = Color(0.72, 0.08, 0.08) if i < new_health \
|
||||
else Color(0.20, 0.10, 0.10)
|
||||
|
||||
|
||||
func _build_ability_bar() -> void:
|
||||
var bar := HBoxContainer.new()
|
||||
bar.add_theme_constant_override("separation", 10)
|
||||
|
||||
Reference in New Issue
Block a user