Projectile Rotation

This commit is contained in:
Marco 2025-02-13 18:25:55 +01:00
commit 56ac07367b
12 changed files with 188 additions and 27 deletions

View file

@ -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")])

View file

@ -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

View file

@ -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"]

View file

@ -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")])

View file

@ -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<Resource> _timeModifiers;
[Export] private Array<TimeModifier> _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<TimeModifier>().ToList() ?? new List<TimeModifier>()
TimeModifiers = ((_timeModifiers?.Where(mod => mod != null)) ?? Array.Empty<TimeModifier>()).Select(m => new ModifierWrapper()
{
TimeModifier = m,
Applied = false
}).ToList()
});
// spawner.SpawnSpiralPattern(Boss.GlobalPosition, bulletSpeed, owner, bulletCount, rotationSpeed, timer, spread, BulletScene);

View file

@ -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<ModifierWrapper> _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}");
}

View file

@ -23,24 +23,22 @@ public partial class BulletSpawner : Node2D
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, bulletInfo.BulletScene ?? BulletScene, bulletInfo.Position);
bullet.Initialize(bulletInfo);
//var bullet = BulletScene.Instantiate<Bullet>();
//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<TimeModifier> TimeModifiers { get; set; } = new List<TimeModifier>();
public List<ModifierWrapper> TimeModifiers { get; set; } = new List<ModifierWrapper>();
}

View file

@ -39,8 +39,18 @@ public partial class BulletResource : Resource
Modifier = Modifier,
LifeTime = LifeTime,
DestructionParticlesScene = DestructionParticlesScene,
TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().ToList() ??
new List<TimeModifier>()
TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().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<TimeModifier>().ToList() ??
// new List<TimeModifier>()
};
}
}

View file

@ -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

BIN
Sprites/Bullets/rice_bullet_yellow.aseprite (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Sprites/Bullets/rice_bullet_yellow.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -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