mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:55:35 +00:00
Added ammo reload to enemy
This commit is contained in:
parent
4f731b221b
commit
ed502eb061
1 changed files with 25 additions and 2 deletions
|
|
@ -15,6 +15,10 @@ public partial class Enemy : Area2D, IDestructible
|
|||
|
||||
[Export] public double RateOfFire = 0.4f;
|
||||
|
||||
[Export] public double ReloadTime = 1.0f;
|
||||
|
||||
[Export] public int BulletCount = 4;
|
||||
|
||||
[Export] public float BulletSpeed = 100f;
|
||||
|
||||
private float _currentHealth = 0f;
|
||||
|
|
@ -23,10 +27,13 @@ public partial class Enemy : Area2D, IDestructible
|
|||
|
||||
private Timer _cooldownTimer;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
|
@ -66,6 +73,12 @@ public partial class Enemy : Area2D, IDestructible
|
|||
|
||||
if (_cooldownTimer.IsStopped() && IsPlayerInSight())
|
||||
{
|
||||
Shoot();
|
||||
}
|
||||
}
|
||||
|
||||
private void Shoot()
|
||||
{
|
||||
// SHOOT
|
||||
var bullet = this.CreateChild<Bullet>(BulletScene);
|
||||
// var bullet = BulletScene.Instantiate<Bullet>();
|
||||
|
|
@ -74,8 +87,18 @@ public partial class Enemy : Area2D, IDestructible
|
|||
// bullet.Position = this.Position;
|
||||
bullet.SetDirection((_cachedPlayer.GlobalPosition - this.GlobalPosition).Normalized());
|
||||
bullet.Speed = BulletSpeed;
|
||||
_cooldownTimer.Start(RateOfFire);
|
||||
}
|
||||
|
||||
_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