* Implement BeamComponent in C# and enhance marketplace button functionality * Add core game components including ConfigFileHandler, GameManager, SaveSystem, and UIManager * cleanup * Add new components: CanPickUpComponent, CollapsableComponent, DestroyableComponent, EffectInflictorComponent, StatusEffectComponent, and StatusEffectDataResource * Add new components: EnemyDeathComponent, EnemyWaveTriggerComponent, and ExitDoorComponent * Add new components: ExplosiveComponent, FadeAwayComponent, FireEffectComponent, FlipComponent, GravityMotionComponent, LaunchComponent, and update PlatformMovement with LastDirection property * Add new components: HealComponent, HitComponent, HomingMissileMotionComponent, LeverComponent, and TriggerLeverComponent * Refactor GameManager session state handling and add new components: CanBeLaunchedComponent, IceEffectComponent, JumpPadComponent, KillPlayerOutOfScreenComponent, KnockbackComponent, LifetimeComponent, MagneticSkillComponent, OutOfScreenComponent, PeriodicShootingComponent, PlayerDeathComponent, ProgressiveDamageComponent, ProjectileComponent, ProjectileInitComponent, RequirementComponent, ScoreComponent, ShipMovementComponent, ShipShooterComponent, and SideToSideMovementComponent * Add new components: CannotStompComponent, SkillUnlockedComponent, SpaceshipEnterComponent, SpaceshipExitComponent, SpinComponent, StompDamageComponent, StraightMotionComponent, TerrainHitFx, TooltipComponent, TrailComponent, and UnlockOnRequirementComponent * Add new components: BrickThrowComponent, BulletComponent, CageComponent, ChaseLevelComponent, CleanupComponent, and ThrowInputResource classes; implement game saving and loading logic in SaveSystem * Add audio settings management and platform movement component * Add ChargeProgressBar, Credits, and GameOverScreen components for UI management * Add UID files for ConfigFileHandler, GameManager, SaveSystem, and UIManager components * Add README.md file with game description and features; include project license and contribution guidelines * Add Hud component for UI management; display health, coins, and lives * Add MainMenu and Marketplace components; implement game management and skill unlocking features * Add PauseMenu, SettingsMenu, and SkillButton components; enhance game management and UI functionality
103 lines
2.7 KiB
C#
103 lines
2.7 KiB
C#
using System.Collections.Generic;
|
|
using Godot;
|
|
using Mr.BrickAdventures.scripts.interfaces;
|
|
|
|
namespace Mr.BrickAdventures.scripts.components;
|
|
|
|
public partial class PlayerController : Node2D
|
|
{
|
|
[Export]
|
|
public string DefaultMovementType { get; set; } = "platform";
|
|
|
|
[Export]
|
|
public Godot.Collections.Dictionary<string, NodePath> MovementTypes { get; set; }
|
|
|
|
[Export]
|
|
public Sprite2D ShipSprite { get; set; }
|
|
|
|
public IMovement CurrentMovement = null;
|
|
[Signal]
|
|
public delegate void MovementSwitchedEventHandler(string movementType);
|
|
|
|
public override void _Ready()
|
|
{
|
|
base._Ready();
|
|
|
|
foreach (var movementType in MovementTypes.Keys)
|
|
{
|
|
var movementNode = GetNodeOrNull(movementType);
|
|
if (movementNode is IMovement playerMovement)
|
|
{
|
|
playerMovement.Enabled = false;
|
|
}
|
|
}
|
|
|
|
SwitchMovement(DefaultMovementType);
|
|
}
|
|
|
|
public override void _UnhandledInput(InputEvent @event)
|
|
{
|
|
base._UnhandledInput(@event);
|
|
|
|
if (@event is InputEventKey inputEventKey && inputEventKey.IsActionPressed("switch_movement"))
|
|
{
|
|
var nextMovementType = GetNextMovementType();
|
|
SwitchMovement(nextMovementType);
|
|
}
|
|
}
|
|
|
|
private void SwitchMovement(string movementType)
|
|
{
|
|
if (CurrentMovement != null)
|
|
{
|
|
CurrentMovement.Enabled = false;
|
|
}
|
|
|
|
if (MovementTypes.TryGetValue(movementType, out var movement))
|
|
{
|
|
CurrentMovement = GetNodeOrNull<IMovement>(movement);
|
|
if (CurrentMovement == null)
|
|
{
|
|
GD.PushError($"Movement type '{movementType}' not found in MovementTypes.");
|
|
return;
|
|
}
|
|
CurrentMovement.Enabled = true;
|
|
EmitSignalMovementSwitched(movementType);
|
|
}
|
|
else
|
|
{
|
|
GD.PushError($"Movement type '{movementType}' not found in MovementTypes.");
|
|
}
|
|
|
|
if (CurrentMovement == null)
|
|
{
|
|
GD.PushError("No current movement set after switching.");
|
|
}
|
|
}
|
|
|
|
private string GetNextMovementType()
|
|
{
|
|
var keys = new List<string>(MovementTypes.Keys);
|
|
var currentIndex = keys.IndexOf(CurrentMovement?.MovementType);
|
|
|
|
if (currentIndex == -1)
|
|
{
|
|
return DefaultMovementType;
|
|
}
|
|
|
|
currentIndex = (currentIndex + 1) % keys.Count;
|
|
return keys[currentIndex];
|
|
}
|
|
|
|
public void OnSpaceshipEntered()
|
|
{
|
|
SwitchMovement("ship");
|
|
ShipSprite.Visible = true;
|
|
}
|
|
|
|
public void OnSpaceshipExited()
|
|
{
|
|
SwitchMovement(DefaultMovementType);
|
|
ShipSprite.Visible = false;
|
|
}
|
|
} |