Plunger
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.
Part of the Physics Games module: Physics puzzlers: a Slingshot to pull back and launch shots from, and Breakable things (planks, panes, blocks, pigs) that crack and break on hard knocks; a LevelGoal that wins a level once its targets are down (with a bonus for the shots left, and one to three stars) or loses it once the shots run out; a Slingshot and a Tower to make from the Entity menu (Genres, Physics Games); and the Physics template, levels of wood, glass and stone to knock down.
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.
Requires: Collider (its tip, where the ball rests)
Works with: Drain (serves each new ball onto it); TurnTaker (its side: pulled on its side’s turn)
Takes the player’s input only while it has focus (its Controllable): its Focus action hands it the input and takes it from everything else the same player plays.
Draws itself (its entity draws at Order 0 unless it has a Sprite, whose order counts).
Properties
Section titled “Properties”Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.
power: a number = 36. How fast the ball leaves when it’s pulled all the way back, in world units a second; less the less it’s pulled. (Field: a number.)minPower: a number = 6. How fast the ball leaves however little it was pulled, so a tap still sends it a little way. (Field: a number.)pullTime: a number = 1. Seconds its button is held to pull it all the way back. (Field: a number.)direction: [x, y] = [0,1]. Which way it shoots, in its own space (turned with it): (0, 1) is up. (A direction, x right and y up: [0, 1] is up, [1, 0] right, [1, 1] up and to the right, in its own space (turned with the entity). The Inspector has a compass of the eight ways; with Distance Handles the Scene view draws it as an arrow to drag round.) (Field: its own editor: Direction.)layers: text = null. The collision layers it shoots, e.g. “Ball”. Empty shoots any body resting on it. (Names collision layers: their names, separated by commas.) (Field: a name.)
Controls
Section titled “Controls”action: text = “Plunger”. The input action held to pull it back: “Plunger” is Space, the down arrow or the gamepad’s A. (Names an input action.) (Field: a name.)analog: true or false = true. A gamepad’s right stick pushed down pulls it back as far as it’s pushed, and shoots as it’s let go. (Field: on or off.)grabRadius: a number = 1.2. 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). (Field: a number.)controllable: true or false = true. 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. (Field: on or off.)
travel: a number = 0.9. How far its knob goes down as it’s pulled all the way back, in world units. (Field: a number.)length: a number = 1.6. How long its rod and spring are below its tip, in world units. (Field: a number.)width: a number = 0.55. How wide its knob is, in world units. (Field: a number.)color: a color, “#RRGGBB” or “#RRGGBBAA” = “#C83C3CFF”. The color of its knob and rod. (Field: a color.)springColor: a color, “#RRGGBB” or “#RRGGBBAA” = “#C8CCD4FF”. The color of its spring. (Field: a color.)
Sound and Messages
Section titled “Sound and Messages”pullSound: text = null. A sound played as it starts being pulled back, e.g. “Sounds/spring.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)launchSound: text = null. A sound played as it shoots, e.g. “Sounds/launch.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)launchMessage: text = null. A message sent as it shoots a ball, with the ball as its data, e.g. “Launched”. (Names a message.) (Field: a name.)
pull: a number = 0. How far it’s pulled back, from 0 (resting) to 1 (all the way). Set by the game as it’s pulled. (Field: a number.)pulling: true or false = false. True while it’s being pulled back by the keys, the mouse or a finger. Set by the game. (Field: on or off.)loaded: true or false = false. True while a ball rests on its tip, ready to shoot. Set by the game. (Field: on or off.)launchIn: a number = 0. 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. (Field: a number.)launches: a whole number = 0. How many balls it has shot. (Field: a number.)
Actions
Section titled “Actions”What anything can make it do with no code: a Trigger’s do when its message arrives, a Contraptions Wire’s input as its signal comes on, a script’s Game.Do(entity, “Name”).
Launch. Shoots whatever rests on it at full power, with nobody pulling it: an auto-plunger, a kickback.Focus. Gives its entity the player’s input: whatever there and inside it has focus, and everything else the same player plays loses it (a platformer’s player stops on the arrow keys while a board takes them).
Outputs
Section titled “Outputs”What anything can read with no code: a Counter’s, Bar’s or Text’s output, a Contraptions Wire’s output as its signal; Text shows names too, the rest read numbers, true as 1.
Pull(a number). How far it’s pulled back, from 0 (resting) to 1 (all the way). Set by the game as it’s pulled.Loaded(true or false). True while a ball rests on its tip, ready to shoot. Set by the game.Launches(a whole number). How many balls it has shot.
While the game runs
Section titled “While the game runs”Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.
worldDirection: [x, y]. The way it shoots in the world (its Direction turned with it).tip: [x, y]. Where its tip is in the world: its position, where a ball rests.
Scripts use it as Plunger: its methods, events and values that aren’t saved with the scene.