mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 11:55:54 +00:00
Bullet emitter
This commit is contained in:
parent
2e8bb70348
commit
e9a9653c20
6 changed files with 84 additions and 11 deletions
50
Scripts/Activables/BulletEmitter.cs
Normal file
50
Scripts/Activables/BulletEmitter.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using Cirno.Scripts.Components;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Activables;
|
||||
|
||||
public partial class BulletEmitter : Node2D, IActivable
|
||||
{
|
||||
|
||||
[Export]
|
||||
public BulletResource BulletResource { get; set; }
|
||||
|
||||
[Export]
|
||||
private bool _isEmitting { get; set; } = false;
|
||||
|
||||
[Export] public float Spread { get; set; } = 0f;
|
||||
|
||||
[Export] public float Rotation { get; set; } = 0f;
|
||||
|
||||
private BulletSpawner _bulletSpawner;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_bulletSpawner = GetNode<BulletSpawner>("BulletSpawner");
|
||||
}
|
||||
|
||||
public void Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
switch (activationType)
|
||||
{
|
||||
case ActivationType.Toggle:
|
||||
break;
|
||||
case ActivationType.Enable:
|
||||
_bulletSpawner.SpawnBullet(BulletResource.MakeBullet(this.GlobalPosition, 1, Spread, Rotation));
|
||||
break;
|
||||
case ActivationType.Disable:
|
||||
break;
|
||||
case ActivationType.Use:
|
||||
_bulletSpawner.SpawnBullet(BulletResource.MakeBullet(this.GlobalPosition, 1, Spread, Rotation));
|
||||
break;
|
||||
case ActivationType.Destroy:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(activationType), activationType, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ public partial class BulletSpawner : Node2D
|
|||
float baseAngle = Mathf.Atan2(baseDirection.Y, baseDirection.X);
|
||||
|
||||
float offsetRadians = Mathf.DegToRad(bulletInfo.RotationOffset);
|
||||
float spreadStep = Mathf.DegToRad(bulletInfo.Spread) / (bulletInfo.BulletCount - 1); // Ensure proper spread spacing
|
||||
float spreadStep = Mathf.DegToRad(bulletInfo.Spread) / Mathf.Max(1,bulletInfo.BulletCount - 1); // Ensure proper spread spacing, also add 1 if 0
|
||||
float angle = baseAngle + offsetRadians + (spreadStep * i);
|
||||
// float angle = baseAngle + Mathf.DegToRad(bulletInfo.RotationOffset + (bulletInfo.Spread / bulletInfo.BulletCount) * i);
|
||||
|
||||
|
|
|
|||
|
|
@ -74,8 +74,6 @@ public partial class Door : Activable
|
|||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(activationType), activationType, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void SetState(DoorState state)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue