Skip to content

Rope

namespace Griff.Scenes;
public sealed class Rope : Component, IDrawable

A rope from its entity to another (To), to a point in the world, or hanging loose: it hangs and sags under gravity, swings, lies over what it falls on and wraps round corners, and holds what’s tied to it no further than its Length: hang a crate or a lamp from the ceiling, tie a balloon to a box, tow a cart, swing a wrecking ball. Either end can be a body (pulled about by it, and turned if it rotates), something that doesn’t move, or the world. A player with Platformer Movement grabs a Climbable one with up, climbs it, swings on it and jumps off.

It’s a chain of short pieces worked out with the bodies that rotate, and drawn as a smooth curve. In the Scene view, drag the knobs at its ends to move them and the one at its middle to make it longer or shorter. Give it a BreakForce to have it snap when it’s pulled too hard (it then says Broke and sends its BreakMessage), or Cut it from a wire or a script.

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

public Vector2 Anchor { get; set; }

Where it’s tied on this entity, from its position, in its own units (before its scale, turned with it): (0, 0) is its middle; (0, 0.5) the top of a crate 1 high.

public float BreakForce { get; set; }

How hard it can be pulled before it snaps, in the units of gravity’s pull on a body (a crate of Mass 1 hanging still pulls 25). 0 never breaks.

public string? BreakMessage { get; set; }

A message sent with Game.Send when it breaks, with the entity as its data, e.g. “RopeSnapped”.

public bool Broke { get; set; }

True once it has broken (pulled harder than its BreakForce, or Cut): its two halves hang from their ends. Wire it to a lamp or a gate; untick it to mend it.

public bool Climbable { get; set; }

A player with Platformer Movement grabs it with up, climbs it at its Climb Speed, swings on it left and right, and jumps off.

public bool Collide { get; set; }

It meets the world: it lies on the ground, drapes over things and wraps round corners. Off, it passes through everything.

public Color Color { get; set; }

The rope’s color.

public bool EndIsLoose { get; }

True when its other end hangs free: LooseEnd with nothing in To, or tied to something that has gone.

public float GravityScale { get; set; }

How strongly gravity pulls it: 1 hangs and sags; 0 (a top-down game) lies where it’s put.

public IEnumerable<Entity> Hanging { get; }

The players hanging on it now.

public float Length { get; set; }

How long it is, in world units: the two ends can come closer (it sags) but no further apart. 0 makes it as long as the ends are apart as the game starts. It can change while the game runs, to winch something up or let it down.

public bool LooseEnd { get; set; }

With nothing in To, its other end hangs free rather than tied to the world: a rope to climb and swing on, a bell pull. It starts laid out towards OtherAnchor (and straight down from there for any length left over), and falls and swings from there.

public Vector2 OtherAnchor { get; set; }

Where its other end is tied on what it’s tied to, in that one’s own units; tied to nothing, where that end is in the world (with LooseEnd, where it starts).

public Entity? OtherEntity { get; }

What its other end is tied to (see To): null for the world or a loose end, or when nothing has that name.

public float PlacedLength { get; }

How long it is as placed: its Length, or (at 0) as far apart as its ends are.

public int PointCount { get; }

How many points it’s laid out as while the game runs (0 before), from this end to the other.

public float Stiffness { get; set; }

How much it gives, from 0 to 1: 1 (the default) doesn’t stretch; lower stretches like elastic, so what hangs on it bounces (0.5 is a bungee cord, 0 a rubber band).

public float Tension { get; }

How hard it’s pulled as the last step ended, in the units of BreakForce.

public string? To { get; set; }

What its other end is tied to, by name: the nearest entity called that. Empty ties it to a point in the world (see OtherAnchor), or leaves it hanging free with LooseEnd.

public float Width { get; set; }

How thick it’s drawn, in world units: it meets the world this thick too (at least 0.08).

public Vector2 WorldAnchor { get; }

Where it’s tied on its entity, in the world.

public Vector2 WorldOtherAnchor { get; }

Where its other end is in the world as it’s placed: on what it’s tied to, or the point in the world (a loose end: where it starts).

public void Cut()

Breaks it: in the middle, or above the lowest player hanging on it. Its halves hang from their ends.

public void Mend()

Joins it up again, as it was before it broke.

public Vector2 PointAt(int index)

Where point index (0 at this end, PointCount - 1 at the other) is while the game runs.

public int Shape(Span<Vector2> points, StepBlend blend)

Its shape now into points (at least MaxPoints long): as the game has it (drawn between steps as blend says, its ends where what they’re tied to is drawn), or before the game runs, hanging at rest. How many points.

public void TieTo(Entity? other)

Ties its other end to other (null: the world), that one even if others share its name.

public const int MaxPoints

The most points a rope is laid out as.