Skip to content

Plunger

namespace Griff.Modules.PhysicsGames;
public sealed class Plunger : Component, IDrawable, IPlaytestReport, IActionReady

A 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.

public string? Action { get; set; }

The input action held to pull it back: “Plunger” is Space, the down arrow or the gamepad’s A.

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.

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.

public Vector2 Direction { get; set; }

Which way it shoots, in its own space (turned with it): (0, 1) is up.

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).

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.

public string? LaunchMessage { get; set; }

A message sent as it shoots a ball, with the ball as its data, e.g. “Launched”.

public string? LaunchSound { get; set; }

A sound played as it shoots, e.g. “Sounds/launch.wav”.

public int Launches { get; set; }

How many balls it has shot.

public string? Layers { get; set; }

The collision layers it shoots, e.g. “Ball”. Empty shoots any body resting on it.

public float Length { get; set; }

How long its rod and spring are below its tip, in world units.

public bool Loaded { get; set; }

True while a ball rests on its tip, ready to shoot. Set by the game.

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.

public string? PullSound { get; set; }

A sound played as it starts being pulled back, e.g. “Sounds/spring.wav”.

public float PullTime { get; set; }

Seconds its button is held to pull it all the way back.

public bool Pulling { get; set; }

True while it’s being pulled back by the keys, the mouse or a finger. Set by the game.

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.

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.

public Vector2 WorldDirection { get; }

The way it shoots in the world (its Direction turned with it).

public void Launch()

Shoots whatever rests on it at full power, with nobody pulling it: an auto-plunger, a kickback.

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)
public event Action<Plunger, Entity>? Launched

Raised as it shoots a ball, with the ball.