mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Use bullet flags instead of bools
This commit is contained in:
parent
fa3805ecfe
commit
72c6270eb5
14 changed files with 49 additions and 38 deletions
|
|
@ -34,13 +34,14 @@ public partial class Bullet : Area2D
|
|||
public bool IsFrozen { get; private set; } = false;
|
||||
public bool Enabled { get; private set; } = false;
|
||||
|
||||
[Signal] public delegate void OnDestroyEventHandler();
|
||||
[Signal]
|
||||
public delegate void OnDestroyEventHandler();
|
||||
|
||||
private AudioStreamPlayer2D _grazeSound;
|
||||
private GpuParticles2D _grazeParticles;
|
||||
|
||||
|
||||
private CollisionShape2D _collisionShape2D;
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_grazeSound = GetNodeOrNull<AudioStreamPlayer2D>("AudioStreamPlayer2D");
|
||||
|
|
@ -48,7 +49,7 @@ public partial class Bullet : Area2D
|
|||
|
||||
_collisionShape2D = GetNode<CollisionShape2D>("CollisionShape2D");
|
||||
}
|
||||
|
||||
|
||||
public void Initialize(BulletInfo bulletInfo, GameManager gameManager)
|
||||
{
|
||||
_bulletInfo = bulletInfo;
|
||||
|
|
@ -58,7 +59,7 @@ public partial class Bullet : Area2D
|
|||
_elapsedTime = 0f;
|
||||
|
||||
this.Speed = bulletInfo.Speed;
|
||||
|
||||
|
||||
// Need to clone them here
|
||||
// _modifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone()).ToList();
|
||||
|
||||
|
|
@ -81,9 +82,8 @@ public partial class Bullet : Area2D
|
|||
{
|
||||
_collisionShape2D = GetNode<CollisionShape2D>("CollisionShape2D");
|
||||
}
|
||||
|
||||
|
||||
_collisionShape2D.SetDeferred(CollisionShape2D.PropertyName.Disabled, false);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -92,18 +92,19 @@ public partial class Bullet : Area2D
|
|||
public void Disable(bool hideSprite = true)
|
||||
{
|
||||
Enabled = false;
|
||||
if (hideSprite)
|
||||
if (hideSprite && !BulletInfo.Attributes.HasFlag(BulletFlags.PersistSprite))
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
if (this._collisionShape2D is null)
|
||||
{
|
||||
_collisionShape2D = GetNode<CollisionShape2D>("CollisionShape2D");
|
||||
}
|
||||
|
||||
|
||||
_collisionShape2D.SetDeferred(CollisionShape2D.PropertyName.Disabled, true);
|
||||
}
|
||||
|
||||
|
||||
public void Graze()
|
||||
{
|
||||
if (!Enabled) return;
|
||||
|
|
@ -112,6 +113,7 @@ public partial class Bullet : Area2D
|
|||
{
|
||||
_grazeParticles.Emitting = true;
|
||||
}
|
||||
|
||||
IsGrazed = true;
|
||||
}
|
||||
|
||||
|
|
@ -162,19 +164,20 @@ public partial class Bullet : Area2D
|
|||
//SetRotationDegrees(RotationDegrees + degrees);
|
||||
float radians = Mathf.DegToRad(degrees);
|
||||
_direction = _direction.Rotated(radians).Normalized(); // Rotate direction
|
||||
if (!BulletInfo.RotateSprite) return;
|
||||
|
||||
if (!BulletInfo.Attributes.HasFlag(BulletFlags.Rotateable)) return;
|
||||
SetRotation(Rotation + radians);
|
||||
}
|
||||
|
||||
public virtual void RotateSpriteDegrees(float degrees)
|
||||
{
|
||||
if (!BulletInfo.RotateSprite) return;
|
||||
if (!BulletInfo.Attributes.HasFlag(BulletFlags.Rotateable)) return;
|
||||
SetRotationDegrees(RotationDegrees + degrees);
|
||||
}
|
||||
|
||||
public virtual void RotateSprite(float radians)
|
||||
{
|
||||
if (!BulletInfo.RotateSprite) return;
|
||||
if (!BulletInfo.Attributes.HasFlag(BulletFlags.Rotateable)) return;
|
||||
SetRotation(Rotation + radians);
|
||||
}
|
||||
|
||||
|
|
@ -204,7 +207,7 @@ public partial class Bullet : Area2D
|
|||
|
||||
_direction = normalized;
|
||||
|
||||
if (!BulletInfo.RotateSprite) return;
|
||||
if (!BulletInfo.Attributes.HasFlag(BulletFlags.Rotateable)) return;
|
||||
SetRotation(Mathf.Atan2(normalized.Y, normalized.X) + Mathf.Pi / 2);
|
||||
|
||||
//Debug.WriteLine($"Bullet Shot at direction {direction.X} {direction.Y}");
|
||||
|
|
@ -229,8 +232,8 @@ public partial class Bullet : Area2D
|
|||
{
|
||||
ApplyTimeModifiers(delta);
|
||||
}
|
||||
|
||||
if (BulletInfo.Controllabe)
|
||||
|
||||
if (BulletInfo.Attributes.HasFlag(BulletFlags.Controllable))
|
||||
{
|
||||
ControlBullet(delta);
|
||||
}
|
||||
|
|
@ -253,6 +256,7 @@ public partial class Bullet : Area2D
|
|||
private void _on_visible_on_screen_notifier_2d_screen_exited()
|
||||
{
|
||||
if (!Enabled) return;
|
||||
if (!BulletInfo.Attributes.HasFlag(BulletFlags.DieOutOfScreen)) return;
|
||||
//Debug.WriteLine("Destroy bullet out of screen");
|
||||
Destroy();
|
||||
}
|
||||
|
|
@ -319,6 +323,7 @@ public partial class Bullet : Area2D
|
|||
|
||||
//particle.Init();
|
||||
}
|
||||
|
||||
EmitSignal(SignalName.OnDestroy);
|
||||
//QueueFree();
|
||||
PoolingManager.Instance.DisableBullet(this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue