mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 12:35:53 +00:00
Redesigned bullet emitters
This commit is contained in:
parent
ed87163b2f
commit
7b24e47739
16 changed files with 306 additions and 28 deletions
|
|
@ -14,33 +14,74 @@ public partial class BulletEmitter : Node2D, IActivable
|
|||
public bool EmitOnStart { get; set; } = false;
|
||||
|
||||
[Export]
|
||||
public float EmitCoolDown { get; private set; } = 1f;
|
||||
public bool InvertSignal { get; private set; } = false;
|
||||
|
||||
[Export]
|
||||
public float EmitCoolDown { get; private set; } = 0.2f;
|
||||
|
||||
[Export] public float BurstCoolDown { get; private set; } = 2f;
|
||||
|
||||
[Export] public float Spread { get; set; } = 0f;
|
||||
|
||||
[Export] public int Count { get; set; } = 1;
|
||||
|
||||
[Export] public float EmissionRotation { get; set; } = 0f;
|
||||
|
||||
|
||||
[Export] public float RotationSpeed { get; private set; } = 0f;
|
||||
|
||||
[Export] public int BulletsPerBurst { get; private set; } = 1;
|
||||
|
||||
|
||||
[Signal]
|
||||
public delegate void StateChangedEventHandler(bool isEmitting);
|
||||
|
||||
private BulletSpawner _bulletSpawner;
|
||||
|
||||
protected bool IsEmitting = false;
|
||||
|
||||
private double _emitTimer = 0f;
|
||||
|
||||
private double _reloadTimer = 0f;
|
||||
|
||||
private float _currentEmissionRotation = 0f;
|
||||
|
||||
private int _currentBullets = 0;
|
||||
|
||||
private bool _isReloading = false;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_bulletSpawner = GetNode<BulletSpawner>("BulletSpawner");
|
||||
|
||||
_currentEmissionRotation = EmissionRotation;
|
||||
_currentBullets = BulletsPerBurst;
|
||||
|
||||
if (EmitOnStart)
|
||||
{
|
||||
IsEmitting = true;
|
||||
CallDeferred(MethodName.Shoot);
|
||||
}
|
||||
EmitSignal(SignalName.StateChanged, IsEmitting);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!IsEmitting) return;
|
||||
|
||||
if (_isReloading)
|
||||
{
|
||||
_reloadTimer += delta;
|
||||
|
||||
if (_reloadTimer >= BurstCoolDown)
|
||||
{
|
||||
_currentBullets = BulletsPerBurst;
|
||||
_isReloading = false;
|
||||
_reloadTimer = 0f;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_emitTimer += delta;
|
||||
|
||||
if (_emitTimer >= EmitCoolDown)
|
||||
|
|
@ -52,7 +93,16 @@ public partial class BulletEmitter : Node2D, IActivable
|
|||
|
||||
public void Shoot()
|
||||
{
|
||||
_bulletSpawner.SpawnBullet(BulletResource.MakeBullet(this.GlobalPosition, Count, Spread, EmissionRotation));
|
||||
_bulletSpawner.SpawnBullet(BulletResource.MakeBullet(this.GlobalPosition, Count, Spread, _currentEmissionRotation));
|
||||
|
||||
_currentEmissionRotation += RotationSpeed;
|
||||
|
||||
_currentBullets--;
|
||||
|
||||
if (_currentBullets <= 0)
|
||||
{
|
||||
_isReloading = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
|
|
@ -61,12 +111,12 @@ public partial class BulletEmitter : Node2D, IActivable
|
|||
{
|
||||
case ActivationType.Open:
|
||||
case ActivationType.Enable:
|
||||
IsEmitting = true;
|
||||
IsEmitting = !InvertSignal;
|
||||
_emitTimer = 0;
|
||||
break;
|
||||
case ActivationType.Close:
|
||||
case ActivationType.Disable:
|
||||
IsEmitting = false;
|
||||
IsEmitting = InvertSignal;
|
||||
_emitTimer = 0;
|
||||
break;
|
||||
case ActivationType.Use:
|
||||
|
|
@ -77,7 +127,8 @@ public partial class BulletEmitter : Node2D, IActivable
|
|||
case ActivationType.Destroy:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
EmitSignal(SignalName.StateChanged, IsEmitting);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
17
Scripts/Components/Actors/EmitterActivationStateSprite.cs
Normal file
17
Scripts/Components/Actors/EmitterActivationStateSprite.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class EmitterActivationStateSprite : Sprite2D
|
||||
{
|
||||
public void ChangeState(bool enabled)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
this.Frame = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Frame = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://701a3no2cu45
|
||||
|
|
@ -19,15 +19,23 @@ public partial class GenericDamageReceiver : Area2D, IHittable
|
|||
|
||||
private Node2D _parent;
|
||||
|
||||
public bool Enabled { get; private set; } = true;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_parent = GetParent<Node2D>();
|
||||
HealthProvider.FillResource();
|
||||
HealthProvider.ResourceDepleted += OnDeath;
|
||||
}
|
||||
|
||||
public void ChangeState(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
|
||||
private void _on_damage_hitbox_area_entered(Area2D area)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
if (Invulnerable) return;
|
||||
if (area is not Bullet bullet) return;
|
||||
|
||||
|
|
@ -46,6 +54,7 @@ public partial class GenericDamageReceiver : Area2D, IHittable
|
|||
|
||||
public void Hit(float damage, DamageType damageType = DamageType.Neutral)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
if (Invulnerable) return;
|
||||
|
||||
var dmg = DamageResistances.Aggregate(damage, (current, resistance) => current * resistance.CalculateDamage(current, damageType));
|
||||
|
|
|
|||
|
|
@ -16,6 +16,21 @@ public partial class StateSwitch : Switch
|
|||
base._Ready();
|
||||
|
||||
CurrentState = StartingState;
|
||||
|
||||
switch (CurrentState)
|
||||
{
|
||||
case SwitchState.On:
|
||||
TriggerEnable();
|
||||
break;
|
||||
case SwitchState.Off:
|
||||
TriggerDisable();
|
||||
break;
|
||||
case SwitchState.Destroyed:
|
||||
break;
|
||||
case SwitchState.Disabled:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue