diff --git a/Resources/Bullets/cheat_bullet.tres b/Resources/Bullets/cheat_bullet.tres index 1cfeac4c..3f77ee83 100644 --- a/Resources/Bullets/cheat_bullet.tres +++ b/Resources/Bullets/cheat_bullet.tres @@ -13,4 +13,5 @@ LifeTime = 10.0 DestroyOnCollision = true Owner = 1 DamageType = 0 +Controllable = true TimeModifiers = null diff --git a/Scenes/test.tscn b/Scenes/test.tscn index f5ca0841..a66881b8 100644 --- a/Scenes/test.tscn +++ b/Scenes/test.tscn @@ -461,6 +461,7 @@ LifeTime = 20.0 DestroyOnCollision = true Owner = 2 DamageType = 0 +Controllable = false Modifier = SubResource("Resource_ksslq") TimeModifiers = Array[Object]([]) metadata/_custom_type_script = "uid://dslyrfcej3g2n" diff --git a/Scripts/Bullet.cs b/Scripts/Bullet.cs index ab1140de..3239d0b8 100644 --- a/Scripts/Bullet.cs +++ b/Scripts/Bullet.cs @@ -35,14 +35,14 @@ public partial class Bullet : Area2D _gameManager = gameManager; _elapsedTime = 0f; - + // 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(); } @@ -151,9 +151,26 @@ public partial class Bullet : Area2D ApplyTimeModifiers(delta); } + + if (BulletInfo.Controllabe) + { + ControlBullet(delta); + } + this.Position += ((float)(Speed * delta) * _direction); } + private void ControlBullet(double delta) + { + var axis = Input.GetAxis("left", "right"); + + if (axis != 0) + { + float rotationSpeed = 180f; // Degrees per second + RotateBullet(axis * rotationSpeed * (float)delta); + } + } + private void _on_visible_on_screen_notifier_2d_screen_exited() { //Debug.WriteLine("Destroy bullet out of screen"); diff --git a/Scripts/Components/BulletSpawner.cs b/Scripts/Components/BulletSpawner.cs index b112b84f..e4e60a34 100644 --- a/Scripts/Components/BulletSpawner.cs +++ b/Scripts/Components/BulletSpawner.cs @@ -11,7 +11,7 @@ public partial class BulletSpawner : Node2D { [Export] public PackedScene BulletScene; private GameManager _gameManager; - + public override void _Ready() { _gameManager = this.GetGameManager(); @@ -21,16 +21,16 @@ public partial class BulletSpawner : Node2D { var bulletScene = bulletInfo.BulletScene ?? BulletScene; Bullet bullet; - + for (int i = 0; i < bulletInfo.BulletCount; i++) { if (bulletInfo.IsLaser) bullet = this.CreateChildOf(_gameManager.BulletsContainer, bulletScene, bulletInfo.Position); else bullet = this.CreateChildOf(_gameManager.BulletsContainer, bulletScene, bulletInfo.Position); - + // var bullet = this.CreateChildOf(_gameManager.BulletsContainer, bulletInfo.BulletScene ?? BulletScene, bulletInfo.Position); - + bullet.Initialize(bulletInfo, _gameManager); float modifiedSpeed = bulletInfo.Modifier?.ModifySpeed(bulletInfo.Speed, i, bulletInfo.BulletCount) ?? bulletInfo.Speed; @@ -38,28 +38,28 @@ public partial class BulletSpawner : Node2D Vector2 baseDirection = bulletInfo.Direction == Vector2.Zero ? Vector2.Right : bulletInfo.Direction.Normalized(); float baseAngle = Mathf.Atan2(baseDirection.Y, baseDirection.X); - + float offsetRadians = Mathf.DegToRad(bulletInfo.RotationOffset); - float spreadStep = Mathf.DegToRad(bulletInfo.Spread) / Mathf.Max(1,bulletInfo.BulletCount - 1); // Ensure proper spread spacing, also add 1 if 0 + float spreadStep = Mathf.DegToRad(bulletInfo.Spread) / Mathf.Max(1, bulletInfo.BulletCount - 1); // Ensure proper spread spacing, also add 1 if 0 float angle = baseAngle + offsetRadians + (spreadStep * i); // float angle = baseAngle + Mathf.DegToRad(bulletInfo.RotationOffset + (bulletInfo.Spread / bulletInfo.BulletCount) * i); - + Vector2 bulletDirection = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)); - + bullet.SetDirection(bulletDirection); } } - + 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(_gameManager.BulletsContainer, bulletScene ?? BulletScene, position); - + //var bullet = BulletScene.Instantiate(); bullet.Position = position; //bullet.Speed = speed; - + float modifiedSpeed = modifier?.ModifySpeed(speed, i, count) ?? speed; bullet.Speed = modifiedSpeed; @@ -74,7 +74,7 @@ public partial class BulletSpawner : Node2D //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(); @@ -97,6 +97,7 @@ public class BulletInfo public float RotationOffset { get; set; } //public double Time { get; set; } public float Spread { get; set; } + public bool Controllabe { get; set; } = false; public PackedScene BulletScene { get; set; } public PackedScene DestructionParticlesScene { get; set; } public IBulletModifier Modifier { get; set; } diff --git a/Scripts/Resources/BulletResource.cs b/Scripts/Resources/BulletResource.cs index 7c832c72..83f93433 100644 --- a/Scripts/Resources/BulletResource.cs +++ b/Scripts/Resources/BulletResource.cs @@ -19,11 +19,12 @@ public partial class BulletResource : Resource [Export] public bool DestroyOnCollision = true; [Export] public BulletOwner Owner = BulletOwner.None; [Export] public DamageType DamageType = DamageType.Neutral; + [Export] public bool Controllable = false; [Export] public BulletCreationModifier Modifier; [Export] public Array TimeModifiers; - + public BulletInfo MakeBullet(Vector2 position, int count = 1, float spread = 0f, float rotationOffset = 0f) { return new BulletInfo() @@ -42,6 +43,7 @@ public partial class BulletResource : Resource LifeTime = LifeTime, DestroyOnCollision = DestroyOnCollision, DestructionParticlesScene = DestructionParticlesScene, + Controllabe = Controllable, TimeModifiers = TimeModifiers.Select(x => x).ToList() // TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast().Select(m => new ModifierWrapper() // { diff --git a/Scripts/UI/MusicRoom.cs b/Scripts/UI/MusicRoom.cs index 08f32ee1..22c2096b 100644 --- a/Scripts/UI/MusicRoom.cs +++ b/Scripts/UI/MusicRoom.cs @@ -5,56 +5,56 @@ using Godot.Collections; public partial class MusicRoom : MenuBase { - [Export] - public Array Tracks { get; private set; } = new(); + [Export] + public Array Tracks { get; private set; } = new(); - [Export] - public ItemList TracksContainer { get; private set; } + [Export] + public ItemList TracksContainer { get; private set; } - [Export] - public Texture2D Icon { get; private set; } + [Export] + public Texture2D Icon { get; private set; } - [Export] - public Label DescriptionLabel { get; private set; } + [Export] + public Label DescriptionLabel { get; private set; } - private Dictionary _tracks = new(); + private Dictionary _tracks = new(); - public override void _Ready() - { - DescriptionLabel.Text = string.Empty; - TracksContainer.Clear(); - foreach (var track in Tracks) - { - var index = TracksContainer.AddItem($"{track.TrackName} ({track.AuthorName})", Icon); + public override void _Ready() + { + DescriptionLabel.Text = string.Empty; + TracksContainer.Clear(); + foreach (var track in Tracks) + { + var index = TracksContainer.AddItem($"{track.TrackName} ({track.AuthorName})", Icon); - var visualizer = new AudioNameVisualizer(); - visualizer.MusicData = track; - TracksContainer.CallDeferred("add_child", visualizer); + var visualizer = new AudioNameVisualizer(); + visualizer.MusicData = track; + TracksContainer.CallDeferred("add_child", visualizer); - _tracks.Add((long)index, visualizer); + _tracks.Add((long)index, visualizer); - } + } - TracksContainer.ItemSelected += (long selectedItem) => - { - var vis = _tracks[selectedItem]; - if (vis.MusicData is null) { return; } - StopAllTracks(); - vis.PlayWithName(); - UpdateDescription(vis.MusicData.Description); - }; - } + TracksContainer.ItemSelected += (long selectedItem) => + { + var vis = _tracks[selectedItem]; + if (vis.MusicData is null) { return; } + StopAllTracks(); + vis.PlayWithName(); + UpdateDescription(vis.MusicData.Description); + }; + } - private void StopAllTracks() - { - foreach (var track in _tracks) - { - track.Value.Stop(); - } - } + private void StopAllTracks() + { + foreach (var track in _tracks) + { + track.Value.Stop(); + } + } - private void UpdateDescription(string name) - { - DescriptionLabel.Text = name; - } + private void UpdateDescription(string name) + { + DescriptionLabel.Text = name; + } }