Gamemanager in bullet

This commit is contained in:
MaddoScientisto 2025-02-13 21:55:14 +01:00
commit 1ee8f085e8
6 changed files with 92 additions and 13 deletions

View file

@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="BossPhase" load_steps=15 format=3 uid="uid://ddb5dqocmk6x7"] [gd_resource type="Resource" script_class="BossPhase" load_steps=25 format=3 uid="uid://ddb5dqocmk6x7"]
[ext_resource type="PackedScene" uid="uid://dh81snen2f6bf" path="res://Scenes/Weapons/Bullets/enemyBullet_rice_blue_small.tscn" id="1_as8n2"] [ext_resource type="PackedScene" uid="uid://dh81snen2f6bf" path="res://Scenes/Weapons/Bullets/enemyBullet_rice_blue_small.tscn" id="1_as8n2"]
[ext_resource type="Script" path="res://Scripts/Resources/BossPhase.cs" id="1_fdlxv"] [ext_resource type="Script" path="res://Scripts/Resources/BossPhase.cs" id="1_fdlxv"]
@ -6,6 +6,9 @@
[ext_resource type="Script" path="res://Scripts/AttackPatterns/SpiralPattern.cs" id="2_wkmhk"] [ext_resource type="Script" path="res://Scripts/AttackPatterns/SpiralPattern.cs" id="2_wkmhk"]
[ext_resource type="PackedScene" uid="uid://ctrk5qrb7n3fm" path="res://Scenes/Weapons/Bullets/enemyBullet_rice_green_small.tscn" id="4_tek7n"] [ext_resource type="PackedScene" uid="uid://ctrk5qrb7n3fm" path="res://Scenes/Weapons/Bullets/enemyBullet_rice_green_small.tscn" id="4_tek7n"]
[ext_resource type="PackedScene" uid="uid://chowj81jsdvcx" path="res://Scenes/Weapons/Bullets/enemyBullet_rice_red_small.tscn" id="5_n4xqo"] [ext_resource type="PackedScene" uid="uid://chowj81jsdvcx" path="res://Scenes/Weapons/Bullets/enemyBullet_rice_red_small.tscn" id="5_n4xqo"]
[ext_resource type="Script" path="res://Scripts/Resources/SimpleMovementPattern.cs" id="6_bw7cj"]
[ext_resource type="PackedScene" uid="uid://dohakkayqj4w2" path="res://Scenes/Weapons/Bullets/enemyBullet_green.tscn" id="7_gsnyb"]
[ext_resource type="Script" path="res://Scripts/Resources/SpeedModifier.cs" id="8_6ya1v"]
[sub_resource type="Resource" id="Resource_17kqi"] [sub_resource type="Resource" id="Resource_17kqi"]
script = ExtResource("2_kghxb") script = ExtResource("2_kghxb")
@ -121,9 +124,81 @@ _timeModifiers = Array[Resource]([SubResource("Resource_sk6w4")])
_targetPlayer = false _targetPlayer = false
WaitForCompletion = true WaitForCompletion = true
[sub_resource type="Resource" id="Resource_erexw"]
script = ExtResource("6_bw7cj")
relativeTargetPosition = Vector2(50, 5)
moveDuration = 2.0
transitionType = 0
easeType = 2
WaitForCompletion = true
[sub_resource type="Resource" id="Resource_80ngy"]
script = ExtResource("8_6ya1v")
ModifierType = 1
Easing = 0
Invert = true
MinimumSpeed = 10.0
ScalingFactor = 10.0
[sub_resource type="Resource" id="Resource_hutbf"]
script = ExtResource("2_kghxb")
TimeInSeconds = 0.5
ModifierType = 2
Value = 0.0
[sub_resource type="Resource" id="Resource_krtsy"]
script = ExtResource("2_kghxb")
TimeInSeconds = 0.8
ModifierType = 0
Value = 50.0
[sub_resource type="Resource" id="Resource_mpjrl"]
script = ExtResource("2_wkmhk")
BulletScene = ExtResource("7_gsnyb")
bulletSpeed = 80.0
bulletCount = 12
rotationSpeed = 0.0
_rotationOffset = 45.0
duration = 1.0
burstInterval = 1.0
spread = 180.0
owner = 2
_damageType = 0
_bulletDamage = 1.0
_modifier = SubResource("Resource_80ngy")
_timeModifiers = Array[Resource]([SubResource("Resource_hutbf"), SubResource("Resource_krtsy")])
_targetPlayer = false
WaitForCompletion = true
[sub_resource type="Resource" id="Resource_l05f2"]
script = ExtResource("6_bw7cj")
relativeTargetPosition = Vector2(45, 0)
moveDuration = 0.4
transitionType = 0
easeType = 2
WaitForCompletion = true
[sub_resource type="Resource" id="Resource_ncfnl"]
script = ExtResource("2_wkmhk")
BulletScene = ExtResource("7_gsnyb")
bulletSpeed = 80.0
bulletCount = 12
rotationSpeed = 0.0
_rotationOffset = 45.0
duration = 1.0
burstInterval = 1.0
spread = 180.0
owner = 2
_damageType = 0
_bulletDamage = 1.0
_modifier = SubResource("Resource_80ngy")
_timeModifiers = Array[Resource]([SubResource("Resource_hutbf"), SubResource("Resource_krtsy")])
_targetPlayer = false
WaitForCompletion = true
[resource] [resource]
script = ExtResource("1_fdlxv") script = ExtResource("1_fdlxv")
PhaseName = "" PhaseName = ""
Threshold = 800 Threshold = 800
PlayAnimation = false PlayAnimation = false
Patterns = Array[Object]([SubResource("Resource_puvpt"), SubResource("Resource_44j24"), SubResource("Resource_wkxow"), SubResource("Resource_gcqck"), SubResource("Resource_bxbto"), SubResource("Resource_q48s1")]) Patterns = Array[Object]([SubResource("Resource_puvpt"), SubResource("Resource_44j24"), SubResource("Resource_wkxow"), SubResource("Resource_gcqck"), SubResource("Resource_bxbto"), SubResource("Resource_q48s1"), SubResource("Resource_erexw"), SubResource("Resource_mpjrl"), SubResource("Resource_l05f2"), SubResource("Resource_ncfnl")])

View file

@ -17,6 +17,8 @@ public partial class Barrel : Area2D, IDestructible
[Export] public PackedScene ExplosionParticles { get; set; } [Export] public PackedScene ExplosionParticles { get; set; }
[Export] public BulletResource ExplosionData { get; set; } [Export] public BulletResource ExplosionData { get; set; }
private GameManager _gameManager;
private float _currentHealth = 0f; private float _currentHealth = 0f;
private bool _isDestroyed = false; private bool _isDestroyed = false;
@ -24,6 +26,7 @@ public partial class Barrel : Area2D, IDestructible
// Called when the node enters the scene tree for the first time. // Called when the node enters the scene tree for the first time.
public override void _Ready() public override void _Ready()
{ {
_gameManager = this.GetGameManager();
_currentHealth = Health; _currentHealth = Health;
} }
@ -48,7 +51,7 @@ public partial class Barrel : Area2D, IDestructible
var explosion = this.CreateSibling<Bullet>(ExplosionData.BulletScene); var explosion = this.CreateSibling<Bullet>(ExplosionData.BulletScene);
explosion.Speed = 0; explosion.Speed = 0;
explosion.Initialize(ExplosionData.MakeBullet(this.GlobalPosition)); explosion.Initialize(ExplosionData.MakeBullet(this.GlobalPosition), _gameManager);
} }
private void ApplyExplosionDamage() private void ApplyExplosionDamage()

View file

@ -27,10 +27,14 @@ public partial class Bullet : Area2D
private List<ModifierWrapper> _modifiers = new(); private List<ModifierWrapper> _modifiers = new();
public void Initialize(BulletInfo bulletInfo) private GameManager _gameManager;
public void Initialize(BulletInfo bulletInfo, GameManager gameManager)
{ {
_bulletInfo = bulletInfo; _bulletInfo = bulletInfo;
_gameManager = gameManager;
// Ugly hack to make instances unique // Ugly hack to make instances unique
_modifiers = _bulletInfo.TimeModifiers.Select(x => new ModifierWrapper() _modifiers = _bulletInfo.TimeModifiers.Select(x => new ModifierWrapper()
{ {
@ -79,14 +83,11 @@ public partial class Bullet : Area2D
//Rotation = radians; //Rotation = radians;
} }
private void FacePlayer() private void FacePlayer()
{ {
// TODO: cache player if (_gameManager.Player != null)
var player = GetTree().GetFirstNodeInGroup("Player") as Node2D;
if (player != null)
{ {
_direction = (player.GlobalPosition - this.GlobalPosition).Normalized(); _direction = (_gameManager.Player.GlobalPosition - this.GlobalPosition).Normalized();
//LookAt(player.GlobalPosition); //LookAt(player.GlobalPosition);
} }
} }

View file

@ -22,7 +22,7 @@ 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); bullet.Initialize(bulletInfo, _gameManager);
float modifiedSpeed = bulletInfo.Modifier?.ModifySpeed(bulletInfo.Speed, i, bulletInfo.BulletCount) ?? bulletInfo.Speed; float modifiedSpeed = bulletInfo.Modifier?.ModifySpeed(bulletInfo.Speed, i, bulletInfo.BulletCount) ?? bulletInfo.Speed;
bullet.Speed = modifiedSpeed; bullet.Speed = modifiedSpeed;
@ -37,7 +37,6 @@ public partial class BulletSpawner : Node2D
Vector2 bulletDirection = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)); Vector2 bulletDirection = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
bullet.SetDirection(bulletDirection); bullet.SetDirection(bulletDirection);
} }
} }

View file

@ -64,7 +64,8 @@ public static class Tools
public static GameManager GetGameManager(this Node2D node) public static GameManager GetGameManager(this Node2D node)
{ {
return node.GetNode<GameManager>("/root/GameScene"); return node.GetTree().Root.GetNode<GameManager>("GameScene");
// node.GetNode<GameManager>("/root/GameScene");
} }
public static AlarmManager GetAlarmManager(this Node2D node) public static AlarmManager GetAlarmManager(this Node2D node)

View file

@ -107,7 +107,7 @@ public partial class Weapon : Node2D
return; return;
}; };
bullet.Initialize(WeaponData.MakeBullet(_muzzle.GlobalPosition)); bullet.Initialize(WeaponData.MakeBullet(_muzzle.GlobalPosition), _gameManager);
//bullet.SetDirection(ShootDirection); //bullet.SetDirection(ShootDirection);
bullet.SetDirection(spreadDirection); bullet.SetDirection(spreadDirection);