mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 21:35:53 +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
|
|
@ -1,55 +0,0 @@
|
|||
using Cirno.Scripts.Actors;
|
||||
using Cirno.Scripts.Components;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.AttackPatterns;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class PatternTest : AttackPattern
|
||||
{
|
||||
[Export] public PackedScene BulletScene;
|
||||
[Export] public float bulletSpeed = 5f;
|
||||
[Export] public int bulletCount = 12;
|
||||
[Export] public float duration = 3f;
|
||||
[Export] public float burstInterval = 0.5f;
|
||||
[Export] public BulletOwner owner = BulletOwner.Enemy;
|
||||
|
||||
public override IPatternMachine MakeMachine(Node2D parent)
|
||||
{
|
||||
return new PatternTestMachine(this, parent);
|
||||
}
|
||||
|
||||
public class PatternTestMachine(PatternTest pattern, Node2D parent) : IPatternMachine
|
||||
{
|
||||
public Node2D Parent => parent;
|
||||
private double timer;
|
||||
private double burstTimer;
|
||||
private BulletSpawner spawner;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
timer = 0;
|
||||
burstTimer = 0;
|
||||
spawner = Parent.GetNode<BulletSpawner>("BulletSpawner");
|
||||
}
|
||||
|
||||
public void UpdatePattern(double delta)
|
||||
{
|
||||
timer += delta;
|
||||
burstTimer += delta;
|
||||
if (timer < pattern.duration && burstTimer >= pattern.burstInterval)
|
||||
{
|
||||
spawner.SpawnBullet(Parent.GlobalPosition, Vector2.Right, pattern.bulletSpeed, pattern.owner, pattern.bulletCount, bulletScene: pattern.BulletScene);
|
||||
burstTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsComplete()
|
||||
{
|
||||
return timer >= pattern.duration;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://bay71pcaj4nj2
|
||||
|
|
@ -16,6 +16,8 @@ public partial class SpiralPattern : AttackPattern
|
|||
{
|
||||
[Export] public BulletResource BulletResource { get; set; }
|
||||
|
||||
[Export] public Vector2 EmitterOffset { get; set; } = Vector2.Zero;
|
||||
|
||||
//Export] public PackedScene BulletScene;
|
||||
//[Export] private float _bulletLifeTime = 20f; // Switch to res
|
||||
//[Export] private bool _destroyOnCollision = false; // Switch to res
|
||||
|
|
@ -242,7 +244,7 @@ public partial class SpiralPattern : AttackPattern
|
|||
}
|
||||
}
|
||||
|
||||
var bullet = pattern.MakeBullet(Parent.GlobalPosition, pattern.bulletCount,
|
||||
var bullet = pattern.MakeBullet(Parent.GlobalPosition + pattern.EmitterOffset, pattern.bulletCount,
|
||||
pattern.spread, angleOffset);
|
||||
|
||||
bullet.Direction = direction;
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
using Cirno.Scripts.Actors;
|
||||
using Cirno.Scripts.Components;
|
||||
using Cirno.Scripts.Resources;
|
||||
|
||||
namespace Cirno.Scripts.AttackPatterns;
|
||||
|
||||
using Godot;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class TargetedPattern : AttackPattern
|
||||
{
|
||||
[Export] public PackedScene BulletScene;
|
||||
|
||||
[Export] private float bulletSpeed = 5f;
|
||||
[Export] private float duration = 3f;
|
||||
[Export] private float burstInterval = 0.5f;
|
||||
[Export] private int bulletsPerShot = 1;
|
||||
[Export] private float spread = 0f;
|
||||
[Export] private BulletOwner owner = BulletOwner.Enemy;
|
||||
[Export] private BulletCreationModifier modifier;
|
||||
|
||||
public override IPatternMachine MakeMachine(Node2D parent)
|
||||
{
|
||||
return new TargetedPatternMachine(this, parent);
|
||||
}
|
||||
|
||||
public class TargetedPatternMachine(TargetedPattern pattern, Node2D parent) : IPatternMachine
|
||||
{
|
||||
public Node2D Parent => parent;
|
||||
|
||||
private double timer;
|
||||
private double burstTimer;
|
||||
private BulletSpawner spawner;
|
||||
//private Node2D player;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
timer = 0;
|
||||
burstTimer = 0;
|
||||
spawner = Parent.GetNode<BulletSpawner>("BulletSpawner");
|
||||
|
||||
}
|
||||
|
||||
public void UpdatePattern(double delta)
|
||||
{
|
||||
timer += delta;
|
||||
burstTimer += delta;
|
||||
if (timer < pattern.duration && burstTimer >= pattern.burstInterval && GameManager.Instance.PlayerPosition.HasValue)
|
||||
{
|
||||
spawner.SpawnTargetedBullet(Parent.GlobalPosition, GameManager.Instance.PlayerPosition.Value, pattern.bulletSpeed, pattern.owner, pattern.BulletScene, pattern.bulletsPerShot, pattern.spread, pattern.modifier);
|
||||
burstTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsComplete()
|
||||
{
|
||||
return timer >= pattern.duration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://by0fm3opaexcs
|
||||
|
|
@ -51,6 +51,8 @@ public partial class Bullet : Area2D
|
|||
|
||||
_elapsedTime = 0f;
|
||||
|
||||
this.Speed = bulletInfo.Speed;
|
||||
|
||||
// Need to clone them here
|
||||
// _modifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone()).ToList();
|
||||
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using Cirno.Scripts.Components;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources;
|
||||
|
||||
|
|
@ -6,5 +7,6 @@ namespace Cirno.Scripts.Resources;
|
|||
[Tool]
|
||||
public abstract partial class BulletCreationModifier : Resource, IBulletModifier
|
||||
{
|
||||
public abstract float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets);
|
||||
public abstract BulletInfo ModifyBullet(BulletInfo bullet, int bulletIndex, int totalBullets);
|
||||
//public abstract float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets);
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ public partial class BulletResource : Resource
|
|||
|
||||
public BulletInfo MakeBullet(Vector2 position, int count = 1, float spread = 0f, float rotationOffset = 0f)
|
||||
{
|
||||
return new BulletInfo()
|
||||
return new BulletInfo(this)
|
||||
{
|
||||
Position = position,
|
||||
Direction = Direction,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using Cirno.Scripts.Components;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources;
|
||||
|
||||
|
|
@ -8,7 +9,13 @@ public partial class DecreasingSpeedModifier : BulletCreationModifier, IBulletMo
|
|||
{
|
||||
[Export] private float decreaseRate = 0.1f;
|
||||
|
||||
public override float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
|
||||
public override BulletInfo ModifyBullet(BulletInfo bullet, int bulletIndex, int totalBullets)
|
||||
{
|
||||
bullet.Speed = ModifySpeed(bullet.OriginalBulletResource.BulletSpeed, bulletIndex, totalBullets);
|
||||
return bullet;
|
||||
}
|
||||
|
||||
public float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
|
||||
{
|
||||
return Mathf.Max(0, baseSpeed - (decreaseRate * bulletIndex));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using Godot;
|
||||
using Cirno.Scripts.Components;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources;
|
||||
|
||||
public interface IBulletModifier
|
||||
{
|
||||
float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets);
|
||||
BulletInfo ModifyBullet(BulletInfo bullet, int bulletIndex, int totalBullets);
|
||||
//float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets);
|
||||
}
|
||||
56
Scripts/Resources/ScriptableBullets/ParallelPatternGroup.cs
Normal file
56
Scripts/Resources/ScriptableBullets/ParallelPatternGroup.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
using System.Collections.Generic;
|
||||
using Cirno.Scripts.AttackPatterns;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Resources.ScriptableBullets;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class ParallelPatternGroup : AttackPattern
|
||||
{
|
||||
[Export(PropertyHint.None, "suffix:s")] public float Duration { get; private set; } = 10f;
|
||||
[Export] public Array<AttackPattern> Patterns { get; private set; } = [];
|
||||
|
||||
public override IPatternMachine MakeMachine(Node2D parent)
|
||||
{
|
||||
return new ParallelPatternGroupMachine(this, parent);
|
||||
}
|
||||
|
||||
public class ParallelPatternGroupMachine(ParallelPatternGroup patternGroup, Node2D parent) : IPatternMachine
|
||||
{
|
||||
public Node2D Parent => parent;
|
||||
//private int _currentPatternIndex = 0;
|
||||
|
||||
//private AttackPattern CurrentPattern => patternGroup.Patterns[_currentPatternIndex];
|
||||
|
||||
private List<IPatternMachine> _patternMachines = [];
|
||||
|
||||
public void Start()
|
||||
{
|
||||
//_currentPatternIndex = 0;
|
||||
foreach (var pattern in patternGroup.Patterns)
|
||||
{
|
||||
var machine = pattern.MakeMachine(parent);
|
||||
_patternMachines.Add(machine);
|
||||
machine.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePattern(double delta)
|
||||
{
|
||||
foreach (var patternMachine in _patternMachines)
|
||||
{
|
||||
//if (!CurrentPattern.WaitForCompletion || _patternMachine.IsComplete())
|
||||
if ( patternMachine.IsComplete()) continue;
|
||||
patternMachine.UpdatePattern(delta);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool IsComplete()
|
||||
{
|
||||
return _patternMachines.TrueForAll(x => x.IsComplete());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://rqtkxuqmo7gi
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using Cirno.Scripts.Components;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources;
|
||||
|
||||
|
|
@ -12,7 +13,13 @@ public partial class SpeedModifier : BulletCreationModifier, IBulletModifier
|
|||
[Export] public float MinimumSpeed = 10f;
|
||||
[Export] public float ScalingFactor = 10.0f;
|
||||
|
||||
public override float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
|
||||
public override BulletInfo ModifyBullet(BulletInfo bullet, int bulletIndex, int totalBullets)
|
||||
{
|
||||
bullet.Speed = ModifySpeed(bullet.OriginalBulletResource.BulletSpeed, bulletIndex, totalBullets);
|
||||
return bullet;
|
||||
}
|
||||
|
||||
public float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
|
||||
{
|
||||
if (totalBullets <= 1)
|
||||
return baseSpeed;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue