mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Moved modifiers code to resource
This commit is contained in:
parent
0203af4642
commit
f9aab9718a
12 changed files with 132 additions and 74 deletions
|
|
@ -25,7 +25,7 @@ public partial class Bullet : Area2D
|
|||
|
||||
public BulletInfo BulletInfo => _bulletInfo;
|
||||
|
||||
private List<TimeModifier> _modifiers = new();
|
||||
private List<ModifierWrapper> _modifiers = new();
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
|
|
@ -35,52 +35,57 @@ public partial class Bullet : Area2D
|
|||
|
||||
_gameManager = gameManager;
|
||||
|
||||
_modifiers = _bulletInfo.TimeModifiers;
|
||||
|
||||
// Need to clone them here
|
||||
// _modifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone()).ToList();
|
||||
|
||||
|
||||
// var clonedModifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone());
|
||||
// _modifiers = clonedModifiers.ToList();
|
||||
|
||||
|
||||
|
||||
|
||||
// Ugly hack to make instances unique
|
||||
//_modifiers = _bulletInfo.TimeModifiers.Select(x => x.Wrap()).ToList();
|
||||
_modifiers = _bulletInfo.TimeModifiers.Select(x => x.Wrap()).ToList();
|
||||
|
||||
}
|
||||
|
||||
private void ApplyTimeModifiers()
|
||||
private void ApplyTimeModifiers(double delta)
|
||||
{
|
||||
foreach (var modifier in _modifiers)
|
||||
{
|
||||
if (modifier.Applied)
|
||||
if (_elapsedTime >= modifier.TimeModifier.TimeInSeconds)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (_elapsedTime >= modifier.TimeInSeconds)
|
||||
{
|
||||
GD.Print("Applied time modifier");
|
||||
switch (modifier.ModifierType)
|
||||
{
|
||||
case TimeModifierType.SpeedChange:
|
||||
//_bulletInfo.Speed += modifier.Value;
|
||||
Speed = modifier.Value;
|
||||
break;
|
||||
case TimeModifierType.RotationChange:
|
||||
RotateBullet(modifier.Value);
|
||||
//Rotation += Mathf.DegToRad(modifier.Value);
|
||||
break;
|
||||
case TimeModifierType.FacePlayer:
|
||||
FacePlayer();
|
||||
break;
|
||||
}
|
||||
|
||||
if (!modifier.Continuous)
|
||||
if (!modifier.Applied)
|
||||
{
|
||||
modifier.Applied = true;
|
||||
modifier.TimeModifier.Start(this);
|
||||
}
|
||||
|
||||
modifier.TimeModifier.Update(this, delta);
|
||||
|
||||
// switch (modifier.ModifierType)
|
||||
// {
|
||||
// case TimeModifierType.SpeedChange:
|
||||
// //_bulletInfo.Speed += modifier.Value;
|
||||
// Speed = modifier.Value;
|
||||
// break;
|
||||
// case TimeModifierType.RotationChange:
|
||||
// RotateBullet(modifier.Value);
|
||||
// //Rotation += Mathf.DegToRad(modifier.Value);
|
||||
// break;
|
||||
// case TimeModifierType.FacePlayer:
|
||||
// FacePlayer();
|
||||
// break;
|
||||
// }
|
||||
|
||||
// if (!modifier.Continuous)
|
||||
// {
|
||||
// modifier.Applied = true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void RotateBullet(float degrees)
|
||||
public virtual void RotateBullet(float degrees)
|
||||
{
|
||||
float radians = Mathf.DegToRad(degrees);
|
||||
_direction = _direction.Rotated(radians).Normalized(); // Rotate direction
|
||||
|
|
@ -88,7 +93,7 @@ public partial class Bullet : Area2D
|
|||
//Rotation = radians;
|
||||
}
|
||||
|
||||
private void FacePlayer()
|
||||
public void FacePlayer()
|
||||
{
|
||||
if (_gameManager.Player != null)
|
||||
{
|
||||
|
|
@ -123,14 +128,16 @@ public partial class Bullet : Area2D
|
|||
public override void _Process(double delta)
|
||||
{
|
||||
_elapsedTime += delta;
|
||||
if (_bulletInfo != null)
|
||||
{
|
||||
ApplyTimeModifiers();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (_bulletInfo != null)
|
||||
{
|
||||
ApplyTimeModifiers(delta);
|
||||
}
|
||||
|
||||
this.Position += ((float)(Speed * delta) * _direction);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue