* Add GridMovementAbility and PacXonGridInteractor for grid-based movement; integrate with PlayerController and PacXonLevel * Add GhostMovementComponent and PacXonTrailComponent; integrate ghost movement and trail features in PacXonLevel * Update main menu button focus and add new movement abilities; adjust player and ghost initialization in PacXonLevel
59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
using System.Linq;
|
|
using Godot;
|
|
using Mr.BrickAdventures.scripts.components;
|
|
|
|
namespace Mr.BrickAdventures.scripts;
|
|
|
|
[GlobalClass]
|
|
public partial class PacXonLevel : Node
|
|
{
|
|
[Export] public PlayerController Player { get; set; }
|
|
[Export] public PacXonGridManager GridManager { get; set; }
|
|
[Export] public Node GhostContainer { get; set; }
|
|
[Export] public Label PercentageLabel { get; set; }
|
|
|
|
private const float WinPercentage = 0.90f;
|
|
|
|
public override void _Ready()
|
|
{
|
|
var ghosts = GhostContainer.GetChildren().OfType<Node2D>().ToList();
|
|
Player.ClearMovementAbilities();
|
|
Player.SetGridMovement();
|
|
|
|
foreach (var ghost in ghosts)
|
|
{
|
|
var movement = ghost.GetNode<GhostMovementComponent>("GhostMovementComponent");
|
|
movement?.Initialize(GridManager, Player);
|
|
}
|
|
|
|
var gridMovement = Player.GetNodeOrNull<GridMovementAbility>("Movements/GridMovementAbility");
|
|
var gridInteractor = Player.GetNodeOrNull<PacXonGridInteractor>("PacXonGridInteractor");
|
|
var trailComponent = Player.GetNodeOrNull<PacXonTrailComponent>("PacXonTrailComponent");
|
|
|
|
if (gridMovement != null && gridInteractor != null)
|
|
{
|
|
gridInteractor.Initialize(GridManager, gridMovement, ghosts);
|
|
trailComponent?.Initialize(gridInteractor);
|
|
}
|
|
else
|
|
{
|
|
GD.PushError("Could not find GridMovementAbility or PacXonGridInteractor on Player.");
|
|
}
|
|
|
|
GridManager.FillPercentageChanged += OnFillPercentageChanged;
|
|
OnFillPercentageChanged(GridManager.GetFillPercentage());
|
|
|
|
var playerMapPos = GridManager.LocalToMap(Player.Position);
|
|
Player.GlobalPosition = GridManager.MapToLocal(playerMapPos);
|
|
}
|
|
|
|
private void OnFillPercentageChanged(float percentage)
|
|
{
|
|
PercentageLabel.Text = $"Fill: {percentage:P0}";
|
|
if (percentage >= WinPercentage)
|
|
{
|
|
GD.Print("YOU WIN!");
|
|
GetTree().Paused = true;
|
|
}
|
|
}
|
|
} |