mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-07 17:55:53 +00:00
Collisions and cooldowns
This commit is contained in:
parent
0eb6a9140f
commit
6ff1ab76ed
9 changed files with 105 additions and 3848 deletions
|
|
@ -70,7 +70,12 @@ public partial class Bullet : Area2D
|
|||
|
||||
private void _on_area_entered(Area2D area)
|
||||
{
|
||||
// Replace with function body.
|
||||
if (area.IsInGroup("Solid"))
|
||||
{
|
||||
QueueFree();
|
||||
return;
|
||||
}
|
||||
|
||||
if (area.IsInGroup("Destroyable") && area is IDestructible destructible)
|
||||
{
|
||||
//Debug.WriteLine("Collision with destroyable object area");
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using Godot;
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
public partial class Enemy : Area2D
|
||||
public partial class Enemy : Area2D, IDestructible
|
||||
{
|
||||
private InteractionController _cachedPlayer;
|
||||
private EnemyState _currentState = EnemyState.Idle;
|
||||
|
|
@ -11,10 +11,21 @@ public partial class Enemy : Area2D
|
|||
[Export]
|
||||
public PackedScene BulletScene { get; set; }
|
||||
|
||||
[Export] public float Health = 4f;
|
||||
|
||||
[Export] public double RateOfFire = 0.4f;
|
||||
|
||||
private float _currentHealth = 0f;
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
private Timer _cooldownTimer;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
_currentHealth = Health;
|
||||
_cooldownTimer = GetNode<Timer>("./ShootTimer");
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
|
@ -51,7 +62,7 @@ public partial class Enemy : Area2D
|
|||
return;
|
||||
}
|
||||
|
||||
if (IsPlayerInSight())
|
||||
if (_cooldownTimer.IsStopped() && IsPlayerInSight())
|
||||
{
|
||||
// SHOOT
|
||||
var bullet = this.CreateChild<Bullet>(BulletScene);
|
||||
|
|
@ -60,6 +71,7 @@ public partial class Enemy : Area2D
|
|||
// bullet.Transform = this.GlobalTransform;
|
||||
// bullet.Position = this.Position;
|
||||
bullet.SetDirection((_cachedPlayer.GlobalPosition - this.GlobalPosition).Normalized());
|
||||
_cooldownTimer.Start(RateOfFire);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,6 +111,35 @@ public partial class Enemy : Area2D
|
|||
}
|
||||
}
|
||||
|
||||
// Bullets collision
|
||||
private void _on_area_entered(Area2D area)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Hit(float damage)
|
||||
{
|
||||
if (_isDestroyed) return;
|
||||
|
||||
_currentHealth -= damage;
|
||||
if (!(_currentHealth <= 0)) return;
|
||||
_isDestroyed = true;
|
||||
Explode();
|
||||
}
|
||||
|
||||
private void Explode()
|
||||
{
|
||||
Debug.WriteLine("Ded");
|
||||
//CreateParticles();
|
||||
//CreateDebris();
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
public bool IsDestroyed()
|
||||
{
|
||||
return _isDestroyed;
|
||||
}
|
||||
|
||||
private enum EnemyState
|
||||
{
|
||||
Idle,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue