Moved weapons to their own scene

This commit is contained in:
Marco 2024-11-15 16:32:26 +01:00
commit 34e0603170
6 changed files with 159 additions and 62 deletions

View file

@ -11,9 +11,6 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
[Export]
public float CrosshairDistance { get; set; } = 10f;
[Export]
public PackedScene BulletScene { get; set; }
[Export]
public PackedScene SelectorScene { get; set; }
@ -35,17 +32,13 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
private Sprite2D _crosshair;
private Timer _cooldownTimer;
[Export] public float Health = 4f;
[Export] public Weapon EquippedWeapon;
[DebugGUIPrint]
private float _currentHealth = 0f;
[Export] public double RateOfFire = 0.4f;
[Export] public float BulletSpeed = 300f;
private bool _isDestroyed = false;
public override void _Ready()
@ -54,7 +47,6 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
_animatedSprite = GetNode<AnimatedSprite2D>("./Smoothing2D/AnimatedSprite2D");
_crosshair = GetNode<Sprite2D>("./Smoothing2D/Crosshair");
_cooldownTimer = GetNode<Timer>("./ShootTimer");
_movementDirection = Vector2.Zero;
_facingDirection = Vector2.Zero;
@ -100,13 +92,18 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
private void HandleShoot()
{
if (!Input.IsActionJustPressed("shoot")) return;
//Debug.WriteLine("Shoot");
var bullet = BulletScene.Instantiate<Bullet>();
Owner.AddChild(bullet);
bullet.Transform = Muzzle.GlobalTransform;
bullet.Position = this.Position;
bullet.SetDirection(this._facingDirection);
if (EquippedWeapon == null) return;
if (!Input.IsActionPressed("shoot")) return;
EquippedWeapon.ShootDirection = this._facingDirection;
EquippedWeapon.Shoot();
// //Debug.WriteLine("Shoot");
// var bullet = BulletScene.Instantiate<Bullet>();
// Owner.AddChild(bullet);
// bullet.Transform = Muzzle.GlobalTransform;
// bullet.Position = this.Position;
// bullet.SetDirection(this._facingDirection);
}
private void SetAnimation()