Plunger
namespace Griff.Modules.PhysicsGames;
public sealed class Plunger : Component, IDrawable, IPlaytestReport, IActionReadyA pinball plunger, with no code: the ball rests on its tip; hold its button to pull it back (the longer, the further, up to all the way in PullTime seconds) and let go to shoot the ball up the lane, the harder the further it was pulled. A gamepad’s right stick pulls it back as far as it’s pushed down, and letting the stick go shoots. It draws itself: a knob on a rod, and a spring that squeezes up as it’s pulled.
Its position is the top of its tip, where the ball rests: give it a solid collider there (Entity > Genres > Physics Games > Plunger does). Its Action is Plunger (Space, the down arrow, the gamepad’s A); the mouse or a finger held down on it pulls it too. Its Launch action shoots at full power with nobody pulling it (an auto-plunger, or a kickback a Trigger fires); a Drain serves the next ball onto it.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”Action
Section titled “Action”public string? Action { get; set; }The input action held to pull it back: “Plunger” is Space, the down arrow or the gamepad’s A.
Analog
Section titled “Analog”public bool Analog { get; set; }A gamepad’s right stick pushed down pulls it back as far as it’s pushed, and shoots as it’s let go.
public Color Color { get; set; }The color of its knob and rod.
Controllable
Section titled “Controllable”public bool Controllable { get; set; }Untick it to have it ignore the keys, mouse and gamepad (its Launch action and scripts still work). Its Focus action ticks it and unticks it on everything else the player plays.
Direction
Section titled “Direction”public Vector2 Direction { get; set; }Which way it shoots, in its own space (turned with it): (0, 1) is up.
GrabRadius
Section titled “GrabRadius”public float GrabRadius { get; set; }The mouse button or a finger held down within this of its tip pulls it, and letting go shoots (a finger on it while another holds a flipper up, too).
LaunchIn
Section titled “LaunchIn”public float LaunchIn { get; set; }Seconds until it shoots by itself at full power (a ball saved, put back on it); 0 when it won’t. Set by the game.
LaunchMessage
Section titled “LaunchMessage”public string? LaunchMessage { get; set; }A message sent as it shoots a ball, with the ball as its data, e.g. “Launched”.
LaunchSound
Section titled “LaunchSound”public string? LaunchSound { get; set; }A sound played as it shoots, e.g. “Sounds/launch.wav”.
Launches
Section titled “Launches”public int Launches { get; set; }How many balls it has shot.
Layers
Section titled “Layers”public string? Layers { get; set; }The collision layers it shoots, e.g. “Ball”. Empty shoots any body resting on it.
Length
Section titled “Length”public float Length { get; set; }How long its rod and spring are below its tip, in world units.
Loaded
Section titled “Loaded”public bool Loaded { get; set; }True while a ball rests on its tip, ready to shoot. Set by the game.
MinPower
Section titled “MinPower”public float MinPower { get; set; }How fast the ball leaves however little it was pulled, so a tap still sends it a little way.
public float Power { get; set; }How fast the ball leaves when it’s pulled all the way back, in world units a second; less the less it’s pulled.
public float Pull { get; set; }How far it’s pulled back, from 0 (resting) to 1 (all the way). Set by the game as it’s pulled.
PullSound
Section titled “PullSound”public string? PullSound { get; set; }A sound played as it starts being pulled back, e.g. “Sounds/spring.wav”.
PullTime
Section titled “PullTime”public float PullTime { get; set; }Seconds its button is held to pull it all the way back.
Pulling
Section titled “Pulling”public bool Pulling { get; set; }True while it’s being pulled back by the keys, the mouse or a finger. Set by the game.
SpringColor
Section titled “SpringColor”public Color SpringColor { get; set; }The color of its spring.
public Vector2 Tip { get; }Where its tip is in the world: its position, where a ball rests.
Travel
Section titled “Travel”public float Travel { get; set; }How far its knob goes down as it’s pulled all the way back, in world units.
public float Width { get; set; }How wide its knob is, in world units.
WorldDirection
Section titled “WorldDirection”public Vector2 WorldDirection { get; }The way it shoots in the world (its Direction turned with it).
Methods
Section titled “Methods”Launch
Section titled “Launch”public void Launch()Shoots whatever rests on it at full power, with nobody pulling it: an auto-plunger, a kickback.
SpeedFor
Section titled “SpeedFor”public float SpeedFor(float pull)How fast a ball leaves pulled back pull (0 to 1): from its Min Power up to its Power.
public override bool Uses(string property)Events
Section titled “Events”Launched
Section titled “Launched”public event Action<Plunger, Entity>? LaunchedRaised as it shoots a ball, with the ball.