Skip to content

Breakable

Something that breaks when it’s hit hard enough, with no code: a plank of wood, a pane of glass, a stone block, a pig in a tower. Every hit harder than its MinHit adds to its Damage, cracking it more and more as it goes, and once that reaches its Strength it breaks: it splits into pieces that tumble away and fade (Split), or vanishes in a puff of dust, with its Sound and BreakMessage. A hit is as hard as the push it took to stop the two coming together: a crate of Mass 1 landing at 5 units a second hits 5, so heavy, fast things hit hardest. Hits come from anything (a shot from a Slingshot, a falling block, the floor), and what breaks it can break something else in turn.

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.

Materials come from a table: give it a Table Values on a Materials table whose rows (Wood, Glass, Stone) have columns named like its properties (Strength, Min Hit) and its body’s and sprite’s (Mass, Tint). With a Health on the same entity, each hit that counts takes its damage off that too (its bar, flash and Hurt Sound go with it), and it breaks when the Health dies. Its Break action breaks it whatever its damage, and Repair mends it. Its Damage and Broken outputs are for a Counter, a Bar or a wire; its Damage Message and Break Message (with its Points) for a Counter that keeps the score.

Requires: Collider (what gets hit)

Works with: Body (with Rotates on, it tumbles, topples and knocks things over); TableValues (its strength and look from a Materials table); Health (hits take its damage off the health too, and it breaks as that dies); Counter (keeps the score from its Break Message (on another entity))

Draws itself, along with the rest of its entity (it doesn’t set the entity’s draw order).

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.

  • strength: a number = 10. How much damage it takes before it breaks: the hits it takes add up to this. A hit’s damage is how hard it is (a crate of Mass 1 landing at 5 units a second hits 5). 0 doesn’t break by damage (only its Break action, or its Health dying). (Field: a number.)
  • minHit: a number = 2. Hits softer than this do no damage at all: knocks, nudges and landing gently don’t wear it down. (Field: a number.)
  • split: a whole number = 2. How many pieces it splits into along its longer side as it breaks, and as many across as keeps them about square: 2 halves a plank and quarters a crate, 3 makes nine of a crate. Each is a part of its sprite, tumbling away and fading. 0 (or 1) vanishes in a puff of dust instead. (Field: a number.)
  • piecesLast: a number = 3. Seconds its pieces last before they’ve faded away; 0 leaves them lying about. (Only used when split is set.) (Field: a number.)
  • dust: a whole number = 16. How many specks of dust burst out as it breaks, in its color (without an Effect); 0 none. (Field: a number.)
  • effect: text = null. A prefab spawned where it broke, e.g. “Explosion”: a burst of particles, a score popup. Takes the place of the dust. (Names a prefab.) (Field: a name.)
  • remove: true or false = true. Takes it away as it breaks. Untick it to leave it turned off instead, with its Broken output on (for a wire or a script to read), until its Repair action brings it back. (Field: on or off.)
  • stages: a whole number = 3. How many stages of cracking it shows as its damage builds up, one more for each share of its Strength. With a sprite sheet (a Sprite with Columns or Rows), its frames from the first are those stages instead: frame 0 whole, 1 cracked, and so on. 0 shows none. (Field: a number.)
  • crackColor: a color, “#RRGGBB” or “#RRGGBBAA” = “#1A120DBF”. The color its cracks are drawn in (on a sprite with no sheet of stages); clear draws none. (Field: a color.)
  • sound: text = null. A sound played as it breaks, e.g. “Sounds/smash.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • hitSound: text = null. A sound played as a hit damages it without breaking it, e.g. “Sounds/crack.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • breakMessage: text = null. A message sent with Game.Send as it breaks, e.g. “Popped”: with its Points as its data (a Counter adds them up), or with none, the entity (a Counter counts one). (Names a message.) (Field: a name.)
  • points: a whole number = 0. What it’s worth as it breaks: the data its Break Message carries, for a Counter keeping the score. 0 sends the entity. (Field: a number.)
  • showPoints: true or false = false. Shows its Points where it broke, rising and fading away: what knocking it out scored. (Field: on or off.)
  • pointsColor: a color, “#RRGGBB” or “#RRGGBBAA” = “#FFFFFFFF”. The color its points are shown in. (Only used when showPoints is on.) (Field: a color.)
  • damageMessage: text = null. A message sent as each hit damages it, with the damage as its data: a Counter of these scores every knock. (Names a message.) (Field: a name.)
  • damage: a number = 0. How much damage it has taken: its hits added up. It breaks as this reaches its Strength. Set it to start it cracked. (Field: a number.)
  • broken: true or false = false. True once it has broken (and, with Remove off, while it lies turned off until it’s repaired). (Field: on or off.)

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

  • Break. Breaks it now, whatever its damage.
  • Damage (done with a number, its amount: a trigger’s with, 1 without one). Takes amount damage, as a hit that hard would.
  • Repair. Mends it: no damage, no cracks, and (left turned off as it broke, with Remove off) back where it was.

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.

  • Damage (a number, out of its strength). How much damage it has taken: its hits added up. It breaks as this reaches its Strength. Set it to start it cracked.
  • Broken (true or false). True once it has broken (and, with Remove off, while it lies turned off until it’s repaired).

Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.

  • stage: a whole number. Which stage of cracking it’s at: 0 whole, up to its Stages as its damage nears its Strength.

Scripts use it as Breakable: its methods, events and values that aren’t saved with the scene.