Skip to content

Pushable

namespace Griff.Scenes;
public sealed class Pushable : Component, IDrawEffect, IGridDriver

A crate that bodies push along by walking into it, with no code: sideways in a platformer, any way in a top-down game (when its Body’s Gravity Scale is 0). It pushes crates in front of it in turn, and stops at walls. Needs a Body and a solid collider. Give it a layer (say “Crate”) to have it hold a pressure plate down. With a GridMovement too it’s a Sokoban crate: a grid mover stepping into it pushes it a cell (gliding along with it), unless a wall or another crate is in the way, and resting on a puzzle’s Goal covers it. A crate whose body Rotates doesn’t need one: whatever walks into it knocks it along (and over), by their weights.

This is a component: its saved properties are on its component page.

public Color? GoalTint { get; }

The color the goal it rests on turns it, drawn instead of its sprite’s own (not saved, so a rewind never keeps it).

public string? Kind { get; set; }

What kind of crate it is, e.g. “Red”: a Goal’s Accepts names the kinds that cover it.

public string? Layers { get; set; }

The collision layers that can push it, e.g. “Player”. Empty lets any body push it.

public Entity? OnGoal { get; }

The goal it rests on, or null. Kept up to date while the game runs.

public bool PushesRow { get; set; }

On a grid, pushing it into another crate pushes that one too, so a row slides together. Off, a crate behind it blocks it, as in Sokoban.

public float Speed { get; set; }

How fast it goes compared to whoever pushes it: 1 is as fast, 0.5 half as fast (a heavy crate), 0 won’t budge. On a grid it always keeps pace with its pusher, and 0 still won’t budge.

public bool AcceptsLayer(string? layer)

True if something on collision layer layer can push it.

public void MarkGoal(Entity? goal, Color? tint)

Rests it on goal (null: none), turning it tint while it does: what owns the goals says.

public event Action<Entity, Vector2>? Pushed

Raised when a grid mover pushes it a cell, with the pusher and the way it’s pushed.