mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Shooting and big tank fix
This commit is contained in:
parent
cc00c8eaf0
commit
0a6e89faed
26 changed files with 797 additions and 9 deletions
55
Scripts/Actors/BulletSpawner3D.cs
Normal file
55
Scripts/Actors/BulletSpawner3D.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using Cirno.Scripts.Components;
|
||||
using Cirno.Scripts.Controllers;
|
||||
using Cirno.Scripts.Weapons;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Actors;
|
||||
|
||||
public partial class BulletSpawner3D : Node3D
|
||||
{
|
||||
[Export] public PackedScene BulletScene;
|
||||
|
||||
public void SpawnBullet(BulletInfo bulletInfo, Vector3 position)
|
||||
{
|
||||
var bulletScene = bulletInfo.BulletScene ?? BulletScene;
|
||||
Bullet3D bullet;
|
||||
int count = bulletInfo.BulletCount;
|
||||
float spreadRadians = Mathf.DegToRad(bulletInfo.Spread);
|
||||
float step = count > 1 ? spreadRadians / (count - 1) : 0;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
|
||||
bullet = PoolingManager.Instance.SpawnBullet<Bullet3D>(bulletInfo.OriginalBulletResource);
|
||||
bullet.GlobalPosition = position;
|
||||
|
||||
if (bulletInfo.Modifier is not null)
|
||||
{
|
||||
bulletInfo = bulletInfo.Modifier.ModifyBullet(bulletInfo, i, count);
|
||||
}
|
||||
|
||||
bullet.Initialize(bulletInfo);
|
||||
|
||||
Vector2 baseDirection = bulletInfo.Direction == Vector2.Zero ? Vector2.Right : bulletInfo.Direction.Normalized();
|
||||
float baseAngle = Mathf.Atan2(baseDirection.Y, baseDirection.X);
|
||||
|
||||
// Spread centered: offset from center
|
||||
float offsetFromCenter = (i - (count - 1) / 2.0f) * step;
|
||||
float angle = baseAngle + Mathf.DegToRad(bulletInfo.RotationOffset) + offsetFromCenter;
|
||||
|
||||
Vector2 bulletDirection = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
|
||||
bullet.SetDirection(bulletDirection);
|
||||
|
||||
// float offsetRadians = Mathf.DegToRad(bulletInfo.RotationOffset);
|
||||
// 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);
|
||||
//
|
||||
//
|
||||
// Vector2 bulletDirection = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
|
||||
//
|
||||
// bullet.SetDirection(bulletDirection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1
Scripts/Actors/BulletSpawner3D.cs.uid
Normal file
1
Scripts/Actors/BulletSpawner3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bf5f2phitdqw8
|
||||
97
Scripts/Actors/ScriptableBulletsEmitter3D.cs
Normal file
97
Scripts/Actors/ScriptableBulletsEmitter3D.cs
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
using Cirno.Scripts.AttackPatterns;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Resources.BulletScripts;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Actors;
|
||||
|
||||
public partial class ScriptableBulletsEmitter3D : Node3D, IActivable, IScriptHost3D
|
||||
{
|
||||
public Node3D ParentObject => this;
|
||||
|
||||
[Export]
|
||||
public BulletScript3D Script { get; set; }
|
||||
|
||||
[Export]
|
||||
public bool InvertSignal { get; private set; } = false;
|
||||
|
||||
[Export]
|
||||
public bool EmitOnStart { get; set; } = false;
|
||||
|
||||
[Signal]
|
||||
public delegate void StateChangedEventHandler(bool isEmitting);
|
||||
|
||||
private bool _isActive = false;
|
||||
|
||||
//private BulletScript _scriptInstance;
|
||||
|
||||
protected BulletScript3D.BulletScriptMachine ScriptMachine;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
//_scriptInstance = Script.Duplicate(true) as BulletScript;
|
||||
|
||||
ScriptMachine = Script.Make(this);
|
||||
|
||||
_homePosition = this.GlobalPosition;
|
||||
|
||||
if (EmitOnStart)
|
||||
{
|
||||
_isActive = true;
|
||||
ScriptMachine.Start();
|
||||
}
|
||||
EmitSignal(SignalName.StateChanged, _isActive);
|
||||
}
|
||||
|
||||
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
switch (activationType)
|
||||
{
|
||||
case ActivationType.Use:
|
||||
case ActivationType.Toggle:
|
||||
_isActive = !_isActive;
|
||||
break;
|
||||
case ActivationType.Open:
|
||||
case ActivationType.Enable:
|
||||
_isActive = !InvertSignal;
|
||||
break;
|
||||
case ActivationType.Close:
|
||||
case ActivationType.Disable:
|
||||
_isActive = InvertSignal;
|
||||
break;
|
||||
case ActivationType.Destroy:
|
||||
_isActive = InvertSignal;
|
||||
// TODO: Explode
|
||||
break;
|
||||
}
|
||||
|
||||
if (_isActive)
|
||||
{
|
||||
ScriptMachine.Start();
|
||||
}
|
||||
|
||||
EmitSignal(SignalName.StateChanged, _isActive);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Toggle()
|
||||
{
|
||||
this.Activate();
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!_isActive) return;
|
||||
|
||||
ScriptMachine.UpdatePhase(delta);
|
||||
}
|
||||
|
||||
private Vector3 _homePosition;
|
||||
public Vector3 HomePosition => _homePosition;
|
||||
|
||||
public void ChangeSpriteDirection(Vector2 direction)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
1
Scripts/Actors/ScriptableBulletsEmitter3D.cs.uid
Normal file
1
Scripts/Actors/ScriptableBulletsEmitter3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dpibtd73awwp7
|
||||
Loading…
Add table
Add a link
Reference in a new issue