mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 03:15:55 +00:00
Ammo UI system
This commit is contained in:
parent
70c514f1a9
commit
5eb7b578bc
22 changed files with 238 additions and 87 deletions
|
|
@ -1,6 +1,10 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Cirno.Scripts;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class GameManager : Node2D
|
||||
{
|
||||
|
|
@ -22,6 +26,10 @@ public partial class GameManager : Node2D
|
|||
[Export]
|
||||
public Marker2D PlayerSpawnMarker { get; set; }
|
||||
|
||||
[Export] public PackedScene WeaponTemplate { get; private set; }
|
||||
|
||||
[Export] public Array<LootItem> StartingEquipment { get; private set; }
|
||||
|
||||
private InventoryManager _inventoryManager { get; set; }
|
||||
|
||||
//private AlarmManager _alarmManager { get; set; }
|
||||
|
|
@ -52,25 +60,15 @@ public partial class GameManager : Node2D
|
|||
|
||||
SpawnBulletsContainer();
|
||||
|
||||
if (PlayerSpawnMarker != null)
|
||||
{
|
||||
SpawnPlayer();
|
||||
}
|
||||
|
||||
if (_inventoryManager != null && _hud != null)
|
||||
{
|
||||
_inventoryManager.ItemAdded += (item, currentAmount) => _hud.AddInventoryItem(item, currentAmount);
|
||||
_inventoryManager.ItemRemoved += (item, currentAmount) => _hud.RemoveInventoryItem(item, currentAmount);
|
||||
}
|
||||
|
||||
if (_player != null && _hud != null)
|
||||
{
|
||||
_player.HealthChanged += (newHealth, maxHealth) => _hud.UpdateHealth(newHealth, maxHealth);
|
||||
|
||||
_player.InteractableAreaEntered += (interactable) => _hud.UpdateInteractable(interactable);
|
||||
}
|
||||
|
||||
GameState = GameState.Playing;
|
||||
|
||||
_ = DelayPlayerSpawn();
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
|
@ -82,6 +80,25 @@ public partial class GameManager : Node2D
|
|||
}
|
||||
}
|
||||
|
||||
private async Task DelayPlayerSpawn()
|
||||
{
|
||||
await Task.Delay(500);
|
||||
|
||||
if (PlayerSpawnMarker != null)
|
||||
{
|
||||
SpawnPlayer();
|
||||
|
||||
SpawnWeapons();
|
||||
}
|
||||
|
||||
if (_player != null && _hud != null)
|
||||
{
|
||||
_player.HealthChanged += (newHealth, maxHealth) => _hud.UpdateHealth(newHealth, maxHealth);
|
||||
|
||||
_player.InteractableAreaEntered += (interactable) => _hud.UpdateInteractable(interactable);
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnPlayer()
|
||||
{
|
||||
if (_player != null) return;
|
||||
|
|
@ -99,6 +116,35 @@ public partial class GameManager : Node2D
|
|||
_cameraTarget.GlobalPosition = _player.Position;
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnWeapons()
|
||||
{
|
||||
if (!StartingEquipment.Any())
|
||||
{
|
||||
GD.Print("No items to spawn on Player");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var startingItem in StartingEquipment)
|
||||
{
|
||||
switch (startingItem.Item)
|
||||
{
|
||||
case ItemTypes.Weapon:
|
||||
if (WeaponTemplate == null)
|
||||
{
|
||||
GD.Print("Could not spawn weapon because template is null");
|
||||
break;
|
||||
}
|
||||
var weapon = _player.CreateChild<Weapon>(WeaponTemplate);
|
||||
weapon.WeaponData = startingItem.WeaponData;
|
||||
|
||||
_player.EquippedWeapon ??= weapon;
|
||||
break;
|
||||
}
|
||||
|
||||
_inventoryManager.AddItem(startingItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnBulletsContainer()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue