Tilt
namespace Griff.Modules.PhysicsGames;
public sealed class Tilt : Component, IDrawable, IPlaytestReportNudging and tilting a pinball table, with no code: its NudgeAction bumps the table, giving every ball on it a small push (and shaking the view), but nudge too often in a short time and it warns, then tilts: the flippers drop and stay down and the bumpers, kickers, targets and lanes go dead until the ball drains.
Each nudge adds one to its Danger, which falls back by one every Settle seconds. A nudge that takes it past one warns (its WarningMessage, “DANGER” over the table); past Warnings plus one, it tilts. It covers what’s inside the entity its Within names (or stands in its area), or the whole scene. A Drain it covers puts it right as the ball drains; its Reset action does too.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”Controllable
Section titled “Controllable”public bool Controllable { get; set; }Untick it to have it ignore the keys and gamepad (its actions and scripts still work). Its Focus action ticks it and unticks it on everything else the player plays.
Danger
Section titled “Danger”public float Danger { get; set; }How close it is to tilting: one for each recent nudge, falling back by one every Settle seconds.
NudgeAction
Section titled “NudgeAction”public string? NudgeAction { get; set; }The input action that nudges the table: “Nudge” is N, the up arrow or the gamepad’s B.
NudgeDirection
Section titled “NudgeDirection”public Vector2 NudgeDirection { get; set; }Which way a nudge pushes the balls, in the world: (0, 1) is up the table. Holding left or right as it’s nudged (the arrows, A and D, the stick) pushes them that way too.
NudgeSound
Section titled “NudgeSound”public string? NudgeSound { get; set; }A sound played with each nudge, e.g. “Sounds/thud.wav”.
NudgeStrength
Section titled “NudgeStrength”public float NudgeStrength { get; set; }How hard a nudge pushes each ball, in world units a second.
Nudges
Section titled “Nudges”public int Nudges { get; set; }How many times the table has been nudged.
Settle
Section titled “Settle”public float Settle { get; set; }Seconds for each nudge to wear off: nudges further apart than this never add up to a tilt.
public float Shake { get; set; }How hard the view shakes with each nudge; 0 doesn’t shake it.
ShowText
Section titled “ShowText”public bool ShowText { get; set; }Shows “DANGER” over the table for a moment after a warning, and “TILT” while it’s tilted, at its position.
TextColor
Section titled “TextColor”public Color TextColor { get; set; }The color of its “DANGER” and “TILT”.
TextSize
Section titled “TextSize”public float TextSize { get; set; }How tall its “DANGER” and “TILT” are, in world units.
TiltMessage
Section titled “TiltMessage”public string? TiltMessage { get; set; }A message sent as it tilts, e.g. “Tilted”.
TiltSound
Section titled “TiltSound”public string? TiltSound { get; set; }A sound played as it tilts.
Tilted
Section titled “Tilted”public bool Tilted { get; set; }True once it has tilted, until the ball drains (or its Reset action).
WarningFor
Section titled “WarningFor”public float WarningFor { get; set; }Seconds “DANGER” still shows. Set by the game.
WarningMessage
Section titled “WarningMessage”public string? WarningMessage { get; set; }A message sent as it warns, with how many warnings it has given this ball as its data, e.g. “Danger”.
WarningSound
Section titled “WarningSound”public string? WarningSound { get; set; }A sound played as it warns.
Warnings
Section titled “Warnings”public int Warnings { get; set; }How many nudges close together only warn: the next tilts.
Within
Section titled “Within”public string? Within { get; set; }The table it covers, by an entity’s name: the balls, flippers, bumpers, targets and lanes inside it or standing in its area. Empty covers the whole scene.
Methods
Section titled “Methods”public void Nudge()Nudges the table: each ball gets a little push, and it’s one nudge nearer tilting.
public void Reset()Puts it right: not tilted, and no nudges counting against it.
TiltNow
Section titled “TiltNow”public void TiltNow()Tilts it now: the flippers drop and the table goes dead until the ball drains.
public override bool Uses(string property)Events
Section titled “Events”TiltedOver
Section titled “TiltedOver”public event Action<Tilt>? TiltedOverRaised as it tilts.
Warned
Section titled “Warned”public event Action<Tilt>? WarnedRaised as it warns.