mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-15 03:33:46 +00:00
Moved weapons to their own scene
This commit is contained in:
parent
7ebbc207e6
commit
34e0603170
6 changed files with 159 additions and 62 deletions
|
|
@ -8,34 +8,19 @@ public partial class Enemy : Area2D, IDestructible
|
|||
private InteractionController _cachedPlayer;
|
||||
private EnemyState _currentState = EnemyState.Idle;
|
||||
|
||||
[Export]
|
||||
public PackedScene BulletScene { get; set; }
|
||||
|
||||
[Export] public float Health = 4f;
|
||||
|
||||
[Export] public double RateOfFire = 0.4f;
|
||||
|
||||
[Export] public double ReloadTime = 1.0f;
|
||||
|
||||
[Export] public int BulletCount = 4;
|
||||
|
||||
[Export] public float BulletSpeed = 100f;
|
||||
[Export] public Weapon EquippedWeapon;
|
||||
|
||||
private float _currentHealth = 0f;
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
private Timer _cooldownTimer;
|
||||
|
||||
[DebugGUIPrint]
|
||||
private int _ammo = 0;
|
||||
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_currentHealth = Health;
|
||||
_ammo = BulletCount;
|
||||
_cooldownTimer = GetNode<Timer>("./ShootTimer");
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
|
@ -72,7 +57,7 @@ public partial class Enemy : Area2D, IDestructible
|
|||
return;
|
||||
}
|
||||
|
||||
if (_cooldownTimer.IsStopped() && IsPlayerInSight())
|
||||
if (IsPlayerInSight())
|
||||
{
|
||||
Shoot();
|
||||
}
|
||||
|
|
@ -80,26 +65,32 @@ public partial class Enemy : Area2D, IDestructible
|
|||
|
||||
private void Shoot()
|
||||
{
|
||||
// SHOOT
|
||||
var bullet = this.CreateChild<Bullet>(BulletScene);
|
||||
// var bullet = BulletScene.Instantiate<Bullet>();
|
||||
// Owner.AddChild(bullet);
|
||||
// bullet.Transform = this.GlobalTransform;
|
||||
// bullet.Position = this.Position;
|
||||
bullet.SetDirection((_cachedPlayer.GlobalPosition - this.GlobalPosition).Normalized());
|
||||
bullet.Speed = BulletSpeed;
|
||||
if (EquippedWeapon == null) return;
|
||||
|
||||
_ammo -= 1;
|
||||
|
||||
if (_ammo <= 0)
|
||||
{
|
||||
_ammo = BulletCount;
|
||||
_cooldownTimer.Start(ReloadTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
_cooldownTimer.Start(RateOfFire);
|
||||
}
|
||||
EquippedWeapon.ShootDirection = (_cachedPlayer.GlobalPosition - this.GlobalPosition).Normalized();
|
||||
|
||||
EquippedWeapon.Shoot();
|
||||
|
||||
// // SHOOT
|
||||
// var bullet = this.CreateChild<Bullet>(BulletScene);
|
||||
// // var bullet = BulletScene.Instantiate<Bullet>();
|
||||
// // Owner.AddChild(bullet);
|
||||
// // bullet.Transform = this.GlobalTransform;
|
||||
// // bullet.Position = this.Position;
|
||||
// bullet.SetDirection((_cachedPlayer.GlobalPosition - this.GlobalPosition).Normalized());
|
||||
// bullet.Speed = BulletSpeed;
|
||||
//
|
||||
// _ammo -= 1;
|
||||
//
|
||||
// if (_ammo <= 0)
|
||||
// {
|
||||
// _ammo = BulletCount;
|
||||
// _cooldownTimer.Start(ReloadTime);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _cooldownTimer.Start(RateOfFire);
|
||||
// }
|
||||
}
|
||||
|
||||
private bool IsPlayerInSight()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue