On this page
  1. Fields
    1. heading_for
    2. from

rmp::behavior::Patrol

behavior #include <rmp/behavior.h> include/rmp/behavior.h:785
struct Patrol

Goes from waypoint to waypoint — round in a loop, or back and forth with ping_pong — waiting wait seconds at each. With no waypoints it walks the floor instead: left and right at speed, turning at a wall and, with turn_at_ledges, before a drop, which is a platformer's goomba. The way it goes sets flip_x, and its sprite plays walk and idle when its sheet has them — unless the object has an Animator, which then chooses.

Waypoints are for what flies or walks top-down: it moves straight to each, on both axes. Floor walking moves only along x, and gravity is the object's.

From the editor: "path" (Array<Point>; the entity's own position is the first waypoint), "speed" (Float), "wait" (Float), "ping_pong" (Bool).

Added to an object with add<rmp::behavior::Patrol>(); the framework calls its _update with the object it is on.

Fields

FieldTypeDefaultWhat it is
waypointsstd::vector<Vector2>

World positions; empty = it walks the floor

speedfloat60

Units per second

waitfloat0

Seconds it stays at each waypoint

ping_pongboolfalse

Back and forth; false = from the last straight to the first

turn_at_ledgesbooltrue

Walking the floor: turns before a drop

walkstd::string"walk"

The tag played while it moves; "" = none

idlestd::string"idle"

The tag played while it waits; "" = none

oursstruct { … }

What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then { .speed = 320 } stops compiling — which is the whole design. The name is the fence.

heading_for

int heading_for() const

The waypoint it is heading for, an index into waypoints.

from

static Patrol from(const MapObject &object)

A Patrol with the fields the map's entity has by these names — path, speed, wait, ping_pong — and the defaults for the rest. See "FROM THE EDITOR" at the top of this file.