mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-10 13:15:53 +00:00
Hitbox visible
This commit is contained in:
parent
88fb08a451
commit
0ccc272ada
10 changed files with 141 additions and 17 deletions
|
|
@ -23,6 +23,11 @@ public partial class Weapon : Node2D
|
|||
[Export] public bool AutoReload = true;
|
||||
|
||||
[Export] public bool InfiniteAmmo = true;
|
||||
|
||||
[Export] public int BulletsPerShot = 1;
|
||||
|
||||
[Export] public float BulletsSpreadAngle = 0f;
|
||||
|
||||
public int Ammo { get; set; } = 0;
|
||||
|
||||
public int LoadedAmmo { get; private set; }
|
||||
|
|
@ -80,23 +85,32 @@ public partial class Weapon : Node2D
|
|||
}
|
||||
|
||||
// TODO: Shoot at muzzle position, need to provide a way to turn it, on a radius?
|
||||
// TODO: Create not as child but as standalone
|
||||
|
||||
// if (BulletScene == null) return;
|
||||
//
|
||||
// var newInstance = BulletScene.Instantiate<Bullet>();
|
||||
// _gameManager.BulletsContainer.CallDeferred("add_child", newInstance);
|
||||
|
||||
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, BulletScene, _muzzle.GlobalPosition);
|
||||
|
||||
if (bullet == null)
|
||||
{
|
||||
GD.PrintErr("Bullet is null, not shooting");
|
||||
return;
|
||||
};
|
||||
float halfSpread = BulletsSpreadAngle / 2f;
|
||||
float spreadStep = BulletsPerShot > 1 ? BulletsSpreadAngle / (BulletsPerShot - 1) : 0;
|
||||
|
||||
|
||||
bullet.SetDirection(ShootDirection);
|
||||
bullet.Speed = BulletSpeed;
|
||||
for (int i = 0; i < BulletsPerShot; i++)
|
||||
{
|
||||
// Calculate angle offset for this bullet
|
||||
float spreadOffset = -halfSpread + (spreadStep * i);
|
||||
|
||||
// Rotate the ShootDirection by the spread angle
|
||||
Vector2 spreadDirection = ShootDirection.Rotated(Mathf.DegToRad(spreadOffset));
|
||||
|
||||
|
||||
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, BulletScene, _muzzle.GlobalPosition);
|
||||
|
||||
if (bullet == null)
|
||||
{
|
||||
GD.PrintErr("Bullet is null, not shooting");
|
||||
return;
|
||||
};
|
||||
|
||||
//bullet.SetDirection(ShootDirection);
|
||||
bullet.SetDirection(spreadDirection);
|
||||
bullet.Speed = BulletSpeed;
|
||||
}
|
||||
|
||||
LoadedAmmo -= 1;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue