Stat bar and timer
This commit is contained in:
@@ -3,9 +3,7 @@ using Chickensoft.Collections;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace GameJamDungeon
|
||||
{
|
||||
@@ -65,11 +63,21 @@ namespace GameJamDungeon
|
||||
|
||||
[Node] public IHitbox Hitbox { get; set; } = default!;
|
||||
|
||||
[Node] public Timer HealthTimer { get; set; } = default!;
|
||||
|
||||
[Node] public Label HPNumber { get; set; } = default!;
|
||||
|
||||
[Node] public Label VTNumber { get; set; } = default!;
|
||||
|
||||
[Node] public ProgressBar HPBar { get; set; } = default!;
|
||||
|
||||
[Node] public ProgressBar VTBar { get; set; } = default!;
|
||||
|
||||
private IAutoProp<WeaponInfo> EquippedWeapon { get; set; } = default!;
|
||||
|
||||
private AutoProp<double> _currentHP { get; set; } = default!;
|
||||
|
||||
private IAutoProp<int> _currentVT { get; set; } = default!;
|
||||
private AutoProp<int> _currentVT { get; set; } = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -88,10 +96,22 @@ namespace GameJamDungeon
|
||||
PlayerLogic.Set(PlayerData);
|
||||
|
||||
GameRepo.SetPlayerGlobalPosition(GlobalPosition);
|
||||
GameRepo.PlayerGlobalPosition.Sync += OnPlayerPositionUpdated;
|
||||
|
||||
EquippedWeapon = new AutoProp<WeaponInfo>(WeaponInfo.Default);
|
||||
EquippedWeapon.Sync += OnEquippedWeaponChanged;
|
||||
|
||||
_currentHP = new AutoProp<double>(PlayerStatInfo.MaximumHP);
|
||||
_currentVT = new AutoProp<int>(PlayerStatInfo.MaximumVT);
|
||||
GameRepo.PlayerGlobalPosition.Sync += OnPlayerPositionUpdated;
|
||||
_currentHP.Sync += OnHPChanged;
|
||||
_currentVT.Sync += OnVTChanged;
|
||||
|
||||
HPBar.MaxValue = PlayerStatInfo.MaximumHP;
|
||||
HPBar.Value = _currentHP.Value;
|
||||
VTBar.MaxValue = PlayerStatInfo.MaximumVT;
|
||||
VTBar.Value = _currentVT.Value;
|
||||
|
||||
HealthTimer.Timeout += OnHealthTimerTimeout;
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
@@ -116,8 +136,6 @@ namespace GameJamDungeon
|
||||
this.Provide();
|
||||
PlayerLogic.Start();
|
||||
|
||||
EquippedWeapon.Sync += OnEquippedWeaponChanged;
|
||||
_currentHP.Sync += OnHPChanged;
|
||||
SwordSlashAnimation.Position = GetViewport().GetVisibleRect().Size / 2;
|
||||
}
|
||||
|
||||
@@ -178,10 +196,27 @@ namespace GameJamDungeon
|
||||
|
||||
private void OnHPChanged(double newHP)
|
||||
{
|
||||
HPNumber.Text = Mathf.RoundToInt(newHP).ToString();
|
||||
HPBar.Value = newHP;
|
||||
|
||||
if (newHP <= 0.0)
|
||||
PlayerLogic.Input(new PlayerLogic.Input.Killed());
|
||||
}
|
||||
|
||||
private void OnVTChanged(int newVT)
|
||||
{
|
||||
VTNumber.Text = newVT.ToString();
|
||||
VTBar.Value = newVT;
|
||||
}
|
||||
|
||||
private void OnPlayerPositionUpdated(Vector3 globalPosition) => GlobalPosition = globalPosition;
|
||||
|
||||
private void OnHealthTimerTimeout()
|
||||
{
|
||||
if (_currentVT.Value > 0)
|
||||
_currentVT.OnNext(_currentVT.Value - 1);
|
||||
else
|
||||
_currentHP.OnNext(_currentHP.Value - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,3 +156,47 @@ unique_name_in_owner = true
|
||||
scale = Vector2(9.03192, 6.39623)
|
||||
sprite_frames = SubResource("SpriteFrames_ywvvo")
|
||||
animation = &"attack"
|
||||
|
||||
[node name="HealthTimer" type="Timer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
wait_time = 3.0
|
||||
autostart = true
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/margin_left = 20
|
||||
theme_override_constants/margin_top = 20
|
||||
theme_override_constants/margin_right = 20
|
||||
theme_override_constants/margin_bottom = 20
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||
custom_minimum_size = Vector2(400, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
|
||||
[node name="HPNumber" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "HP: inf/inf"
|
||||
|
||||
[node name="HPBar" type="ProgressBar" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(0, 25)
|
||||
layout_mode = 2
|
||||
show_percentage = false
|
||||
|
||||
[node name="VTNumber" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "VT: inf/inf"
|
||||
|
||||
[node name="VTBar" type="ProgressBar" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(0, 25)
|
||||
layout_mode = 2
|
||||
show_percentage = false
|
||||
|
||||
Reference in New Issue
Block a user