mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 12:15:53 +00:00
Basic weapon direction
This commit is contained in:
parent
9362f66fdf
commit
0146de8ab5
4 changed files with 92 additions and 6 deletions
|
|
@ -14,6 +14,10 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
[Export] public PackedScene WeaponTemplate { get; private set; }
|
||||
|
||||
[Export] public double WeaponSwitchCooldown { get; private set; } = 0.5d;
|
||||
|
||||
[Export] public Marker2D WeaponRightOffset { get; private set; } // local offset when facing right
|
||||
[Export] public Marker2D WeaponLeftOffset { get; private set; } // local offset when facing left
|
||||
|
||||
public Array<Weapon> EquippedWeapons { get; set; } = [];
|
||||
|
||||
private int _currentWeaponIndex = 0;
|
||||
|
|
@ -64,6 +68,8 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
|
||||
public void Update(double delta)
|
||||
{
|
||||
RotateWeapon();
|
||||
|
||||
if (!_switching) return;
|
||||
_switchCooldown += delta;
|
||||
if (_switchCooldown >= WeaponSwitchCooldown)
|
||||
|
|
@ -72,6 +78,24 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
_switchCooldown = 0d;
|
||||
}
|
||||
}
|
||||
|
||||
private void RotateWeapon()
|
||||
{
|
||||
if (EquippedWeapon is null) return;
|
||||
|
||||
EquippedWeapon.RotateWeapon(StorageModule.FacingDirection, WeaponLeftOffset.Position, WeaponRightOffset.Position);
|
||||
|
||||
|
||||
|
||||
// EquippedWeapon.SetRotation(angle + Mathf.Pi / 2.0f);
|
||||
//
|
||||
//
|
||||
//
|
||||
// EquippedWeapon.FlipH = facingLeft;
|
||||
//
|
||||
// // 3. Position on correct side (assuming EquippedWeapon is a child of the Player node)
|
||||
// EquippedWeapon.Position = facingLeft ? WeaponLeftOffset : WeaponRightOffset;
|
||||
}
|
||||
|
||||
private void OnInventoryWeaponEquipped(string itemKey)
|
||||
{
|
||||
|
|
@ -192,7 +216,7 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
var weapon = this.CreateSibling<Weapon>(WeaponTemplate);
|
||||
weapon.WeaponData = startingItem.WeaponData;
|
||||
|
||||
weapon.Texture = startingItem.InventorySprite;
|
||||
weapon.Sprite.Texture = startingItem.InventorySprite;
|
||||
|
||||
this.AddWeapon(weapon);
|
||||
return weapon;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue