Health and shield gauges

This commit is contained in:
Marco 2025-02-11 17:55:50 +01:00
commit 3682de18d5
14 changed files with 188 additions and 22 deletions

View file

@ -8,12 +8,22 @@
"sound_moods": {},
"style": ""
},
"default_portrait": "",
"default_portrait": "Default",
"description": "",
"display_name": "Navigator",
"mirror": false,
"nicknames": [""],
"offset": Vector2(0, 0),
"portraits": {},
"portraits": {
"Default": {
"export_overrides": {
"image": "\"res://Sprites/Portraits/Navigator.png\""
},
"mirror": false,
"offset": Vector2(0, 0),
"scale": 1,
"scene": ""
}
},
"scale": 1.0
}

View file

@ -30,6 +30,7 @@ overrides = {}
script = ExtResource("1_5pbjb")
scene = ExtResource("4_m8ph6")
overrides = {
"box_distance": "8.0",
"box_size": "Vector2(300, 80)",
"name_label_custom_size": "9.0",
"name_label_use_global_size": "false",

View file

@ -1 +1,8 @@
Cirno: Test message intro
Cirno: Navigator, I infiltrated the facility!
Navigator: Very good, Cirno.\
Do you remember your mission?
Cirno: No...
Navigator: Try to remember it this time\: Your mission is to infiltrate the refining facility and retrieve the artifact from your world.
Navigator: Be careful, I'm picking up a lot of activity on the local network, it seems like the facility is on lockdown due to an external threat, but to my knowledge it's none of us.
Cirno: Don't worry, whatever it is I can deal with it!
Navigator: I really hope that's the case. Anyway try to use any terminal you may find, we might be able to find more information that way. Also try to remain undetected for as long as possible, cameras might summon reinforcements to your location if you get spotted.

View file

@ -0,0 +1,9 @@
[gd_resource type="LabelSettings" load_steps=2 format=3 uid="uid://buk3e7bbwmnv1"]
[ext_resource type="FontFile" uid="uid://ccm3u37q1hvux" path="res://fonts/Xolonium-Regular.ttf" id="1_kewj4"]
[resource]
font = ExtResource("1_kewj4")
font_size = 8
outline_size = 4
outline_color = Color(0, 0, 0, 1)

View file

@ -24,9 +24,11 @@ _playerDetection = NodePath("PlayerDetection")
sprite_frames = ExtResource("2_omkb8")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
visible = false
shape = SubResource("CircleShape2D_nkpag")
[node name="PlayerDetection" type="Area2D" parent="."]
visible = false
collision_layer = 16
collision_mask = 2
script = ExtResource("3_ax0x5")
@ -37,6 +39,7 @@ SpritePath = NodePath("../AnimatedSprite2D")
shape = SubResource("CircleShape2D_gs7jc")
[node name="DamageHitbox" type="Area2D" parent="."]
visible = false
collision_layer = 16
collision_mask = 9

View file

@ -45,6 +45,7 @@ size = Vector2(8, 12)
collision_layer = 16
collision_mask = 9
script = ExtResource("1_lpwdj")
Health = 6.0
EquippedWeapon = NodePath("Weapon")
_playerDetection = NodePath("PlayerDetection")
_navigationEnabled = true

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=7 format=3 uid="uid://dkwi1hu1bixoe"]
[gd_scene load_steps=12 format=3 uid="uid://dkwi1hu1bixoe"]
[ext_resource type="Script" path="res://Scripts/Hud.cs" id="1_m0hb0"]
[ext_resource type="FontFile" uid="uid://ccm3u37q1hvux" path="res://fonts/Xolonium-Regular.ttf" id="2_0xmx2"]
[ext_resource type="LabelSettings" uid="uid://buk3e7bbwmnv1" path="res://Resources/Styles/Hud_Text_Style.tres" id="2_x7kl7"]
[ext_resource type="Texture2D" uid="uid://dde36pgb8fbwc" path="res://Sprites/selector_big.png" id="3_hee3i"]
[sub_resource type="AtlasTexture" id="AtlasTexture_h626b"]
@ -26,10 +27,32 @@ animations = [{
"speed": 5.0
}]
[node name="HUD" type="CanvasLayer" node_paths=PackedStringArray("_healthLabel", "_itemsContainer")]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_wu6au"]
bg_color = Color(0.437742, 0.0512416, 0.0286274, 1)
border_color = Color(0.197934, 0.0027957, 1.8049e-08, 1)
anti_aliasing = false
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_5f4mf"]
bg_color = Color(0.958101, 0.255223, 3.85046e-07, 1)
anti_aliasing = false
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_crjx4"]
bg_color = Color(0.120626, 7.70092e-07, 0.682086, 1)
border_color = Color(0.197934, 0.0027957, 1.8049e-08, 1)
anti_aliasing = false
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_rxnbp"]
bg_color = Color(0.338981, 0.507716, 0.996646, 1)
anti_aliasing = false
[node name="HUD" type="CanvasLayer" node_paths=PackedStringArray("_healthLabel", "_healthBar", "_shieldLabel", "_shieldBar", "_itemsContainer")]
script = ExtResource("1_m0hb0")
_healthLabel = NodePath("VBoxContainer/HealthLabel")
_healthLabel = NodePath("VBoxContainer/HealthBarContainer/HealthLabel")
_healthBar = NodePath("VBoxContainer/HealthBarContainer/HealthBar")
_shieldLabel = NodePath("VBoxContainer/ShieldBarContainer/ShieldLabel")
_shieldBar = NodePath("VBoxContainer/ShieldBarContainer/ShieldBar")
_itemsContainer = NodePath("VBoxContainer/ItemsContainer")
_labelSettings = ExtResource("2_x7kl7")
[node name="GameOver" type="Label" parent="."]
visible = false
@ -65,18 +88,48 @@ anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 4.0
offset_top = 6.0
offset_right = -4.0
offset_right = -235.0
offset_bottom = -3.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 0
[node name="HealthLabel" type="Label" parent="VBoxContainer"]
[node name="HealthBarContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
[node name="HealthBar" type="ProgressBar" parent="VBoxContainer/HealthBarContainer"]
custom_minimum_size = Vector2(32, 8)
layout_mode = 2
size_flags_vertical = 4
theme_override_styles/background = SubResource("StyleBoxFlat_wu6au")
theme_override_styles/fill = SubResource("StyleBoxFlat_5f4mf")
value = 50.0
show_percentage = false
[node name="HealthLabel" type="Label" parent="VBoxContainer/HealthBarContainer"]
layout_mode = 2
theme_override_fonts/font = ExtResource("2_0xmx2")
theme_override_font_sizes/font_size = 12
text = "100/100"
label_settings = ExtResource("2_x7kl7")
[node name="ShieldBarContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
[node name="ShieldBar" type="ProgressBar" parent="VBoxContainer/ShieldBarContainer"]
custom_minimum_size = Vector2(32, 8)
layout_mode = 2
size_flags_vertical = 4
theme_override_styles/background = SubResource("StyleBoxFlat_crjx4")
theme_override_styles/fill = SubResource("StyleBoxFlat_rxnbp")
value = 50.0
show_percentage = false
[node name="ShieldLabel" type="Label" parent="VBoxContainer/ShieldBarContainer"]
layout_mode = 2
text = "100/100"
label_settings = ExtResource("2_x7kl7")
[node name="ItemsContainer" type="VBoxContainer" parent="VBoxContainer"]
layout_mode = 2
theme_override_constants/separation = 0

View file

@ -40,5 +40,6 @@ position = Vector2(0, -3)
shape = SubResource("RectangleShape2D_ss2y0")
[node name="NavigationObstacle2D" type="NavigationObstacle2D" parent="."]
visible = false
radius = 8.36
vertices = PackedVector2Array(-6, -9, 6, -9, 6, 2, -6, 2)

File diff suppressed because one or more lines are too long

View file

@ -95,6 +95,8 @@ public partial class GameManager : Node2D
{
_player.HealthChanged += (newHealth, maxHealth) => _hud.UpdateHealth(newHealth, maxHealth);
_player.ShieldChanged += (newShield, maxShield) => _hud.UpdateShield(newShield, maxShield);
_player.InteractableAreaEntered += (interactable) => _hud.UpdateInteractable(interactable);
}
}

View file

@ -19,8 +19,15 @@ public partial class Hud : CanvasLayer
private Node2D _selector;
[Export] private Label _healthLabel;
[Export] private ProgressBar _healthBar;
[Export] private Label _shieldLabel;
[Export] private ProgressBar _shieldBar;
[Export] private Container _itemsContainer;
[Export] private LabelSettings _labelSettings;
private Dictionary<string, HudItem> _items = new();
public override void _Ready()
@ -56,6 +63,19 @@ public partial class Hud : CanvasLayer
public void UpdateHealth(float newHealth, float maxHealth)
{
_healthLabel.Text = $"{newHealth}/{maxHealth}";
if (_healthBar != null)
{
_healthBar.Value = newHealth;
}
}
public void UpdateShield(float newValue, float maxValue)
{
_shieldLabel.Text = $"{newValue}/{maxValue}";
if (_shieldBar != null)
{
_shieldBar.Value = newValue;
}
}
public void UpdateInteractable(Interactable interactable) {
@ -110,10 +130,7 @@ public partial class Hud : CanvasLayer
// label.Text = currentAmount.ToString();
// }
label.LabelSettings = new LabelSettings()
{
FontSize = 8
};
label.LabelSettings = _labelSettings;
hbox.AddChild(label);
hudItem.Label = label;

View file

@ -35,7 +35,6 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
private AnimatedSprite2D _animatedSprite;
private Vector2 _movementDirection { get; set; }
private Vector2 _facingDirection { get; set; }
private Vector2 _rightStickInput { get; set; }
@ -43,6 +42,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
private Sprite2D _crosshair;
[Export] public float MaxHealth = 32f;
[Export] public float MaxShield = 32f;
public Weapon EquippedWeapon { get; set; }
@ -51,6 +51,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
public int CurrentWeaponIndex { get; set; } = 0;
private float _currentHealth = 0f;
private float _currentShield = 0f;
private bool _isDestroyed = false;
@ -67,6 +68,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
[Signal]
public delegate void HealthChangedEventHandler(float newHealth, float MaxHealth);
[Signal]
public delegate void ShieldChangedEventHandler(float newShield, float maxShield);
[Signal]
public delegate void InteractableAreaEnteredEventHandler(Interactable interactable);
@ -86,11 +90,25 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
}
}
public float CurrentShield
{
get => _currentShield;
set
{
if (_currentShield != value)
{
_currentShield = value;
EmitSignal(nameof(ShieldChanged), _currentShield, MaxShield);
}
}
}
//private InventoryManager _inventoryManager;
public override void _Ready()
{
CurrentHealth = MaxHealth;
CurrentShield = MaxShield;
_animatedSprite = GetNode<AnimatedSprite2D>("./Smoothing2D/AnimatedSprite2D");
_crosshair = GetNode<Sprite2D>("./Smoothing2D/Crosshair");

BIN
Sprites/Portraits/Navigator.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dgq88e6y3twew"
path="res://.godot/imported/Navigator.png-1212ae5cae0c10510a5af90c25cb2683.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/Portraits/Navigator.png"
dest_files=["res://.godot/imported/Navigator.png-1212ae5cae0c10510a5af90c25cb2683.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1