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

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