mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-14 05:45:54 +00:00
Time modifiers
This commit is contained in:
parent
690bae01bc
commit
4e6257dbe3
6 changed files with 99 additions and 9 deletions
|
|
@ -36,6 +36,7 @@ burstInterval = 1.0
|
||||||
spread = 180.0
|
spread = 180.0
|
||||||
owner = 2
|
owner = 2
|
||||||
_modifier = SubResource("Resource_l3ln6")
|
_modifier = SubResource("Resource_l3ln6")
|
||||||
|
_timeModifiers = Array[Resource]([])
|
||||||
WaitForCompletion = true
|
WaitForCompletion = true
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_7yi74"]
|
[sub_resource type="Resource" id="Resource_7yi74"]
|
||||||
|
|
@ -50,6 +51,7 @@ burstInterval = 1.0
|
||||||
spread = 180.0
|
spread = 180.0
|
||||||
owner = 2
|
owner = 2
|
||||||
_modifier = SubResource("Resource_l3ln6")
|
_modifier = SubResource("Resource_l3ln6")
|
||||||
|
_timeModifiers = null
|
||||||
WaitForCompletion = true
|
WaitForCompletion = true
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_gm1rv"]
|
[sub_resource type="Resource" id="Resource_gm1rv"]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
using Cirno.Scripts.Actors;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Cirno.Scripts.Actors;
|
||||||
using Cirno.Scripts.Components;
|
using Cirno.Scripts.Components;
|
||||||
using Cirno.Scripts.Resources;
|
using Cirno.Scripts.Resources;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Godot.Collections;
|
||||||
|
|
||||||
namespace Cirno.Scripts.AttackPatterns;
|
namespace Cirno.Scripts.AttackPatterns;
|
||||||
|
|
||||||
|
|
@ -18,6 +21,7 @@ public partial class SpiralPattern : AttackPattern
|
||||||
[Export] private float spread = 360f;
|
[Export] private float spread = 360f;
|
||||||
[Export] private BulletOwner owner = BulletOwner.Enemy;
|
[Export] private BulletOwner owner = BulletOwner.Enemy;
|
||||||
[Export] private Resource _modifier;
|
[Export] private Resource _modifier;
|
||||||
|
[Export] private Array<Resource> _timeModifiers;
|
||||||
|
|
||||||
private double timer;
|
private double timer;
|
||||||
private double burstTimer;
|
private double burstTimer;
|
||||||
|
|
@ -50,6 +54,7 @@ public partial class SpiralPattern : AttackPattern
|
||||||
BulletScene = BulletScene,
|
BulletScene = BulletScene,
|
||||||
RotationOffset = _rotationOffset,
|
RotationOffset = _rotationOffset,
|
||||||
Modifier = _modifier as IBulletModifier,
|
Modifier = _modifier as IBulletModifier,
|
||||||
|
TimeModifiers = _timeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().ToList() ?? new List<TimeModifier>()
|
||||||
});
|
});
|
||||||
|
|
||||||
// spawner.SpawnSpiralPattern(Boss.GlobalPosition, bulletSpeed, owner, bulletCount, rotationSpeed, timer, spread, BulletScene);
|
// spawner.SpawnSpiralPattern(Boss.GlobalPosition, bulletSpeed, owner, bulletCount, rotationSpeed, timer, spread, BulletScene);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
using Godot;
|
using Godot;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Cirno.Scripts.Components;
|
||||||
|
using Cirno.Scripts.Resources;
|
||||||
|
|
||||||
public partial class Bullet : Area2D
|
public partial class Bullet : Area2D
|
||||||
{
|
{
|
||||||
|
|
@ -15,15 +17,66 @@ public partial class Bullet : Area2D
|
||||||
|
|
||||||
private Vector2 _direction = Vector2.Right;
|
private Vector2 _direction = Vector2.Right;
|
||||||
|
|
||||||
//public delegate void BulletHitEventHandler(Node Body);
|
private double _elapsedTime = 0f;
|
||||||
//public event BulletHitEventHandler BulletHit;
|
private BulletInfo _bulletInfo;
|
||||||
|
|
||||||
// Called when the node enters the scene tree for the first time.
|
public void Initialize(BulletInfo bulletInfo)
|
||||||
public override void _Ready()
|
|
||||||
{
|
{
|
||||||
//this.Connect("body_entered", new Callable(this, nameof(OnBodyEntered)));
|
_bulletInfo = bulletInfo;
|
||||||
|
|
||||||
|
Position = bulletInfo.Position;
|
||||||
|
Owner = bulletInfo.Owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ApplyTimeModifiers()
|
||||||
|
{
|
||||||
|
foreach (var modifier in _bulletInfo.TimeModifiers)
|
||||||
|
{
|
||||||
|
if (modifier.Applied)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (_elapsedTime >= modifier.TimeInSeconds)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifier.Applied = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RotateBullet(float degrees)
|
||||||
|
{
|
||||||
|
float radians = Mathf.DegToRad(degrees);
|
||||||
|
_direction = _direction.Rotated(radians).Normalized(); // Rotate direction
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void FacePlayer()
|
||||||
|
{
|
||||||
|
// TODO: cache player
|
||||||
|
var player = GetTree().GetFirstNodeInGroup("Player") as Node2D;
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
_direction = (player.GlobalPosition - this.GlobalPosition).Normalized();
|
||||||
|
//LookAt(player.GlobalPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//private void OnBodyEntered(Node body)
|
//private void OnBodyEntered(Node body)
|
||||||
//{
|
//{
|
||||||
// When a body is entered, invoke the event and pass the collided body
|
// When a body is entered, invoke the event and pass the collided body
|
||||||
|
|
@ -45,6 +98,12 @@ public partial class Bullet : Area2D
|
||||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
|
_elapsedTime += delta;
|
||||||
|
if (_bulletInfo != null)
|
||||||
|
{
|
||||||
|
ApplyTimeModifiers();
|
||||||
|
}
|
||||||
|
|
||||||
this.Position += ((float)(Speed * delta) * _direction);
|
this.Position += ((float)(Speed * delta) * _direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Cirno.Scripts.Resources;
|
using Cirno.Scripts.Resources;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Godot.Collections;
|
||||||
|
|
||||||
namespace Cirno.Scripts.Components;
|
namespace Cirno.Scripts.Components;
|
||||||
|
|
||||||
|
|
@ -20,9 +22,11 @@ public partial class BulletSpawner : Node2D
|
||||||
{
|
{
|
||||||
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, bulletInfo.BulletScene ?? BulletScene, bulletInfo.Position);
|
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, bulletInfo.BulletScene ?? BulletScene, bulletInfo.Position);
|
||||||
|
|
||||||
|
bullet.Initialize(bulletInfo);
|
||||||
|
|
||||||
//var bullet = BulletScene.Instantiate<Bullet>();
|
//var bullet = BulletScene.Instantiate<Bullet>();
|
||||||
bullet.Position = bulletInfo.Position;
|
//bullet.Position = bulletInfo.Position;
|
||||||
bullet.Owner = bulletInfo.Owner;
|
//bullet.Owner = bulletInfo.Owner;
|
||||||
//bullet.Speed = speed;
|
//bullet.Speed = speed;
|
||||||
|
|
||||||
float modifiedSpeed = bulletInfo.Modifier?.ModifySpeed(bulletInfo.Speed, i, bulletInfo.BulletCount) ?? bulletInfo.Speed;
|
float modifiedSpeed = bulletInfo.Modifier?.ModifySpeed(bulletInfo.Speed, i, bulletInfo.BulletCount) ?? bulletInfo.Speed;
|
||||||
|
|
@ -93,4 +97,5 @@ public class BulletInfo
|
||||||
public float Spread { get; set; }
|
public float Spread { get; set; }
|
||||||
public PackedScene BulletScene { get; set; }
|
public PackedScene BulletScene { get; set; }
|
||||||
public IBulletModifier Modifier { get; set; }
|
public IBulletModifier Modifier { get; set; }
|
||||||
|
public List<TimeModifier> TimeModifiers { get; set; } = new List<TimeModifier>();
|
||||||
}
|
}
|
||||||
19
Scripts/Resources/TimeModifier.cs
Normal file
19
Scripts/Resources/TimeModifier.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Cirno.Scripts.Resources;
|
||||||
|
|
||||||
|
[GlobalClass]
|
||||||
|
public partial class TimeModifier : Resource
|
||||||
|
{
|
||||||
|
[Export] public float TimeInSeconds = 1f;
|
||||||
|
[Export] public TimeModifierType ModifierType;
|
||||||
|
[Export] public float Value;
|
||||||
|
public bool Applied = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum TimeModifierType
|
||||||
|
{
|
||||||
|
SpeedChange,
|
||||||
|
RotationChange,
|
||||||
|
FacePlayer
|
||||||
|
}
|
||||||
|
|
@ -21,7 +21,7 @@ Settings/temporaryLogLifetime=5.0
|
||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Cirno"
|
config/name="Cirno"
|
||||||
run/main_scene="res://Scenes/test.tscn"
|
run/main_scene="res://Scenes/Maps/BossTestArena.tscn"
|
||||||
config/features=PackedStringArray("4.3", "C#", "GL Compatibility")
|
config/features=PackedStringArray("4.3", "C#", "GL Compatibility")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue