mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Danmaku system
This commit is contained in:
parent
9c8ec486fc
commit
fdec052c16
38 changed files with 924 additions and 9 deletions
53
Scripts/Components/BulletSpawner.cs
Normal file
53
Scripts/Components/BulletSpawner.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components;
|
||||
|
||||
public partial class BulletSpawner : Node2D
|
||||
{
|
||||
[Export] public PackedScene BulletScene;
|
||||
private GameManager _gameManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetNode<GameManager>("/root/GameScene");
|
||||
}
|
||||
|
||||
public void SpawnBullet(Vector2 position, Vector2 direction, float speed, BulletOwner owner, int count = 1, float angleOffset = 0, float spread = 0, PackedScene bulletScene = null, IBulletModifier modifier = null)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, bulletScene ?? BulletScene, position);
|
||||
|
||||
//var bullet = BulletScene.Instantiate<Bullet>();
|
||||
bullet.Position = position;
|
||||
bullet.Owner = owner;
|
||||
//bullet.Speed = speed;
|
||||
|
||||
float modifiedSpeed = modifier?.ModifySpeed(speed, i) ?? speed;
|
||||
bullet.Speed = modifiedSpeed;
|
||||
|
||||
Vector2 baseDirection = direction == Vector2.Zero ? Vector2.Right : direction.Normalized();
|
||||
float baseAngle = Mathf.Atan2(baseDirection.Y, baseDirection.X);
|
||||
//float angle = angleOffset + (360 / count) * i;
|
||||
float angle = baseAngle + Mathf.DegToRad(angleOffset + (spread / count) * i);
|
||||
Vector2 bulletDirection = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
|
||||
//Vector2 bulletDirection = new Vector2(Mathf.Cos(Mathf.DegToRad(angle)), Mathf.Sin(Mathf.DegToRad(angle)));
|
||||
|
||||
bullet.SetDirection(bulletDirection);
|
||||
//GetParent().AddChild(bullet);
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnTargetedBullet(Vector2 position, Vector2 target, float speed, BulletOwner owner, PackedScene bulletScene = null, int burstCount = 1, float spread = 0, IBulletModifier modifier = null)
|
||||
{
|
||||
Vector2 direction = (target - position).Normalized();
|
||||
SpawnBullet(position, direction, speed, owner, burstCount, spread: spread, bulletScene: bulletScene, modifier: modifier);
|
||||
}
|
||||
|
||||
public void SpawnSpiralPattern(Vector2 position, float speed, BulletOwner owner, int bulletCount, float rotationSpeed, double time, float spread, PackedScene bulletScene = null)
|
||||
{
|
||||
float angleOffset = (float)(rotationSpeed * time);
|
||||
SpawnBullet(position, Vector2.Right, speed, owner, bulletCount, angleOffset, spread, bulletScene: bulletScene);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue