mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-17 14:33:47 +00:00
Grahpics overhaul and predicting bullets
This commit is contained in:
parent
24386e724f
commit
946e7df71e
14 changed files with 144 additions and 26 deletions
Binary file not shown.
Binary file not shown.
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_resource type="Resource" script_class="BossPhase" load_steps=14 format=3 uid="uid://go6rfnglefe8"]
|
[gd_resource type="Resource" script_class="BossPhase" load_steps=17 format=3 uid="uid://go6rfnglefe8"]
|
||||||
|
|
||||||
[ext_resource type="Resource" uid="uid://bpc2kyft8q2qq" path="res://Resources/Bullets/simple_enemy_bullet_big.tres" id="1_favpk"]
|
[ext_resource type="Resource" uid="uid://bpc2kyft8q2qq" path="res://Resources/Bullets/simple_enemy_bullet_big.tres" id="1_favpk"]
|
||||||
[ext_resource type="Script" uid="uid://b5s5mjuk1rng5" path="res://Scripts/Resources/TimeModifier.cs" id="2_36ba4"]
|
[ext_resource type="Script" uid="uid://b5s5mjuk1rng5" path="res://Scripts/Resources/TimeModifier.cs" id="2_36ba4"]
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
[ext_resource type="Script" uid="uid://cdd6q2h0t1hhq" path="res://Scripts/Resources/BossPhase.cs" id="4_tppsm"]
|
[ext_resource type="Script" uid="uid://cdd6q2h0t1hhq" path="res://Scripts/Resources/BossPhase.cs" id="4_tppsm"]
|
||||||
[ext_resource type="Script" uid="uid://dslyrfcej3g2n" path="res://Scripts/Resources/BulletResource.cs" id="5_tppsm"]
|
[ext_resource type="Script" uid="uid://dslyrfcej3g2n" path="res://Scripts/Resources/BulletResource.cs" id="5_tppsm"]
|
||||||
[ext_resource type="PackedScene" uid="uid://ck6f08w1fy5fa" path="res://Scenes/Weapons/Bullets/enemyBullet_rice_yellow.tscn" id="6_tppsm"]
|
[ext_resource type="PackedScene" uid="uid://ck6f08w1fy5fa" path="res://Scenes/Weapons/Bullets/enemyBullet_rice_yellow.tscn" id="6_tppsm"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://chowj81jsdvcx" path="res://Scenes/Weapons/Bullets/enemyBullet_rice_red_small.tscn" id="7_du806"]
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_n7vdy"]
|
[sub_resource type="Resource" id="Resource_n7vdy"]
|
||||||
script = ExtResource("3_agmbo")
|
script = ExtResource("3_agmbo")
|
||||||
|
|
@ -20,6 +21,7 @@ burstInterval = 0.1
|
||||||
ShotsPerBurst = 4
|
ShotsPerBurst = 4
|
||||||
BurstRate = 2.0
|
BurstRate = 2.0
|
||||||
_targetPlayer = false
|
_targetPlayer = false
|
||||||
|
_predictPlayer = false
|
||||||
OverrideOwner = false
|
OverrideOwner = false
|
||||||
Owner = 0
|
Owner = 0
|
||||||
OverrideDamageType = false
|
OverrideDamageType = false
|
||||||
|
|
@ -61,6 +63,7 @@ burstInterval = 0.2
|
||||||
ShotsPerBurst = 4
|
ShotsPerBurst = 4
|
||||||
BurstRate = 0.0
|
BurstRate = 0.0
|
||||||
_targetPlayer = true
|
_targetPlayer = true
|
||||||
|
_predictPlayer = false
|
||||||
OverrideOwner = false
|
OverrideOwner = false
|
||||||
Owner = 0
|
Owner = 0
|
||||||
OverrideDamageType = false
|
OverrideDamageType = false
|
||||||
|
|
@ -84,6 +87,49 @@ burstInterval = 0.1
|
||||||
ShotsPerBurst = 4
|
ShotsPerBurst = 4
|
||||||
BurstRate = 2.0
|
BurstRate = 2.0
|
||||||
_targetPlayer = false
|
_targetPlayer = false
|
||||||
|
_predictPlayer = false
|
||||||
|
OverrideOwner = false
|
||||||
|
Owner = 0
|
||||||
|
OverrideDamageType = false
|
||||||
|
DamageType = 0
|
||||||
|
OverrideControllable = false
|
||||||
|
Controllable = false
|
||||||
|
OverrideCreationModifier = false
|
||||||
|
TimeModifiers = Array[ExtResource("2_36ba4")]([])
|
||||||
|
WaitForCompletion = true
|
||||||
|
metadata/_custom_type_script = "uid://c0ndqalsc4jve"
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id="Resource_ll7yb"]
|
||||||
|
script = ExtResource("5_tppsm")
|
||||||
|
BulletScene = ExtResource("7_du806")
|
||||||
|
BulletSpeed = 120.0
|
||||||
|
Direction = Vector2(1, 0)
|
||||||
|
BulletDamage = 12.0
|
||||||
|
LifeTime = 10.0
|
||||||
|
DestroyOnCollision = true
|
||||||
|
Owner = 2
|
||||||
|
DamageType = 0
|
||||||
|
RotateSprite = true
|
||||||
|
Controllable = false
|
||||||
|
Freezable = true
|
||||||
|
Grazeable = true
|
||||||
|
GrazeValue = 1.0
|
||||||
|
TimeModifiers = []
|
||||||
|
metadata/_custom_type_script = "uid://dslyrfcej3g2n"
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id="Resource_ctoyw"]
|
||||||
|
script = ExtResource("3_agmbo")
|
||||||
|
BulletResource = SubResource("Resource_ll7yb")
|
||||||
|
bulletCount = 1
|
||||||
|
rotationSpeed = 0.0
|
||||||
|
_rotationOffset = 0.0
|
||||||
|
duration = 0.41
|
||||||
|
spread = 360.0
|
||||||
|
burstInterval = 0.1
|
||||||
|
ShotsPerBurst = 4
|
||||||
|
BurstRate = 1.0
|
||||||
|
_targetPlayer = true
|
||||||
|
_predictPlayer = true
|
||||||
OverrideOwner = false
|
OverrideOwner = false
|
||||||
Owner = 0
|
Owner = 0
|
||||||
OverrideDamageType = false
|
OverrideDamageType = false
|
||||||
|
|
@ -119,12 +165,13 @@ BulletResource = SubResource("Resource_qhi1m")
|
||||||
bulletCount = 1
|
bulletCount = 1
|
||||||
rotationSpeed = 0.0
|
rotationSpeed = 0.0
|
||||||
_rotationOffset = 0.0
|
_rotationOffset = 0.0
|
||||||
duration = 2.0
|
duration = 1.0
|
||||||
spread = 360.0
|
spread = 360.0
|
||||||
burstInterval = 0.2
|
burstInterval = 0.2
|
||||||
ShotsPerBurst = 8
|
ShotsPerBurst = 8
|
||||||
BurstRate = 1.0
|
BurstRate = 1.0
|
||||||
_targetPlayer = true
|
_targetPlayer = true
|
||||||
|
_predictPlayer = false
|
||||||
OverrideOwner = false
|
OverrideOwner = false
|
||||||
Owner = 0
|
Owner = 0
|
||||||
OverrideDamageType = false
|
OverrideDamageType = false
|
||||||
|
|
@ -141,5 +188,5 @@ script = ExtResource("4_tppsm")
|
||||||
PhaseName = "Asdf"
|
PhaseName = "Asdf"
|
||||||
Threshold = 0
|
Threshold = 0
|
||||||
PlayAnimation = false
|
PlayAnimation = false
|
||||||
Patterns = Array[Object]([SubResource("Resource_n7vdy"), SubResource("Resource_hmrwn"), SubResource("Resource_tppsm"), SubResource("Resource_we0cr")])
|
Patterns = Array[Object]([SubResource("Resource_n7vdy"), SubResource("Resource_hmrwn"), SubResource("Resource_tppsm"), SubResource("Resource_ctoyw"), SubResource("Resource_we0cr")])
|
||||||
metadata/_custom_type_script = "uid://cdd6q2h0t1hhq"
|
metadata/_custom_type_script = "uid://cdd6q2h0t1hhq"
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
[gd_resource type="Resource" script_class="BossScript" load_steps=4 format=3 uid="uid://umimlgb0hs7k"]
|
[gd_resource type="Resource" script_class="BossScript" load_steps=3 format=3 uid="uid://umimlgb0hs7k"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://cdd6q2h0t1hhq" path="res://Scripts/Resources/BossPhase.cs" id="1_2i700"]
|
|
||||||
[ext_resource type="Resource" uid="uid://go6rfnglefe8" path="res://Resources/BossPhases/Roguelite/Roguelite_Boss_1.tres" id="2_bv4fb"]
|
[ext_resource type="Resource" uid="uid://go6rfnglefe8" path="res://Resources/BossPhases/Roguelite/Roguelite_Boss_1.tres" id="2_bv4fb"]
|
||||||
[ext_resource type="Script" uid="uid://inasa76li3ym" path="res://Scripts/Resources/ScriptableBullets/BossScript.cs" id="3_hj6ge"]
|
[ext_resource type="Script" uid="uid://inasa76li3ym" path="res://Scripts/Resources/ScriptableBullets/BossScript.cs" id="3_hj6ge"]
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource("3_hj6ge")
|
script = ExtResource("3_hj6ge")
|
||||||
BossName = &"Test"
|
BossName = &"Test"
|
||||||
Phases = Array[ExtResource("1_2i700")]([ExtResource("2_bv4fb")])
|
Phases = [ExtResource("2_bv4fb")]
|
||||||
metadata/_custom_type_script = "uid://inasa76li3ym"
|
metadata/_custom_type_script = "uid://inasa76li3ym"
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ burstInterval = 0.6
|
||||||
ShotsPerBurst = 4
|
ShotsPerBurst = 4
|
||||||
BurstRate = 0.8
|
BurstRate = 0.8
|
||||||
_targetPlayer = false
|
_targetPlayer = false
|
||||||
|
_predictPlayer = false
|
||||||
OverrideOwner = false
|
OverrideOwner = false
|
||||||
Owner = 0
|
Owner = 0
|
||||||
OverrideDamageType = false
|
OverrideDamageType = false
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ MovementSpeed = 40.0
|
||||||
Weapon = ExtResource("7_u7yd8")
|
Weapon = ExtResource("7_u7yd8")
|
||||||
LootDrops = Array[ExtResource("2_ivudp")]([SubResource("Resource_c8nix"), SubResource("Resource_gs2l3"), SubResource("Resource_sqnvg"), SubResource("Resource_5tyar"), SubResource("Resource_48xq6")])
|
LootDrops = Array[ExtResource("2_ivudp")]([SubResource("Resource_c8nix"), SubResource("Resource_gs2l3"), SubResource("Resource_sqnvg"), SubResource("Resource_5tyar"), SubResource("Resource_48xq6")])
|
||||||
MotivationReward = 4.0
|
MotivationReward = 4.0
|
||||||
|
PredictPlayer = false
|
||||||
PlayerDetectionRange = 90.0
|
PlayerDetectionRange = 90.0
|
||||||
ViewRange = 120.0
|
ViewRange = 120.0
|
||||||
AlarmReactRange = 150.0
|
AlarmReactRange = 150.0
|
||||||
|
|
|
||||||
|
|
@ -99,10 +99,11 @@ shape = SubResource("RectangleShape2D_u3c1h")
|
||||||
[node name="Features" type="Node2D" parent="."]
|
[node name="Features" type="Node2D" parent="."]
|
||||||
|
|
||||||
[node name="Teleporter" type="Marker2D" parent="Features"]
|
[node name="Teleporter" type="Marker2D" parent="Features"]
|
||||||
position = Vector2(44.8731, -125.141)
|
position = Vector2(61.8844, 118.644)
|
||||||
script = ExtResource("12_f3e1d")
|
script = ExtResource("12_f3e1d")
|
||||||
Type = 4
|
Type = 4
|
||||||
MarkerTexture = SubResource("AtlasTexture_5rt6n")
|
MarkerTexture = SubResource("AtlasTexture_5rt6n")
|
||||||
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="Features/Teleporter"]
|
[node name="Label" type="Label" parent="Features/Teleporter"]
|
||||||
offset_left = -20.0
|
offset_left = -20.0
|
||||||
|
|
@ -111,6 +112,8 @@ offset_right = 32.0
|
||||||
offset_bottom = 1.0
|
offset_bottom = 1.0
|
||||||
text = "Boss Debug"
|
text = "Boss Debug"
|
||||||
label_settings = ExtResource("14_c0yr1")
|
label_settings = ExtResource("14_c0yr1")
|
||||||
|
metadata/_edit_lock_ = true
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
[node name="StartTeleporter" type="Marker2D" parent="Features"]
|
[node name="StartTeleporter" type="Marker2D" parent="Features"]
|
||||||
position = Vector2(183, 88)
|
position = Vector2(183, 88)
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using Cirno.Scripts.Actors;
|
using Cirno.Scripts.Actors;
|
||||||
using Cirno.Scripts.Components;
|
using Cirno.Scripts.Components;
|
||||||
using Cirno.Scripts.Resources;
|
using Cirno.Scripts.Resources;
|
||||||
|
using Cirno.Scripts.Utils;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
using Array = System.Array;
|
using Array = System.Array;
|
||||||
|
|
@ -36,6 +37,7 @@ public partial class SpiralPattern : AttackPattern
|
||||||
// [ExportGroup("Modifiers")] [Export] private BulletCreationModifier _modifier;
|
// [ExportGroup("Modifiers")] [Export] private BulletCreationModifier _modifier;
|
||||||
// [ExportGroup("Modifiers")] [Export] private Array<TimeModifier> _timeModifiers;
|
// [ExportGroup("Modifiers")] [Export] private Array<TimeModifier> _timeModifiers;
|
||||||
[ExportCategory("Other")] [Export] public bool _targetPlayer = false;
|
[ExportCategory("Other")] [Export] public bool _targetPlayer = false;
|
||||||
|
[ExportCategory("Other")] [Export] public bool _predictPlayer = false;
|
||||||
|
|
||||||
[ExportCategory("Overrides")]
|
[ExportCategory("Overrides")]
|
||||||
[Export] public bool OverrideOwner { get; private set; } = false;
|
[Export] public bool OverrideOwner { get; private set; } = false;
|
||||||
|
|
@ -224,7 +226,20 @@ public partial class SpiralPattern : AttackPattern
|
||||||
|
|
||||||
if (pattern._targetPlayer && GameManager.Instance.PlayerPosition.HasValue)
|
if (pattern._targetPlayer && GameManager.Instance.PlayerPosition.HasValue)
|
||||||
{
|
{
|
||||||
direction = (GameManager.Instance.PlayerPosition.Value - Parent.GlobalPosition).Normalized();
|
if (pattern._predictPlayer && GameManager.Instance.PlayerVelocity.HasValue)
|
||||||
|
{
|
||||||
|
var predictedDirection = MathFunctions.PredictInterceptPosition(Parent.GlobalPosition,
|
||||||
|
GameManager.Instance.PlayerPosition.Value, GameManager.Instance.PlayerVelocity.Value,
|
||||||
|
pattern.BulletResource.BulletSpeed);
|
||||||
|
if (predictedDirection.HasValue)
|
||||||
|
{
|
||||||
|
direction = (predictedDirection.Value - Parent.GlobalPosition).Normalized();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
direction = (GameManager.Instance.PlayerPosition.Value - Parent.GlobalPosition).Normalized();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var bullet = pattern.MakeBullet(Parent.GlobalPosition, pattern.bulletCount,
|
var bullet = pattern.MakeBullet(Parent.GlobalPosition, pattern.bulletCount,
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ public partial class PlayerDetectionModule : Area2D
|
||||||
public uint ObstaclesCollisionMask { get; private set; }
|
public uint ObstaclesCollisionMask { get; private set; }
|
||||||
|
|
||||||
public Vector2? LastKnownPlayerPosition { get; set; }
|
public Vector2? LastKnownPlayerPosition { get; set; }
|
||||||
|
public Vector2? LastKnowPlayerVelocity { get; set; }
|
||||||
|
|
||||||
//public bool PlayerInActiveArea { get; private set; }
|
//public bool PlayerInActiveArea { get; private set; }
|
||||||
private CollisionShape2D _collisionShape2D;
|
private CollisionShape2D _collisionShape2D;
|
||||||
|
|
@ -77,6 +78,7 @@ public partial class PlayerDetectionModule : Area2D
|
||||||
if (found)
|
if (found)
|
||||||
{
|
{
|
||||||
LastKnownPlayerPosition = GameManager.Instance.PlayerPosition;
|
LastKnownPlayerPosition = GameManager.Instance.PlayerPosition;
|
||||||
|
LastKnowPlayerVelocity = GameManager.Instance.PlayerVelocity;
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using Cirno.Scripts.Components.Actors;
|
using Cirno.Scripts.Components.Actors;
|
||||||
using Cirno.Scripts.Enums;
|
using Cirno.Scripts.Enums;
|
||||||
|
using Cirno.Scripts.Utils;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace Cirno.Scripts.Components.FSM.Enemy;
|
namespace Cirno.Scripts.Components.FSM.Enemy;
|
||||||
|
|
@ -150,13 +151,27 @@ public partial class Shooting : EnemyStateBase
|
||||||
|
|
||||||
return null; // No valid strafe position found
|
return null; // No valid strafe position found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Vector2 GetShootDirection()
|
||||||
|
{
|
||||||
|
if (StorageModule.EnemyData.PredictPlayer && PlayerDetection.LastKnowPlayerVelocity.HasValue)
|
||||||
|
{
|
||||||
|
var predictedDirection = MathFunctions.PredictInterceptPosition(MainObject.GlobalPosition,
|
||||||
|
PlayerDetection.LastKnownPlayerPosition.Value, PlayerDetection.LastKnowPlayerVelocity.Value,
|
||||||
|
EquippedWeapon.WeaponData.BulletData.BulletSpeed);
|
||||||
|
if (predictedDirection.HasValue) return (predictedDirection.Value - MainObject.GlobalPosition).Normalized();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ( PlayerDetection.LastKnownPlayerPosition.Value - MainObject.GlobalPosition).Normalized();
|
||||||
|
}
|
||||||
|
|
||||||
private void Shoot()
|
private void Shoot()
|
||||||
{
|
{
|
||||||
if (EquippedWeapon == null) return;
|
if (EquippedWeapon == null) return;
|
||||||
if (!PlayerDetection.LastKnownPlayerPosition.HasValue) return;
|
if (!PlayerDetection.LastKnownPlayerPosition.HasValue) return;
|
||||||
|
|
||||||
var direction = ( PlayerDetection.LastKnownPlayerPosition.Value - MainObject.GlobalPosition).Normalized();
|
var direction = GetShootDirection();
|
||||||
|
|
||||||
// Shoot at the player's last known position
|
// Shoot at the player's last known position
|
||||||
EquippedWeapon.ShootDirection = direction;
|
EquippedWeapon.ShootDirection = direction;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ public partial class GameManager : Node2D
|
||||||
private Node2D _cameraTarget;
|
private Node2D _cameraTarget;
|
||||||
|
|
||||||
public Vector2? PlayerPosition => _player?.GlobalPosition ?? null;
|
public Vector2? PlayerPosition => _player?.GlobalPosition ?? null;
|
||||||
|
public Vector2? PlayerVelocity => _player?.Velocity ?? null;
|
||||||
|
|
||||||
[Export] public MapResource MapResource { get; private set; }
|
[Export] public MapResource MapResource { get; private set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ public partial class EnemyResource : Resource
|
||||||
|
|
||||||
[Export] public Array<LootDrop> LootDrops { get; private set; } = [];
|
[Export] public Array<LootDrop> LootDrops { get; private set; } = [];
|
||||||
[Export] public float MotivationReward { get; private set; } = 4f;
|
[Export] public float MotivationReward { get; private set; } = 4f;
|
||||||
|
[Export] public bool PredictPlayer { get; private set; } = false;
|
||||||
[ExportCategory("AI")] [Export] public float PlayerDetectionRange { get; private set; } = 90f;
|
[ExportCategory("AI")] [Export] public float PlayerDetectionRange { get; private set; } = 90f;
|
||||||
[Export] public float ViewRange { get; private set; } = 120f;
|
[Export] public float ViewRange { get; private set; } = 120f;
|
||||||
[Export] public float AlarmReactRange { get; private set; }
|
[Export] public float AlarmReactRange { get; private set; }
|
||||||
|
|
|
||||||
32
Scripts/Utils/MathFunctions.cs
Normal file
32
Scripts/Utils/MathFunctions.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Cirno.Scripts.Utils;
|
||||||
|
|
||||||
|
public static class MathFunctions
|
||||||
|
{
|
||||||
|
public static Vector2? PredictInterceptPosition(Vector2 shooterPos, Vector2 targetPos, Vector2 targetVel, float projectileSpeed)
|
||||||
|
{
|
||||||
|
Vector2 displacement = targetPos - shooterPos;
|
||||||
|
float a = targetVel.LengthSquared() - projectileSpeed * projectileSpeed;
|
||||||
|
float b = 2 * displacement.Dot(targetVel);
|
||||||
|
float c = displacement.LengthSquared();
|
||||||
|
|
||||||
|
float discriminant = b * b - 4 * a * c;
|
||||||
|
|
||||||
|
if (discriminant < 0 || Mathf.Abs(a) < 0.001f)
|
||||||
|
return null; // No solution or projectile too slow
|
||||||
|
|
||||||
|
float sqrtDisc = Mathf.Sqrt(discriminant);
|
||||||
|
float t1 = (-b - sqrtDisc) / (2 * a);
|
||||||
|
float t2 = (-b + sqrtDisc) / (2 * a);
|
||||||
|
|
||||||
|
float t = Mathf.Min(t1, t2);
|
||||||
|
if (t < 0)
|
||||||
|
t = Mathf.Max(t1, t2);
|
||||||
|
|
||||||
|
if (t < 0)
|
||||||
|
return null; // No valid positive time
|
||||||
|
|
||||||
|
return targetPos + targetVel * t;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue