mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 08:45:33 +00:00
Ammo UI system
This commit is contained in:
parent
70c514f1a9
commit
5eb7b578bc
22 changed files with 238 additions and 87 deletions
|
|
@ -3,7 +3,9 @@
|
|||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABullet_005FScriptMethods_002Egenerated_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Fed43dad990dc631ddea2fdab39f95a2741569684_003FBullet_005FScriptMethods_002Egenerated_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACanvasItem_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Fe43c43ee5cdcf2c7c8ddb9366f75a76a3c61c77bf45ceac78721c269f3c360_003FCanvasItem_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACastHelpers_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003F3c92637ae2e83da0a63791071c41eae291d594156062866d8621b7ed7245c_003FCastHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AContainer_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003F8146f3e3f6341957cdf79e3ab90302acaa98c2e4c60a2f098a6fcc8a2c86c7_003FContainer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnemy_005FScriptProperties_002Egenerated_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Fd6739058209280d46591ab296d6b49dfcf7ecd2_003FEnemy_005FScriptProperties_002Egenerated_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Fbb1b701f3c7411227a9d2e09f965d857ff3e771557650c4f513e427d77c_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlayerMovement_005FScriptMethods_002Egenerated_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003F4af4702ac4bbb9ab7299554c41beea2bf703b4a_003FPlayerMovement_005FScriptMethods_002Egenerated_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AScriptManagerBridge_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FDecompilerCache_003Fdecompiler_003F4fd22cd129a84c16b5d8004b467c426f518800_003F3a_003Fc456f450_003FScriptManagerBridge_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVariantUtils_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FDecompilerCache_003Fdecompiler_003F4fd22cd129a84c16b5d8004b467c426f518800_003F38_003Fb04c4423_003FVariantUtils_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||
|
|
@ -1,19 +1,21 @@
|
|||
[gd_resource type="Resource" script_class="LootItem" load_steps=4 format=3 uid="uid://ct1fa2huvy34n"]
|
||||
[gd_resource type="Resource" script_class="LootItem" load_steps=5 format=3 uid="uid://ct1fa2huvy34n"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="1_31o2l"]
|
||||
[ext_resource type="Texture2D" uid="uid://c5g0qg6u2gm6f" path="res://Sprites/Items/Ammo1.png" id="1_bpftr"]
|
||||
[ext_resource type="PackedScene" uid="uid://cjv4yahpb0h2l" path="res://Scenes/HUD/Items/ammo.tscn" id="1_qkp4b"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_3y0hf"]
|
||||
atlas = ExtResource("1_bpftr")
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_31o2l")
|
||||
ItemName = ""
|
||||
ItemKey = ""
|
||||
ItemName = "Ammo 1"
|
||||
ItemKey = "Ammo1"
|
||||
Item = 3
|
||||
Amount = 100
|
||||
Max = 800
|
||||
PickupIfMaxed = false
|
||||
ConsumeOnUse = true
|
||||
UiType = 0
|
||||
UiType = 2
|
||||
InventorySprite = SubResource("AtlasTexture_3y0hf")
|
||||
HudItemScene = ExtResource("1_qkp4b")
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://j1pbuvw2kduo"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dxs3ks2ucaxl4" path="res://Scenes/Items/Red_Keycard.tscn" id="1_v0ux4"]
|
||||
[ext_resource type="Resource" uid="uid://ct1fa2huvy34n" path="res://Resources/Items/Ammo1.tres" id="2_2eoli"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://pmwatoyt2ase" path="res://Resources/Sprites/Ammo_Inventory_Sprite.tres" id="2_8g7mw"]
|
||||
|
||||
[node name="Ammo1" instance=ExtResource("1_v0ux4")]
|
||||
LootTable = [ExtResource("2_2eoli")]
|
||||
|
||||
[node name="AnimatedSprite2D" parent="." index="1"]
|
||||
sprite_frames = ExtResource("2_8g7mw")
|
||||
18
Resources/Items/IceShotgun.tres
Normal file
18
Resources/Items/IceShotgun.tres
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
[gd_resource type="Resource" script_class="LootItem" load_steps=4 format=3 uid="uid://dau0s8ob7qnpc"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bqb3gbnrkqewt" path="res://Scenes/HUD/Items/ice_shotgun_huditem.tscn" id="1_13ven"]
|
||||
[ext_resource type="Resource" uid="uid://cyntngidhcbkc" path="res://Resources/Weapons/Ice_Shotgun_Weapon.tres" id="2_3le6e"]
|
||||
[ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="3_cjfxs"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("3_cjfxs")
|
||||
ItemName = "Ice Shotgun"
|
||||
ItemKey = "IceShotgun"
|
||||
Item = 9
|
||||
WeaponData = ExtResource("2_3le6e")
|
||||
Amount = 1
|
||||
Max = 1
|
||||
PickupIfMaxed = false
|
||||
ConsumeOnUse = false
|
||||
UiType = 1
|
||||
HudItemScene = ExtResource("1_13ven")
|
||||
18
Resources/Items/IcicleGun.tres
Normal file
18
Resources/Items/IcicleGun.tres
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
[gd_resource type="Resource" script_class="LootItem" load_steps=4 format=3 uid="uid://cs3ihltcn2166"]
|
||||
|
||||
[ext_resource type="Resource" uid="uid://b8apu0l5fm4k" path="res://Resources/Weapons/IcicleGun.tres" id="1_itajb"]
|
||||
[ext_resource type="PackedScene" uid="uid://cicthr1v5v4s2" path="res://Scenes/HUD/Items/icicle_gun.tscn" id="1_lfbsh"]
|
||||
[ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="2_hy2hk"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("2_hy2hk")
|
||||
ItemName = "Icicle Gun"
|
||||
ItemKey = "IcicleGun"
|
||||
Item = 9
|
||||
WeaponData = ExtResource("1_itajb")
|
||||
Amount = 1
|
||||
Max = 1
|
||||
PickupIfMaxed = false
|
||||
ConsumeOnUse = false
|
||||
UiType = 1
|
||||
HudItemScene = ExtResource("1_lfbsh")
|
||||
23
Resources/Weapons/Ice_Shotgun_Weapon.tres
Normal file
23
Resources/Weapons/Ice_Shotgun_Weapon.tres
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
[gd_resource type="Resource" script_class="WeaponResource" load_steps=3 format=3 uid="uid://cyntngidhcbkc"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://b1qnfiuokpvsr" path="res://Scenes/Weapons/bullet.tscn" id="1_puh43"]
|
||||
[ext_resource type="Script" path="res://Scripts/Resources/WeaponResource.cs" id="2_utbbo"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("2_utbbo")
|
||||
Name = "Ice Shotgun"
|
||||
BulletScene = ExtResource("1_puh43")
|
||||
RateOfFire = 0.1
|
||||
BulletCapacity = 4
|
||||
ReloadTime = 0.8
|
||||
AutoReload = true
|
||||
InfiniteAmmo = false
|
||||
BulletsPerShot = 3
|
||||
SpreadAngle = 45.0
|
||||
RandomSpread = 0.0
|
||||
AmmoKey = "Ammo1"
|
||||
BulletSpeed = 300.0
|
||||
BulletDamage = 1.0
|
||||
_rotationOffset = 0.0
|
||||
owner = 1
|
||||
_timeModifiers = null
|
||||
|
|
@ -15,9 +15,9 @@ InfiniteAmmo = true
|
|||
BulletsPerShot = 1
|
||||
SpreadAngle = 0.0
|
||||
RandomSpread = 0.0
|
||||
AmmoKey = ""
|
||||
BulletSpeed = 300.0
|
||||
bulletPerShotCount = 1
|
||||
BulletDamage = 1.0
|
||||
_rotationOffset = 0.0
|
||||
spread = 0.0
|
||||
owner = 1
|
||||
_timeModifiers = null
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://dkwi1hu1bixoe"]
|
||||
[gd_scene load_steps=7 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="Texture2D" uid="uid://dde36pgb8fbwc" path="res://Sprites/selector_big.png" id="3_hee3i"]
|
||||
[ext_resource type="PackedScene" uid="uid://cicthr1v5v4s2" path="res://Scenes/HUD/Items/icicle_gun.tscn" id="4_m333p"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_h626b"]
|
||||
atlas = ExtResource("3_hee3i")
|
||||
|
|
@ -81,14 +80,3 @@ text = "100/100"
|
|||
|
||||
[node name="ItemsContainer" type="VBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/ItemsContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="IcicleGun" parent="VBoxContainer/ItemsContainer/HBoxContainer" instance=ExtResource("4_m333p")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/ItemsContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 10
|
||||
text = "100/300"
|
||||
|
|
|
|||
7
Scenes/HUD/Items/ice_shotgun_huditem.tscn
Normal file
7
Scenes/HUD/Items/ice_shotgun_huditem.tscn
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://bqb3gbnrkqewt"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://b46usr10jhmev" path="res://Sprites/Items/Ice_Shotgun.png" id="1_1dd2l"]
|
||||
|
||||
[node name="IceShotgun" type="TextureRect"]
|
||||
texture = ExtResource("1_1dd2l")
|
||||
stretch_mode = 2
|
||||
|
|
@ -21,7 +21,7 @@ public partial class Interactable : Area2D
|
|||
{
|
||||
if (Requirements.Any())
|
||||
{
|
||||
if (_inventoryManager.HasItems(Requirements.Select(x => x.Item).ToList()))
|
||||
if (_inventoryManager.HasItems(Requirements.Select(x => x.ItemKey).ToList()))
|
||||
{
|
||||
GD.Print($"Requirements for activation of {this.Name} successfully met: {string.Join(",", Requirements.Select(x => x.Item))} ");
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://q7hau0tl3vsr"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://q7hau0tl3vsr"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://duwiasewxvcb5" path="res://Sprites/Items/Icicle_Gun.png" id="1_exv8g"]
|
||||
[ext_resource type="Script" path="res://Scripts/Interactables/ItemPickup.cs" id="1_rdvi1"]
|
||||
[ext_resource type="Resource" uid="uid://cs3ihltcn2166" path="res://Resources/Items/IcicleGun.tres" id="2_6qt07"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_jtwy2"]
|
||||
|
||||
[node name="IcicleGun" type="Area2D"]
|
||||
script = ExtResource("1_rdvi1")
|
||||
LootTable = [ExtResource("2_6qt07")]
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_exv8g")
|
||||
|
|
|
|||
|
|
@ -5,5 +5,3 @@
|
|||
|
||||
[node name="EnemyWeapon" instance=ExtResource("1_60orr")]
|
||||
BulletScene = ExtResource("2_dyoou")
|
||||
BulletCapacity = 4
|
||||
BulletSpeed = 50.0
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ radius = 17.2627
|
|||
[sub_resource type="CircleShape2D" id="CircleShape2D_e6woi"]
|
||||
radius = 1.0
|
||||
|
||||
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Muzzle", "EquippedWeapon") groups=["Destroyable", "player"]]
|
||||
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Muzzle") groups=["Destroyable", "player"]]
|
||||
y_sort_enabled = true
|
||||
collision_layer = 2
|
||||
collision_mask = 99
|
||||
|
|
@ -154,7 +154,6 @@ CrosshairDistance = 20.0
|
|||
SelectorScene = ExtResource("3_8wt6s")
|
||||
GameOverScene = "res://Scenes/GameOver.tscn"
|
||||
Muzzle = NodePath("Muzzle")
|
||||
EquippedWeapon = NodePath("Weapon")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
[gd_scene load_steps=40 format=4 uid="uid://bv451a8wgty4u"]
|
||||
[gd_scene load_steps=44 format=4 uid="uid://bv451a8wgty4u"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/GameManager.cs" id="1_8tmoj"]
|
||||
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_8mh54"]
|
||||
[ext_resource type="PackedScene" uid="uid://crry0rgk7a8sm" path="res://Scenes/Weapons/BaseWeapon.tscn" id="3_2wlhc"]
|
||||
[ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="3_kgs2x"]
|
||||
[ext_resource type="Script" path="res://Scripts/TilemapAvoidance.cs" id="4_p1fl3"]
|
||||
[ext_resource type="PackedScene" uid="uid://rp4jhx0tuh24" path="res://Scenes/fragola.tscn" id="4_s7wq6"]
|
||||
[ext_resource type="Resource" uid="uid://ct1fa2huvy34n" path="res://Resources/Items/Ammo1.tres" id="4_swym2"]
|
||||
[ext_resource type="Resource" uid="uid://dau0s8ob7qnpc" path="res://Resources/Items/IceShotgun.tres" id="5_frf65"]
|
||||
[ext_resource type="Resource" uid="uid://cs3ihltcn2166" path="res://Resources/Items/IcicleGun.tres" id="5_nqier"]
|
||||
[ext_resource type="PackedScene" uid="uid://uaf5r6cd71hu" path="res://Scenes/Props/LargeTank.tscn" id="6_nkauc"]
|
||||
[ext_resource type="Script" path="res://Scenes/CameraController.gd" id="6_t8ide"]
|
||||
[ext_resource type="PackedScene" uid="uid://crmwuwhltmdq7" path="res://Scenes/Props/MediumTank.tscn" id="7_lmrl1"]
|
||||
|
|
@ -47,6 +51,8 @@ position = Vector2(38, 39)
|
|||
script = ExtResource("1_8tmoj")
|
||||
PlayerTemplate = ExtResource("2_8mh54")
|
||||
PlayerSpawnMarker = NodePath("PlayerStartPosition")
|
||||
WeaponTemplate = ExtResource("3_2wlhc")
|
||||
StartingEquipment = Array[Object]([ExtResource("4_swym2"), ExtResource("5_frf65"), ExtResource("5_nqier")])
|
||||
|
||||
[node name="Factory Tilemaps" type="Node2D" parent="."]
|
||||
|
||||
|
|
@ -333,3 +339,12 @@ _trackName = "computer2"
|
|||
|
||||
[node name="Ammo1" parent="." instance=ExtResource("34_17pjh")]
|
||||
position = Vector2(-792, -378)
|
||||
|
||||
[node name="Ammo2" parent="." instance=ExtResource("34_17pjh")]
|
||||
position = Vector2(-808, -378)
|
||||
|
||||
[node name="Ammo3" parent="." instance=ExtResource("34_17pjh")]
|
||||
position = Vector2(-808, -400)
|
||||
|
||||
[node name="Ammo4" parent="." instance=ExtResource("34_17pjh")]
|
||||
position = Vector2(-791, -401)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using Godot;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts;
|
||||
using Cirno.Scripts.Resources;
|
||||
|
||||
public partial class Hud : CanvasLayer
|
||||
|
|
@ -82,12 +83,33 @@ public partial class Hud : CanvasLayer
|
|||
{
|
||||
Item = item,
|
||||
Container = hbox,
|
||||
//Amount = currentAmount
|
||||
};
|
||||
|
||||
if (item.UiType == UiItemType.IconText)
|
||||
{
|
||||
var label = new Label();
|
||||
label.Text = currentAmount.ToString();
|
||||
// if (item.Item == ItemTypes.Weapon && item.WeaponData != null)
|
||||
// {
|
||||
// // Show ammo instead of item count
|
||||
// var ammoItem = _items.GetValueOrDefault(item.WeaponData.AmmoKey);
|
||||
//
|
||||
// if (ammoItem != null)
|
||||
// {
|
||||
// label.Text = "0";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// label.Text = ammoItem.
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// label.Text = currentAmount.ToString();
|
||||
// }
|
||||
|
||||
label.LabelSettings = new LabelSettings()
|
||||
{
|
||||
FontSize = 8
|
||||
|
|
@ -116,24 +138,26 @@ public partial class Hud : CanvasLayer
|
|||
// _itemsContainer.AddChild(texture);
|
||||
}
|
||||
|
||||
public void RemoveInventoryItem(LootItem item, int currentAmount)
|
||||
public void RemoveInventoryItem(string itemKey, int currentAmount)
|
||||
{
|
||||
|
||||
if (_items.TryGetValue(item.ItemKey, out var itm))
|
||||
if (_items.TryGetValue(itemKey, out var itm))
|
||||
{
|
||||
if (currentAmount <= 0)
|
||||
{
|
||||
itm.Container.QueueFree();
|
||||
_items.Remove(item.ItemKey);
|
||||
_items.Remove(itemKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
itm.Label.Text = currentAmount.ToString();
|
||||
if (itm.Item.UiType == UiItemType.IconText)
|
||||
{
|
||||
itm.Label.Text = currentAmount.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print($"Tried to remove item {item.ItemName} {item.ItemKey} but it was not found");
|
||||
GD.Print($"Tried to remove item {itemKey} but it was not found");
|
||||
}
|
||||
|
||||
// var containerItem = _items.FirstOrDefault(x => x.Item == item);
|
||||
|
|
@ -152,5 +176,7 @@ public partial class Hud : CanvasLayer
|
|||
public LootItem Item { get; set; }
|
||||
public HBoxContainer Container { get; set; }
|
||||
public Label Label { get; set; }
|
||||
|
||||
//public int Amount { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ public partial class InventoryManager : Node2D
|
|||
{
|
||||
public bool RedKeycard { get; set; }
|
||||
|
||||
private List<LootItem> _items = new List<LootItem>();
|
||||
|
||||
private Dictionary<string, ItemContainer> _itemsDict = new Dictionary<string, ItemContainer>();
|
||||
|
||||
public Dictionary<string, ItemContainer> Items => _itemsDict;
|
||||
|
|
@ -19,7 +17,7 @@ public partial class InventoryManager : Node2D
|
|||
public delegate void ItemAddedEventHandler(LootItem item, int currentAmount);
|
||||
|
||||
[Signal]
|
||||
public delegate void ItemRemovedEventHandler(LootItem item, int currentAmount);
|
||||
public delegate void ItemRemovedEventHandler(string itemKey, int currentAmount);
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
|
|
@ -30,38 +28,34 @@ public partial class InventoryManager : Node2D
|
|||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public bool HasItems(List<ItemTypes> items)
|
||||
|
||||
public bool HasItems(List<string> itemKeys)
|
||||
{
|
||||
return items.Aggregate(false, (current, item) => current || HasItem(item));
|
||||
return itemKeys.Aggregate(false, (current, item) => current || GetItemCount(item) > 0);
|
||||
}
|
||||
|
||||
public bool HasItem(ItemTypes type)
|
||||
public int GetItemCount(string itemKey)
|
||||
{
|
||||
return _items.Any(x => x.Item == type && x.Amount > 0);
|
||||
return _itemsDict.TryGetValue(itemKey, out var itm) ? itm.Count : 0;
|
||||
}
|
||||
|
||||
public int RemoveItem(LootItem item, int amount)
|
||||
public int RemoveItem(string itemKey, int amount)
|
||||
{
|
||||
if (_itemsDict.ContainsKey(item.ItemKey))
|
||||
if (!_itemsDict.TryGetValue(itemKey, out var itm)) return 0;
|
||||
|
||||
int removed = Math.Min(itm.Count, amount);
|
||||
|
||||
itm.Count -= amount;
|
||||
|
||||
if (itm.Count <= 0)
|
||||
{
|
||||
var itm = _itemsDict[item.ItemKey];
|
||||
|
||||
int removed = 0;
|
||||
|
||||
itm.Count -= amount;
|
||||
|
||||
if (itm.Count <= 0)
|
||||
{
|
||||
_itemsDict.Remove(item.ItemKey);
|
||||
}
|
||||
|
||||
EmitSignal(nameof(ItemRemoved), item, item.Amount);
|
||||
|
||||
return itm.Count;
|
||||
_itemsDict.Remove(itemKey);
|
||||
}
|
||||
|
||||
EmitSignal(nameof(ItemRemoved), itemKey, itm.Count);
|
||||
|
||||
return removed;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public bool AddItem(LootItem item)
|
||||
|
|
@ -81,7 +75,7 @@ public partial class InventoryManager : Node2D
|
|||
}
|
||||
else
|
||||
{
|
||||
if (itm.Count < item.Amount)
|
||||
if (itm.Count < item.Max)
|
||||
{
|
||||
itm.Count += item.Amount;
|
||||
}
|
||||
|
|
@ -96,7 +90,7 @@ public partial class InventoryManager : Node2D
|
|||
return false;
|
||||
}
|
||||
}
|
||||
EmitSignal(nameof(ItemAdded), item, itm.Count, item.Amount);
|
||||
EmitSignal(nameof(ItemAdded), item, itm.Count);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ public enum ItemTypes
|
|||
KeycardGreen,
|
||||
Ammo,
|
||||
Medkit,
|
||||
CrabBomb,
|
||||
FrogBomb,
|
||||
Bomb,
|
||||
Mine,
|
||||
Battery
|
||||
Battery,
|
||||
Weapon
|
||||
}
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||
{
|
||||
|
|
@ -41,13 +44,15 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
[Export] public float MaxHealth = 32f;
|
||||
|
||||
[Export] public Weapon EquippedWeapon;
|
||||
public Weapon EquippedWeapon { get; set; }
|
||||
|
||||
private float _currentHealth = 0f;
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
private InventoryManager _inventoryManager;
|
||||
|
||||
[Export] public Sprite2D HitboxSprite { get; set; }
|
||||
|
||||
|
|
@ -94,6 +99,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
_gameManager = this.GetGameManager(); //GetNode<GameManager>("/root/GameScene");
|
||||
|
||||
_inventoryManager = this.GetInventoryManager();
|
||||
|
||||
_gameManager.GameStateChange += GameManagerOnGameStateChange;
|
||||
|
||||
if (SelectorScene != null)
|
||||
|
|
@ -102,7 +109,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
_selector.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void GameManagerOnGameStateChange(GameState state)
|
||||
{
|
||||
switch (state)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ public partial class LootItem : Resource
|
|||
[Export] public string ItemName { get; set; }
|
||||
[Export] public string ItemKey { get; set; }
|
||||
[Export] public ItemTypes Item;
|
||||
[Export] public WeaponResource WeaponData { get; set; }
|
||||
[Export] public int Amount;
|
||||
[Export] public int Max;
|
||||
[Export] public bool PickupIfMaxed;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ public partial class WeaponResource : Resource
|
|||
|
||||
#region Bullet spawn data
|
||||
|
||||
[Export] public string AmmoKey;
|
||||
[Export] public float BulletSpeed = 100f;
|
||||
[Export] public float BulletDamage = 1;
|
||||
[Export] private float _rotationOffset = 0f;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ public partial class Weapon : Node2D
|
|||
private Node2D _bulletsContainer;
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
private InventoryManager _inventoryManager;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
|
|
@ -37,21 +39,31 @@ public partial class Weapon : Node2D
|
|||
_muzzle = GetNode<Marker2D>("./Muzzle");
|
||||
_cooldownTimer = GetNode<Timer>("./ShootTimer");
|
||||
|
||||
_gameManager = GetNode<GameManager>("/root/GameScene");
|
||||
_gameManager = this.GetGameManager();
|
||||
_inventoryManager = this.GetInventoryManager();
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
_cooldownTimer.Start(WeaponData.ReloadTime);
|
||||
|
||||
if (WeaponData.InfiniteAmmo)
|
||||
if (WeaponData.InfiniteAmmo || string.IsNullOrWhiteSpace(WeaponData.AmmoKey))
|
||||
{
|
||||
LoadedAmmo = WeaponData.BulletCapacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Calculate subtraction, etc
|
||||
LoadedAmmo = WeaponData.BulletCapacity;
|
||||
// if (_inventoryManager.GetItemCount(WeaponData.AmmoKey) <= 0) return;
|
||||
var ammoToLoad = _inventoryManager.RemoveItem(WeaponData.AmmoKey, WeaponData.BulletCapacity);
|
||||
|
||||
if (ammoToLoad > 0)
|
||||
{
|
||||
LoadedAmmo = ammoToLoad;
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print("Out of ammo");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue