Add PhantomCamera components and UI elements for improved scene management; refactor existing components for better integration

This commit is contained in:
2025-08-26 19:48:48 +02:00
parent cea3956fbb
commit 4c15f50f6e
65 changed files with 2654 additions and 61 deletions

View File

@@ -1,4 +1,5 @@
using Godot;
using PhantomCamera;
namespace Mr.BrickAdventures.scripts.components;
@@ -6,7 +7,6 @@ public partial class ChaseLevelComponent : Node
{
[Export] public float ChaseSpeed { get; set; } = 200.0f;
[Export] public Marker2D ChaseTarget { get; set; }
[Export] public GodotObject PhantomCamera { get; set; }
[Export] public float MinimumDistance { get; set; } = 10f;
[Signal]
@@ -17,8 +17,17 @@ public partial class ChaseLevelComponent : Node
private bool _isChasing = false;
private Node2D _previousCameraFollowTarget = null;
private PhantomCamera2D _phantomCamera = null;
private Node2D _root = null;
public override void _Process(double delta)
public override void _Ready()
{
_phantomCamera = GetNode<Node2D>("../../%PhantomCamera").AsPhantomCamera2D();
_root = Owner as Node2D;
}
public override void _PhysicsProcess(double delta)
{
if (!_isChasing) return;
if (ChaseTarget == null) return;
@@ -31,21 +40,22 @@ public partial class ChaseLevelComponent : Node
var targetPosition = ChaseTarget.GlobalPosition;
if (Owner is not Node2D root) return;
if (_root == null) return;
var direction = (targetPosition - root.GlobalPosition).Normalized();
root.GlobalPosition += direction * ChaseSpeed * (float)delta;
var direction = (targetPosition - _root.GlobalPosition).Normalized();
var speed = direction * ChaseSpeed * (float)delta;
_root.GlobalPosition += speed;
}
public void OnShipEntered()
{
if (ChaseTarget == null || PhantomCamera == null)
if (ChaseTarget == null || _phantomCamera == null)
return;
if (_isChasing) return;
_previousCameraFollowTarget = (Node2D)PhantomCamera.Call("get_follow_target");
PhantomCamera.Call("set_follow_target", Owner as Node2D);
_previousCameraFollowTarget = _phantomCamera.FollowTarget;
_phantomCamera.FollowTarget = _root;
EmitSignalChaseStarted();
_isChasing = true;
}
@@ -70,9 +80,9 @@ public partial class ChaseLevelComponent : Node
private void StopChasing()
{
if (PhantomCamera == null) return;
if (_phantomCamera == null) return;
PhantomCamera.Call("set_follow_target", _previousCameraFollowTarget);
_phantomCamera.FollowTarget = _previousCameraFollowTarget;
EmitSignalChaseStopped();
_isChasing = false;
}

View File

@@ -28,7 +28,7 @@ public partial class EnemyDeathComponent : Node
private void OnDeath()
{
CallDeferred(nameof(Die));
_ = Die();
}
private async Task Die()

View File

@@ -30,11 +30,10 @@ public partial class FlashingComponent : Node
public void StartFlashing()
{
if (Sprite == null) return;
_tween?.Kill();
if (_tween != null && _tween.IsRunning()) return;
_tween = CreateTween();
_tween.SetParallel(true);
_tween.SetParallel(false);
var flashes = (int)(FlashDuration / FlashTime);
for (var i = 0; i < flashes; i++)

View File

@@ -123,7 +123,8 @@ public partial class PlatformMovementComponent : Node2D, IMovement
Body.Velocity = new Vector2(direction * Speed, Body.Velocity.Y);
else
Body.Velocity = new Vector2(Mathf.MoveToward(Body.Velocity.X, 0, Speed), Body.Velocity.Y);
PreviousVelocity = Body.Velocity;
Body.MoveAndSlide();
}

View File

@@ -31,7 +31,6 @@ public partial class PlayerDeathComponent : Node2D
}
_gameManager.RemoveLives(1);
GD.Print("Player death, lives left: " + _gameManager.GetLives());
_gameManager.ResetCurrentSessionState();
}
}

View File

@@ -10,7 +10,7 @@ public partial class ShipShooterComponent : Node
[Export] public Marker2D BulletSpawn { get; set; }
[Export] public AudioStreamPlayer2D ShootSfx { get; set; }
private bool _canShoot = false;
private bool _canShoot = true;
public override void _Ready()
{

View File

@@ -2,20 +2,19 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
public partial class SpaceshipEnterComponent : Node
public partial class SpaceshipEnterComponent : Area2D
{
[Export] public Area2D Area { get; set; }
[Signal] public delegate void SpaceshipEnteredEventHandler();
public override void _Ready()
{
Area.BodyEntered += OnBodyEntered;
BodyEntered += OnBodyEntered;
}
private void OnBodyEntered(Node2D body)
{
if (body is not PlayerController) return;
EmitSignalSpaceshipEntered();
Owner.QueueFree();
QueueFree();
}
}

View File

@@ -2,14 +2,13 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
public partial class SpaceshipExitComponent : Node
public partial class SpaceshipExitComponent : Area2D
{
[Export] public Area2D Area { get; set; }
[Signal] public delegate void SpaceshipExitEventHandler();
public override void _Ready()
{
Area.BodyEntered += OnBodyEntered;
BodyEntered += OnBodyEntered;
}
private void OnBodyEntered(Node2D body)