Powder

From Sandboxels Wiki
Jump to navigation Jump to search
Falling sand
Sand is an example of a powder.

Powder is a behavior that makes the element act like a powder. The element falls down in the air and slides down slopes. They are characterized by forming piles and dunes. Powders have their own category (Powders), but they also appear in the Land and Food categories.

Powders fall straight down in the air. When supported below by a pixel, the powder will move left or right (chosen randomly) along with falling down. Once supported with a stable floor, the powder will not move. Powders spread in the air because when placed as a square, the game interprets some pixels as on a slope which the pixels fall off to the side.

Powder is one of the most common behaviors, some examples being Sand, Dirt and Rock.

Sturdy Powder

Main article: Sturdy Powder

Sturdy Powder is a type of Powder behavior. It differs in that elements with it fall straight down without moving horizontally and cannot slide down slopes.

Technical

The POWDER behavior in Sandboxels' source code is described as a function:

POWDER: function(pixel) {
  if (pixel.start === pixelTicks) {return}
  if (pixel.charge && elements[pixel.element].behaviorOn) {
    pixelTick(pixel)
  }
  if (!tryMove(pixel, pixel.x, pixel.y+1)) {
    if (Math.random() < 0.5) {
      if (!tryMove(pixel, pixel.x+1, pixel.y+1)) {
        tryMove(pixel, pixel.x-1, pixel.y+1);
      }
    } else {
      if (!tryMove(pixel, pixel.x-1, pixel.y+1)) {
        tryMove(pixel, pixel.x+1, pixel.y+1);
      }
    }
  }
  doDefaults(pixel);
}

This is functionally identical to the POWDER_OLD behavior, which is coded in a grid style:

POWDER_OLD: [
  "XX|XX|XX",
  "XX|XX|XX",
  "M2|M1|M2",
]