mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Added offsets and remade modifiers system
This commit is contained in:
parent
881a4897da
commit
aab69fb609
16 changed files with 474 additions and 426 deletions
|
|
@ -31,10 +31,15 @@ public partial class BulletSpawner : Node2D
|
|||
|
||||
// var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, bulletInfo.BulletScene ?? BulletScene, bulletInfo.Position);
|
||||
|
||||
if (bulletInfo.Modifier is not null)
|
||||
{
|
||||
bulletInfo = bulletInfo.Modifier.ModifyBullet(bulletInfo, i, bulletInfo.BulletCount);
|
||||
}
|
||||
|
||||
bullet.Initialize(bulletInfo, _gameManager);
|
||||
|
||||
float modifiedSpeed = bulletInfo.Modifier?.ModifySpeed(bulletInfo.Speed, i, bulletInfo.BulletCount) ?? bulletInfo.Speed;
|
||||
bullet.Speed = modifiedSpeed;
|
||||
// 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);
|
||||
|
|
@ -50,40 +55,46 @@ public partial class BulletSpawner : Node2D
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
// 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.Speed = speed;
|
||||
//
|
||||
// if (modifier is not null)
|
||||
// {
|
||||
// bullet.BulletInfo = modifier.ModifyBullet(bullet.BulletInfo, i, count);
|
||||
// }
|
||||
//
|
||||
// //float modifiedSpeed = modifier?.ModifySpeed(speed, i, count) ?? 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);
|
||||
// }
|
||||
// }
|
||||
|
||||
//var bullet = BulletScene.Instantiate<Bullet>();
|
||||
bullet.Position = position;
|
||||
//bullet.Speed = speed;
|
||||
|
||||
float modifiedSpeed = modifier?.ModifySpeed(speed, i, count) ?? 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 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 class BulletInfo
|
||||
public class BulletInfo(BulletResource originalBulletResource)
|
||||
{
|
||||
public BulletResource OriginalBulletResource { get; set; } = originalBulletResource;
|
||||
public Vector2 Position { get; set; }
|
||||
public Vector2 Direction { get; set; }
|
||||
public float Speed { get; set; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue