mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
New Modifier
This commit is contained in:
parent
50c111ee28
commit
019f7d7ca0
18 changed files with 423 additions and 45 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using System;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components;
|
||||
|
|
@ -12,6 +13,32 @@ public partial class BulletSpawner : Node2D
|
|||
{
|
||||
_gameManager = GetNode<GameManager>("/root/GameScene");
|
||||
}
|
||||
|
||||
public void SpawnBullet(BulletInfo bulletInfo)
|
||||
{
|
||||
for (int i = 0; i < bulletInfo.BulletCount; i++)
|
||||
{
|
||||
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, bulletInfo.BulletScene ?? BulletScene, bulletInfo.Position);
|
||||
|
||||
//var bullet = BulletScene.Instantiate<Bullet>();
|
||||
bullet.Position = bulletInfo.Position;
|
||||
bullet.Owner = bulletInfo.Owner;
|
||||
//bullet.Speed = speed;
|
||||
|
||||
float modifiedSpeed = bulletInfo.Modifier?.ModifySpeed(bulletInfo.Speed, i, bulletInfo.BulletCount) ?? bulletInfo.Speed;
|
||||
bullet.Speed = modifiedSpeed;
|
||||
|
||||
Vector2 baseDirection = bulletInfo.Direction == Vector2.Zero ? Vector2.Right : bulletInfo.Direction.Normalized();
|
||||
float baseAngle = Mathf.Atan2(baseDirection.Y, baseDirection.X);
|
||||
//float angle = angleOffset + (360 / count) * i;
|
||||
float angle = baseAngle + Mathf.DegToRad(bulletInfo.RotationOffset + (bulletInfo.Spread / bulletInfo.BulletCount) * 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 SpawnBullet(Vector2 position, Vector2 direction, float speed, BulletOwner owner, int count = 1, float angleOffset = 0, float spread = 0, PackedScene bulletScene = null, IBulletModifier modifier = null)
|
||||
{
|
||||
|
|
@ -24,7 +51,7 @@ public partial class BulletSpawner : Node2D
|
|||
bullet.Owner = owner;
|
||||
//bullet.Speed = speed;
|
||||
|
||||
float modifiedSpeed = modifier?.ModifySpeed(speed, i) ?? speed;
|
||||
float modifiedSpeed = modifier?.ModifySpeed(speed, i, count) ?? speed;
|
||||
bullet.Speed = modifiedSpeed;
|
||||
|
||||
Vector2 baseDirection = direction == Vector2.Zero ? Vector2.Right : direction.Normalized();
|
||||
|
|
@ -44,10 +71,26 @@ public partial class BulletSpawner : Node2D
|
|||
Vector2 direction = (target - position).Normalized();
|
||||
SpawnBullet(position, direction, speed, owner, burstCount, spread: spread, bulletScene: bulletScene, modifier: modifier);
|
||||
}
|
||||
|
||||
|
||||
[Obsolete]
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public class BulletInfo
|
||||
{
|
||||
public Vector2 Position { get; set; }
|
||||
public Vector2 Direction { get; set; }
|
||||
public float Speed { get; set; }
|
||||
public BulletOwner Owner { get; set; }
|
||||
public int BulletCount { get; set; }
|
||||
public float RotationSpeed { get; set; }
|
||||
public float RotationOffset { get; set; }
|
||||
//public double Time { get; set; }
|
||||
public float Spread { get; set; }
|
||||
public PackedScene BulletScene { get; set; }
|
||||
public IBulletModifier Modifier { get; set; }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue