Add new skills: Double Jump, Ground Pound, Brick Armor, and Brick Shield; implement skill removal signal in SkillManager (#11)

This commit is contained in:
2025-08-31 15:17:11 +02:00
committed by GitHub
parent bd40c797d4
commit ead52f6d51
89 changed files with 682 additions and 7 deletions

View File

@@ -0,0 +1,48 @@
using Godot;
using Mr.BrickAdventures.scripts.interfaces;
using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class BrickArmorSkillComponent : Node, ISkill
{
private HealthComponent _healthComponent;
private SkillData _skillData;
private float _armorBonus = 0;
public void Initialize(Node owner, SkillData data)
{
if (owner is not PlayerController player) return;
_healthComponent = player.GetNode<HealthComponent>("HealthComponent");
_skillData = data;
}
public void Activate()
{
if (_healthComponent == null || _skillData == null) return;
ApplyUpgrade(_skillData.Upgrades[_skillData.Level - 1]);
}
public void Deactivate()
{
if (_healthComponent == null) return;
_healthComponent.MaxHealth -= _armorBonus;
if (_healthComponent.Health > _healthComponent.MaxHealth)
{
_healthComponent.SetHealth(_healthComponent.MaxHealth);
}
_armorBonus = 0;
}
public void ApplyUpgrade(SkillUpgrade upgrade)
{
if (_healthComponent == null || upgrade == null) return;
_healthComponent.MaxHealth -= _armorBonus;
_armorBonus = (float)upgrade.Properties["health_bonus"];
_healthComponent.MaxHealth += _armorBonus;
_healthComponent.IncreaseHealth(_armorBonus);
}
}

View File

@@ -0,0 +1 @@
uid://5fyepa666cc8

View File

@@ -0,0 +1,72 @@
using Godot;
using Mr.BrickAdventures.Autoloads;
using Mr.BrickAdventures.scripts.interfaces;
using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class BrickShieldSkillComponent : Node, ISkill
{
[Export] public PackedScene ShieldScene { get; set; }
private PlayerController _player;
private Node2D _shieldInstance;
private SkillData _skillData;
private GameManager _gameManager;
private SkillManager _skillManager;
private HealthComponent _shieldHealth;
public override void _Ready()
{
_gameManager = GetNode<GameManager>("/root/GameManager");
_skillManager = GetNode<SkillManager>("/root/SkillManager");
}
public void Initialize(Node owner, SkillData data)
{
_player = owner as PlayerController;
_skillData = data;
}
public void Activate()
{
if (_player == null || ShieldScene == null || _shieldInstance != null) return;
_shieldInstance = ShieldScene.Instantiate<Node2D>();
_player.AddChild(_shieldInstance);
_shieldInstance.Position = Vector2.Zero;
_shieldInstance.TreeExiting += OnShieldDestroyed;
_shieldHealth = _shieldInstance.GetNode<HealthComponent>("HealthComponent");
}
public void Deactivate()
{
if (_shieldInstance != null && IsInstanceValid(_shieldInstance))
{
_shieldInstance.TreeExiting -= OnShieldDestroyed;
_shieldInstance.QueueFree();
}
_shieldInstance = null;
}
public void ApplyUpgrade(SkillUpgrade upgrade)
{
upgrade.Properties.TryGetValue("shield_health", out var newHealth);
if (_shieldHealth != null)
{
_shieldHealth.Health = (float)newHealth;
_shieldHealth.MaxHealth = (float)newHealth;
}
}
private void OnShieldDestroyed()
{
if (_gameManager != null && _skillData != null && _skillManager != null)
{
_gameManager.RemoveSkill(_skillData.Name);
_skillManager.RemoveSkill(_skillData.Name);
}
_shieldInstance = null;
}
}

View File

@@ -0,0 +1 @@
uid://dbiu2qrr8sprx

View File

@@ -4,6 +4,7 @@ using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class BrickThrowComponent : Node, ISkill
{
[Export] public PackedScene BrickScene { get; set; }

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class BulletComponent : Node
{
[Export] public Area2D Area { get; set; }

View File

@@ -3,6 +3,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class CageComponent : Node
{
[Export] public LeverComponent Lever { get; set; }

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class CanBeLaunchedComponent : Node
{

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class CanPickUpComponent : Node
{

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class CannotStompComponent : Node
{

View File

@@ -3,6 +3,7 @@ using PhantomCamera;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class ChaseLevelComponent : Node
{
[Export] public float ChaseSpeed { get; set; } = 200.0f;

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class CleanupComponent : Node
{
public void CleanUp()

View File

@@ -3,6 +3,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class CollapsableComponent : Node
{
[Export] public Timer ToCollapseTimer { get; set; }

View File

@@ -4,6 +4,7 @@ using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class CollectableComponent : Node
{
private bool _hasFadeAway = false;

View File

@@ -3,6 +3,7 @@ using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class DamageComponent : Node
{
[Export] public float Damage { get; set; } = 0.25f;

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class DestroyableComponent : Node2D
{
[Export] public HealthComponent Health { get; set; }

View File

@@ -0,0 +1,45 @@
using System.Linq;
using Godot;
using Mr.BrickAdventures.scripts.interfaces;
using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class DoubleJumpSkillComponent : Node, ISkill
{
[Export] private PackedScene _doubleJumpAbilityScene;
private PlayerController _playerController;
public void Initialize(Node owner, SkillData data)
{
_playerController = owner as PlayerController;
if (_playerController == null)
{
GD.PrintErr("DoubleJumpSkillComponent must be a child of a PlayerController.");
}
}
public void Activate()
{
if (_playerController == null) return;
var hasAbility = _playerController.GetActiveAbilities().Any(ability => ability is DoubleJumpAbility);
if (!hasAbility)
{
var abilityInstance = _doubleJumpAbilityScene.Instantiate<DoubleJumpAbility>();
_playerController.AddAbility(abilityInstance);
}
}
public void Deactivate()
{
_playerController?.RemoveAbility<DoubleJumpAbility>();
}
public void ApplyUpgrade(SkillUpgrade upgrade)
{
}
}

View File

@@ -0,0 +1 @@
uid://c61jxwtgiuqsy

View File

@@ -3,6 +3,7 @@ using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class EffectInflictorComponent : Node
{
[Export] public DamageComponent Damage { get; set; }

View File

@@ -3,6 +3,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class EnemyDeathComponent : Node
{
[Export] public float TweenDuration { get; set; } = 0.5f;

View File

@@ -4,6 +4,7 @@ using Mr.BrickAdventures.scripts.interfaces;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class ExitDoorComponent : Area2D, IUnlockable
{
[Export] public bool Locked { get; set; } = true;

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class ExplosiveComponent : Node2D
{
[Export] public DamageComponent Damage { get; set; }

View File

@@ -3,6 +3,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class FadeAwayComponent : Node
{
[Export] public Sprite2D Sprite { get; set; }

View File

@@ -3,6 +3,7 @@ using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class FireEffectComponent : Node
{
[Export] public HealthComponent Health { get; set; }

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class FlashingComponent : Node
{
[Export] public Node2D Sprite { get; set; }

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class FlipComponent : Node2D
{
[Export] public Sprite2D LeftEye { get; set; }

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class GravityMotionComponent : Node2D
{
[Export] public CharacterBody2D Body { get; set; }

View File

@@ -0,0 +1,66 @@
using Godot;
using Mr.BrickAdventures.scripts.interfaces;
using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class GroundPoundSkillComponent : Node, ISkill
{
[Export] public float PoundForce { get; set; } = 1200f;
[Export] public PackedScene ShockwaveScene { get; set; }
private PlayerController _player;
private PlayerInputHandler _input;
private bool _isPounding = false;
public void Initialize(Node owner, SkillData data)
{
_player = owner as PlayerController;
if (_player != null)
{
_input = _player.GetNode<PlayerInputHandler>("PlayerInputHandler");
}
}
public override void _PhysicsProcess(double delta)
{
if (_player == null || _input == null)
{
return;
}
// Check if we just landed from a ground pound to create the shockwave.
if (_isPounding && _player.IsOnFloor())
{
_isPounding = false;
if (ShockwaveScene != null)
{
var shockwave = ShockwaveScene.Instantiate<Node2D>();
_player.GetParent()?.AddChild(shockwave);
shockwave.GlobalPosition = _player.GlobalPosition;
}
}
// Check to initiate a ground pound. The player must be in the air.
if (_input.DownHeld && !_player.IsOnFloor() && !_isPounding)
{
// Apply a strong downward force, zeroing out horizontal movement.
_player.Velocity = new Vector2(0, PoundForce);
_isPounding = true;
}
}
public void Activate()
{
SetPhysicsProcess(true);
}
public void Deactivate()
{
SetPhysicsProcess(false);
_isPounding = false;
}
public void ApplyUpgrade(SkillUpgrade upgrade) { }
}

View File

@@ -0,0 +1 @@
uid://3sclg5kdjg13

View File

@@ -3,6 +3,7 @@ using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class HealComponent : Node
{
[Export] public GpuParticles2D HealFx { get; set; }

View File

@@ -4,6 +4,7 @@ using Mr.BrickAdventures.Autoloads;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class HealthComponent : Node2D
{
[Export] public float Health { get; set; } = 1.0f;

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class HitComponent : Node
{
[Export] public Sprite2D Sprite { get; set; }

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class HomingMissileMotionComponent : Node
{
[Export] public LaunchComponent Launch { get; set; }

View File

@@ -4,6 +4,7 @@ using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class IceEffectComponent : Node
{
[Export] public Array<Node> ComponentsToDisable { get; set; } = [];

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class InvulnerabilityComponent : Node
{
[Export] public float Duration { get; set; } = 1f;

View File

@@ -3,6 +3,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class JumpPadComponent : Node
{
[Export] public float JumpForce { get; set; } = 10f;

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class KillPlayerOutOfScreenComponent : Node
{
[Export] public VisibleOnScreenNotifier2D ScreenNotifier { get; set; }

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class KnockbackComponent : Node
{
[Export] public CharacterBody2D Body { get; set; }

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class LaunchComponent : Node2D
{
[Export] public Vector2 InitialDirection { get; set; } = Vector2.Right;

View File

@@ -3,6 +3,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class LeverComponent : Node
{
[Export] public Area2D Area { get; set; }

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class LifetimeComponent : Node
{
[Export] public float LifeTime { get; set; } = 5.0f;

View File

@@ -6,6 +6,7 @@ using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class MagneticSkillComponent : Node, ISkill
{
[Export] public Area2D MagneticArea { get; set; }

View File

@@ -0,0 +1,46 @@
using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class DoubleJumpAbility : MovementAbility
{
private bool _hasDoubleJumped = false;
private float _jumpVelocity;
public override void Initialize(PlayerController controller)
{
base.Initialize(controller);
foreach (var ability in _controller.GetActiveAbilities())
{
if (ability is VariableJumpAbility jumpAbility)
{
_jumpVelocity = (2.0f * jumpAbility.JumpHeight) / jumpAbility.JumpTimeToPeak * -1.0f;
break;
}
}
if (_jumpVelocity == 0)
{
_jumpVelocity = -400.0f;
}
}
public override Vector2 ProcessMovement(Vector2 velocity, double delta)
{
if (_body.IsOnFloor())
{
_hasDoubleJumped = false;
}
if (_input.JumpPressed && !_body.IsOnFloor() && !_hasDoubleJumped)
{
velocity.Y = _jumpVelocity;
_controller.EmitSignal(PlayerController.SignalName.JumpInitiated);
_hasDoubleJumped = true;
}
return velocity;
}
}

View File

@@ -0,0 +1 @@
uid://xc0j26e88np7

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class OutOfScreenComponent : Node
{
[Export] public VisibleOnScreenNotifier2D VisibilityNotifier { get; set; }

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class PeriodicShootingComponent : Node
{
[Export] public PackedScene BulletScene { get; set; }

View File

@@ -3,6 +3,7 @@ using Mr.BrickAdventures.Autoloads;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class PlayerDeathComponent : Node2D
{
[Export] public AudioStreamPlayer2D DeathSfx { get; set; }

View File

@@ -10,6 +10,7 @@ public class ProjectileInitParams
public float PowerMultiplier { get; set; } = 1f;
}
[GlobalClass]
public partial class ProjectileInitComponent : Node
{
[Export] public LaunchComponent LaunchComponent { get; set; }

View File

@@ -3,6 +3,7 @@ using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class RequirementComponent : Node
{
[Export] public CollectableType RequirementType { get; set; }

View File

@@ -4,6 +4,7 @@ using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class ScoreComponent : Node
{
private GameManager _gameManager;

View File

@@ -3,6 +3,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class ShipShooterComponent : Node
{
[Export] public PackedScene BulletScene { get; set; }

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class SideToSideMovementComponent : Node
{
[Export] public Sprite2D Sprite { get; set; }

View File

@@ -6,6 +6,7 @@ using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class SkillUnlockerComponent : Node
{
public SkillManager SkillManager { get; private set; }

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class SpaceshipEnterComponent : Area2D
{
[Signal] public delegate void SpaceshipEnteredEventHandler();

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class SpaceshipExitComponent : Area2D
{
[Signal] public delegate void SpaceshipExitEventHandler();

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class SpinComponent : Node
{
[Export] public float SpinSpeed { get; set; } = 8f;

View File

@@ -11,6 +11,7 @@ public partial class StatusEffect : GodotObject
public Timer Timer { get; set; }
}
[GlobalClass]
public partial class StatusEffectComponent : Node
{
private List<StatusEffect> _activeEffects = [];

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class StompDamageComponent : Node
{
[Export] public float Damage { get; set; } = 0.25f;

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class StraightMotionComponent : Node
{
[Export] public LaunchComponent LaunchComponent { get; set; }

View File

@@ -5,6 +5,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class TerrainHitFx : Node
{
private List<GpuParticles2D> _gpuParticles = [];

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class TooltipComponent : Area2D
{
[Export] public Control UiRoot { get; set; }

View File

@@ -3,6 +3,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class TrailComponent : Line2D
{
[Export] public int MaxPoints { get; set; } = 100;

View File

@@ -2,6 +2,7 @@ using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class TriggerLeverComponent : Node
{

View File

@@ -4,6 +4,7 @@ using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class UnlockOnRequirementComponent : Node
{
[Export] public RequirementComponent RequirementComponent { get; set; }

View File

@@ -0,0 +1,51 @@
using Godot;
using Mr.BrickAdventures.scripts.interfaces;
using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class XRayVisionSkillComponent : Node, ISkill
{
[Export(PropertyHint.Layers2DRender)] public uint SecretLayer { get; set; }
[Export] public float Duration { get; set; } = 5.0f;
private Camera2D _camera;
private Viewport _viewport;
private uint _originalVisibilityLayer;
private Timer _timer;
public void Initialize(Node owner, SkillData data)
{
_viewport = GetViewport();
_camera = GetViewport().GetCamera2D();
_timer = new Timer { OneShot = true };
AddChild(_timer);
_timer.Timeout += Deactivate;
}
public void Activate()
{
if (_camera == null) return;
_originalVisibilityLayer = _camera.VisibilityLayer;
_camera.VisibilityLayer |= SecretLayer;
_timer.Start(Duration);
}
public void Deactivate()
{
if (_camera != null)
{
_camera.VisibilityLayer = _originalVisibilityLayer;
}
}
public void ApplyUpgrade(SkillUpgrade upgrade)
{
if (upgrade.Properties.TryGetValue("duration", out var newDuration))
{
Duration = (float)newDuration;
}
}
}

View File

@@ -0,0 +1 @@
uid://dl7vthhurirwc