diff --git a/Resources/BossPhases/Rumia_NS2.tres b/Resources/BossPhases/Rumia_NS2.tres new file mode 100644 index 00000000..e97f81f4 --- /dev/null +++ b/Resources/BossPhases/Rumia_NS2.tres @@ -0,0 +1,59 @@ +[gd_resource type="Resource" script_class="BossPhase" load_steps=9 format=3 uid="uid://ddb5dqocmk6x7"] + +[ext_resource type="Script" path="res://Scripts/Resources/BossPhase.cs" id="1_fdlxv"] +[ext_resource type="PackedScene" uid="uid://ck6f08w1fy5fa" path="res://Scenes/Weapons/Bullets/enemyBullet_rice_yellow.tscn" id="1_r6kqy"] +[ext_resource type="Script" path="res://Scripts/Resources/TimeModifier.cs" id="2_kghxb"] +[ext_resource type="Script" path="res://Scripts/AttackPatterns/SpiralPattern.cs" id="2_wkmhk"] + +[sub_resource type="Resource" id="Resource_17kqi"] +script = ExtResource("2_kghxb") +TimeInSeconds = 1.0 +ModifierType = 1 +Value = 45.0 + +[sub_resource type="Resource" id="Resource_puvpt"] +script = ExtResource("2_wkmhk") +BulletScene = ExtResource("1_r6kqy") +bulletSpeed = 20.0 +bulletCount = 8 +rotationSpeed = 0.0 +_rotationOffset = 0.0 +duration = 1.0 +burstInterval = 2.0 +spread = 360.0 +owner = 2 +_damageType = 0 +_bulletDamage = 1.0 +_timeModifiers = Array[Resource]([SubResource("Resource_17kqi")]) +_targetPlayer = false +WaitForCompletion = false + +[sub_resource type="Resource" id="Resource_sk6w4"] +script = ExtResource("2_kghxb") +TimeInSeconds = 1.0 +ModifierType = 1 +Value = -45.0 + +[sub_resource type="Resource" id="Resource_44j24"] +script = ExtResource("2_wkmhk") +BulletScene = ExtResource("1_r6kqy") +bulletSpeed = 20.0 +bulletCount = 8 +rotationSpeed = 0.0 +_rotationOffset = 180.0 +duration = 5.0 +burstInterval = 6.0 +spread = 360.0 +owner = 2 +_damageType = 0 +_bulletDamage = 1.0 +_timeModifiers = Array[Resource]([SubResource("Resource_sk6w4")]) +_targetPlayer = false +WaitForCompletion = true + +[resource] +script = ExtResource("1_fdlxv") +PhaseName = "" +Threshold = 800 +PlayAnimation = false +Patterns = Array[Object]([SubResource("Resource_puvpt"), SubResource("Resource_44j24")]) diff --git a/Scenes/Actors/Rumia.tscn b/Scenes/Actors/Rumia.tscn index e6046d84..36be2d9f 100644 --- a/Scenes/Actors/Rumia.tscn +++ b/Scenes/Actors/Rumia.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=15 format=3 uid="uid://d1rlw6ddpmrn8"] +[gd_scene load_steps=16 format=3 uid="uid://d1rlw6ddpmrn8"] [ext_resource type="Script" path="res://Scripts/Actors/Boss.cs" id="1_na4uq"] [ext_resource type="Resource" uid="uid://ks6fypeil6gk" path="res://Resources/BossPhases/TestBoss1.tres" id="2_1rhf6"] [ext_resource type="Texture2D" uid="uid://bcqgke6dthlrj" path="res://Sprites/Actors/Rumia.png" id="2_7k5gp"] +[ext_resource type="Resource" uid="uid://ddb5dqocmk6x7" path="res://Resources/BossPhases/Rumia_NS2.tres" id="2_eyxw4"] [ext_resource type="Script" path="res://Scripts/Components/ProximityPlayerDetection.cs" id="3_gka5j"] [ext_resource type="Resource" uid="uid://ccj0cqbveey8c" path="res://Resources/BossPhases/Rumia_SP1.tres" id="3_j7lbl"] [ext_resource type="Texture2D" uid="uid://csuprfskdo1qp" path="res://Sprites/Portraits/Rumia.png" id="4_at5iq"] @@ -28,7 +29,7 @@ collision_layer = 16 collision_mask = 9 script = ExtResource("1_na4uq") BossName = "Rumia" -Phases = Array[Resource]([ExtResource("2_1rhf6"), ExtResource("3_j7lbl")]) +Phases = Array[Resource]([ExtResource("2_eyxw4"), ExtResource("2_1rhf6"), ExtResource("3_j7lbl")]) BossHudPrefab = ExtResource("4_ehp8q") _bossPortraitTexture = ExtResource("4_at5iq") Health = 1000.0 diff --git a/Scenes/Weapons/Bullets/enemyBullet_rice_yellow.tscn b/Scenes/Weapons/Bullets/enemyBullet_rice_yellow.tscn new file mode 100644 index 00000000..9f1a855f --- /dev/null +++ b/Scenes/Weapons/Bullets/enemyBullet_rice_yellow.tscn @@ -0,0 +1,29 @@ +[gd_scene load_steps=4 format=3 uid="uid://ck6f08w1fy5fa"] + +[ext_resource type="Script" path="res://Scripts/Bullet.cs" id="1_kfw6r"] +[ext_resource type="Texture2D" uid="uid://bckdbxo607h5n" path="res://Sprites/Bullets/rice_bullet_yellow.png" id="2_3q3kk"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_jxptd"] +radius = 2.23607 + +[node name="Bullet" type="Area2D" groups=["bullets"]] +collision_layer = 128 +collision_mask = 71 +script = ExtResource("1_kfw6r") +Speed = 200.0 +metadata/_edit_group_ = true + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("2_3q3kk") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_jxptd") + +[node name="Node2D" type="Node2D" parent="."] +editor_description = "Player Bullet" + +[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] + +[connection signal="area_entered" from="." to="." method="_on_area_entered"] +[connection signal="body_entered" from="." to="." method="_on_body_entered"] +[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"] diff --git a/Scenes/test.tscn b/Scenes/test.tscn index ca8d9432..cfeb3f4b 100644 --- a/Scenes/test.tscn +++ b/Scenes/test.tscn @@ -369,6 +369,6 @@ position = Vector2(-808, -400) [node name="Ammo4" parent="." instance=ExtResource("34_17pjh")] position = Vector2(-791, -401) -[node name="ScriptableAreaTrigger" parent="." instance=ExtResource("43_kf3qc")] +[node name="BossBattleStartScript" parent="." instance=ExtResource("43_kf3qc")] position = Vector2(-1487, -396) Events = Array[Object]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy")]) diff --git a/Scripts/AttackPatterns/SpiralPattern.cs b/Scripts/AttackPatterns/SpiralPattern.cs index 99179601..1ceec4df 100644 --- a/Scripts/AttackPatterns/SpiralPattern.cs +++ b/Scripts/AttackPatterns/SpiralPattern.cs @@ -5,6 +5,7 @@ using Cirno.Scripts.Components; using Cirno.Scripts.Resources; using Godot; using Godot.Collections; +using Array = System.Array; namespace Cirno.Scripts.AttackPatterns; @@ -23,7 +24,7 @@ public partial class SpiralPattern : AttackPattern [Export] private DamageType _damageType = DamageType.Neutral; [Export] private float _bulletDamage = 1f; [Export] private BulletCreationModifier _modifier; - [Export] private Array _timeModifiers; + [Export] private Array _timeModifiers; [Export] private bool _targetPlayer = false; @@ -50,7 +51,6 @@ public partial class SpiralPattern : AttackPattern float angleOffset = _rotationOffset + (float)(rotationSpeed * timer); Vector2 direction = Vector2.Right; - ; if (_targetPlayer && Boss.GameManager.PlayerPosition.HasValue) { @@ -70,7 +70,11 @@ public partial class SpiralPattern : AttackPattern BulletScene = BulletScene, RotationOffset = angleOffset, Modifier = _modifier, - TimeModifiers = _timeModifiers?.Where(mod => mod is TimeModifier).Cast().ToList() ?? new List() + TimeModifiers = ((_timeModifiers?.Where(mod => mod != null)) ?? Array.Empty()).Select(m => new ModifierWrapper() + { + TimeModifier = m, + Applied = false + }).ToList() }); // spawner.SpawnSpiralPattern(Boss.GlobalPosition, bulletSpeed, owner, bulletCount, rotationSpeed, timer, spread, BulletScene); diff --git a/Scripts/Bullet.cs b/Scripts/Bullet.cs index 2c9c8838..7aa4f06e 100644 --- a/Scripts/Bullet.cs +++ b/Scripts/Bullet.cs @@ -1,6 +1,8 @@ using Godot; using System; +using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using Cirno.Scripts; using Cirno.Scripts.Components; using Cirno.Scripts.Resources; @@ -22,32 +24,41 @@ public partial class Bullet : Area2D private BulletInfo _bulletInfo; public BulletInfo BulletInfo => _bulletInfo; + + private List _modifiers = new(); public void Initialize(BulletInfo bulletInfo) { _bulletInfo = bulletInfo; + + // Ugly hack to make instances unique + _modifiers = _bulletInfo.TimeModifiers.Select(x => new ModifierWrapper() + { + TimeModifier = x.TimeModifier, + Applied = x.Applied + }).ToList(); - //Position = bulletInfo.Position; } private void ApplyTimeModifiers() { - foreach (var modifier in _bulletInfo.TimeModifiers) + foreach (var modifier in _modifiers) { if (modifier.Applied) { continue; } - if (_elapsedTime >= modifier.TimeInSeconds) + if (_elapsedTime >= modifier.TimeModifier.TimeInSeconds) { - switch (modifier.ModifierType) + GD.Print("Applied time modifier"); + switch (modifier.TimeModifier.ModifierType) { case TimeModifierType.SpeedChange: //_bulletInfo.Speed += modifier.Value; - Speed = modifier.Value; + Speed = modifier.TimeModifier.Value; break; case TimeModifierType.RotationChange: - RotateBullet(modifier.Value); + RotateBullet(modifier.TimeModifier.Value); //Rotation += Mathf.DegToRad(modifier.Value); break; case TimeModifierType.FacePlayer: @@ -64,6 +75,8 @@ public partial class Bullet : Area2D { float radians = Mathf.DegToRad(degrees); _direction = _direction.Rotated(radians).Normalized(); // Rotate direction + SetRotation(Rotation + radians); + //Rotation = radians; } @@ -93,7 +106,9 @@ public partial class Bullet : Area2D var normalized = direction.Normalized(); _direction = normalized; - + + SetRotation(Mathf.Atan2(normalized.Y,normalized.X) + Mathf.Pi / 2); + //Debug.WriteLine($"Bullet Shot at direction {direction.X} {direction.Y}"); } diff --git a/Scripts/Components/BulletSpawner.cs b/Scripts/Components/BulletSpawner.cs index 44f62f26..7becde92 100644 --- a/Scripts/Components/BulletSpawner.cs +++ b/Scripts/Components/BulletSpawner.cs @@ -23,24 +23,22 @@ public partial class BulletSpawner : Node2D var bullet = this.CreateChildOf(_gameManager.BulletsContainer, bulletInfo.BulletScene ?? BulletScene, bulletInfo.Position); bullet.Initialize(bulletInfo); - - //var bullet = BulletScene.Instantiate(); - //bullet.Position = bulletInfo.Position; - //bullet.Owner = bulletInfo.Owner; - //bullet.Speed = speed; - + 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); - //float angle = angleOffset + (360 / count) * i; - float angle = baseAngle + Mathf.DegToRad(bulletInfo.RotationOffset + (bulletInfo.Spread / bulletInfo.BulletCount) * i); + + float offsetRadians = Mathf.DegToRad(bulletInfo.RotationOffset); + float spreadStep = Mathf.DegToRad(bulletInfo.Spread) / (bulletInfo.BulletCount - 1); // Ensure proper spread spacing + 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)); - //Vector2 bulletDirection = new Vector2(Mathf.Cos(Mathf.DegToRad(angle)), Mathf.Sin(Mathf.DegToRad(angle))); + bullet.SetDirection(bulletDirection); - //GetParent().AddChild(bullet); } } @@ -93,5 +91,5 @@ public class BulletInfo public PackedScene BulletScene { get; set; } public PackedScene DestructionParticlesScene { get; set; } public IBulletModifier Modifier { get; set; } - public List TimeModifiers { get; set; } = new List(); + public List TimeModifiers { get; set; } = new List(); } \ No newline at end of file diff --git a/Scripts/Resources/BulletResource.cs b/Scripts/Resources/BulletResource.cs index e9d19625..e435274b 100644 --- a/Scripts/Resources/BulletResource.cs +++ b/Scripts/Resources/BulletResource.cs @@ -39,8 +39,18 @@ public partial class BulletResource : Resource Modifier = Modifier, LifeTime = LifeTime, DestructionParticlesScene = DestructionParticlesScene, - TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast().ToList() ?? - new List() + TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast().Select(m => new ModifierWrapper() + { + TimeModifier = m, + Applied = false + }).ToList() + // TimeModifiers = TimeModifiers?.Select(x => new ModifierWrapper() + // { + // Applied = false, + // TimeModifier = x + // }) + // TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast().ToList() ?? + // new List() }; } } \ No newline at end of file diff --git a/Scripts/Resources/TimeModifier.cs b/Scripts/Resources/TimeModifier.cs index a1bab8a0..4d539c07 100644 --- a/Scripts/Resources/TimeModifier.cs +++ b/Scripts/Resources/TimeModifier.cs @@ -8,7 +8,12 @@ public partial class TimeModifier : Resource [Export] public float TimeInSeconds = 1f; [Export] public TimeModifierType ModifierType; [Export] public float Value; - public bool Applied = false; +} + +public class ModifierWrapper +{ + public TimeModifier TimeModifier { get; set; } + public bool Applied { get; set; } = false; } public enum TimeModifierType diff --git a/Sprites/Bullets/rice_bullet_yellow.aseprite b/Sprites/Bullets/rice_bullet_yellow.aseprite new file mode 100644 index 00000000..dab5d67f --- /dev/null +++ b/Sprites/Bullets/rice_bullet_yellow.aseprite @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ebda9917da0ac619c8c0bc1e240be6b6939f037811ec9d77c352d3d0c7cd238 +size 587 diff --git a/Sprites/Bullets/rice_bullet_yellow.png b/Sprites/Bullets/rice_bullet_yellow.png new file mode 100644 index 00000000..37e784b2 --- /dev/null +++ b/Sprites/Bullets/rice_bullet_yellow.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f06125f8fa0ec892e93d7926949164e1fbac6f8834dfdabcd450674d41aebe9 +size 123 diff --git a/Sprites/Bullets/rice_bullet_yellow.png.import b/Sprites/Bullets/rice_bullet_yellow.png.import new file mode 100644 index 00000000..30c71be3 --- /dev/null +++ b/Sprites/Bullets/rice_bullet_yellow.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bckdbxo607h5n" +path="res://.godot/imported/rice_bullet_yellow.png-a37c9df9af3ce6b170ad710d5e00eef0.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/Bullets/rice_bullet_yellow.png" +dest_files=["res://.godot/imported/rice_bullet_yellow.png-a37c9df9af3ce6b170ad710d5e00eef0.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1