A PowerUpEffect that applies a timed PaddleExpandEffect to a paddle, increasing its width for a duration. It checks paddle validity and asks the game (if present) for permission via TryApplyPaddleExpand before creating and configuring the effect component.
using Sandbox;
namespace Breakout;
/// <summary>
/// Pickup effect that adds a timed PaddleExpandEffect to the paddle, making it wider. In Weekly
/// mode the game can refuse it once the per-board cap on expands has been reached.
/// </summary>
[Title( "Paddle Expand Power Up" ), Category( "Breakout" ), Icon( "open_in_full" )]
public sealed class PaddleExpandPowerUp : PowerUpEffect
{
[Property] public float Multiplier { get; set; } = 1.6f;
[Property] public float Duration { get; set; } = 8f;
/// <summary>
/// Adds a timed wide-paddle effect, unless Weekly mode has already hit its per-board cap on expands.
/// </summary>
public override void Apply( BreakoutGame game, Paddle paddle )
{
if ( !paddle.IsValid() )
return;
if ( game is not null && !game.TryApplyPaddleExpand() )
return;
var effect = paddle.Components.Create<PaddleExpandEffect>();
effect.Multiplier = Multiplier;
effect.Duration = Duration;
}
public override string Label => "WIDE PADDLE";
public override Color LabelColor => new Color( 0.42f, 0.9f, 0.5f );
}