Item pickup

This commit is contained in:
2025-08-29 12:33:10 +08:00
parent 850628ca72
commit fac5e5a597
12 changed files with 191 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
using System;
using AceFieldNewHorizon.Scripts.System;
using Godot;
namespace AceFieldNewHorizon.Scripts.Entities;
@@ -18,6 +19,8 @@ public partial class Player : CharacterBody2D
[Export] public float ZoomAcceleration = 0.05f;
[Export] public float ZoomDecay = 0.9f;
[Export] public float ZoomSmoothing = 10.0f;
[Export] public ResourceManager Inventory;
private Camera2D _camera;
private Vector2 _cameraTargetZoom = Vector2.One;
@@ -29,6 +32,8 @@ public partial class Player : CharacterBody2D
{
_camera = GetNode<Camera2D>("Camera2D");
_cameraTargetZoom = _camera.Zoom;
AddToGroup(ItemPickup.PickupGroupName);
}
public override void _Input(InputEvent @event)
@@ -135,4 +140,10 @@ public partial class Player : CharacterBody2D
// Apply the movement
MoveAndSlide();
}
public void AddItem(string itemId, int quantity)
{
Inventory.AddResource(itemId, quantity);
GD.Print($"[Player] Picked up {quantity} x {itemId}. Total: {Inventory.GetResourceAmount(itemId)}");
}
}