On this page
  1. On pages of their own
  2. Tween: animate one property, with easing, looping and ping-pong
    1. Ease
    2. Property
  3. World and production
    1. MAX_SPAWNED
  4. Moving on its own
    1. Face
  5. The sprite, the pointer and the brain
    1. AnimationRule
    2. State
    3. Transition
    4. kinds

rmp::behavior

namespace #include <rmp/behavior.h>

rmp/behavior.h — the catalogue.

ball.add<rmp::behavior::Ball>({ .speed = 320 });
player.add<rmp::behavior::TopDown>({ .speed = 220 });

A behavior is any struct with void _update(rmp::Object &, float). The model is explained above Object::add in rmp/object.h, and the part worth repeating here is that every one of these is a struct exactly like one of yours: there is no extension API, because there is nothing to extend.

THE FIELDS ARE THE CONFIGURATION, and they are hot:

player.get<rmp::behavior::TopDown>()->speed = 400;   // a power-up

NONE OF THEM CHOOSES A DIRECTION FOR YOU. A behavior contributes behaviour, not intention: which way the Pong ball is served is a rule of the game, and picking it would be the framework deciding something that is not its to decide. So a Ball starts still, a Projectile travels the way you pushed it, a Follow chases the handle you gave it, and a TopDown reads the actions you named.

WHAT THEY WRITE IS A NUMBER. A behavior writes into its object — the position, the velocity, the scale — only finite numbers: a field that is NaN or an infinity, or one so large the arithmetic overflows, leaves the object as it was, and the behavior says so once (a field that is NaN is named). A hook handed a delta that is not a number of seconds, 0 or more, counts it as 0 and says so once; the framework never hands one.

PAUSED, NOT REMOVED. object.enable<B>(false) stops a behavior's hooks and keeps its state; a Chase pauses the Patrol it interrupts that way, and a StateMachine's states say which behaviors run while they are on.

FROM THE EDITOR. The behaviors a level designer places — Patrol, Chase, Orbit, Shooter, Hitbox, Collectible — have B::from(const MapObject &), which reads the entity's fields by the names written above each of them, and leaves every field the entity does not have at its default:

map.on_object("Bat", [](rmp::Scene &s, const rmp::MapObject &o) {
    auto &bat = s.spawn({ .position = o.position });
    bat.add(rmp::behavior::Patrol::from(o));
});

WHAT IS NOT HERE, and why, in short: tetromino, formation and paddle are three games with a different name on them.

On pages of their own

Tween: animate one property, with easing, looping and ping-pong

Ease

enum class Ease

The curve a Tween's value follows from from to to over its seconds. LINEAR moves at a constant rate; IN starts slow and speeds up; OUT starts fast and slows into to; IN_OUT is slow at both ends and fastest in the middle. The last three are quadratic, and a ping_pong's way back runs the same curve in reverse.

ValueMeans
LINEAR
IN
OUT
IN_OUT

Property

enum class Property

Which field of its object a Tween writes, on every update it runs. ALPHA takes 0 to 255 and clamps to that range.

ValueMeans
POSITION_XPosition.x, the centre
POSITION_YPosition.y, the centre
SCALE_XScale.x
SCALE_YScale.y
ROTATIONRotation, in degrees
ALPHAThe shape's colour, or the sprite's tint

World and production

MAX_SPAWNED

inline constexpr int MAX_SPAWNED = 64

How many of its own objects one Spawner keeps track of, which is the largest max_alive it can enforce. A fixed array and not a std::vector because <vector> costs 92 ms in every translation unit that includes a behavior, and a spawner that needs hundreds of things alive at once is a pool, not a spawner. A max_alive above this warns once and is treated as this.

Moving on its own

Face

enum class Face

Which way an Orbit turns its object.

ValueMeans
NONEIts rotation is left alone
CENTREIt looks at what it circles
OUTWARDIt looks away from it

The sprite, the pointer and the brain

AnimationRule

struct AnimationRule

A rule of an Animator: play tag while when says so. The rules are asked in order, before anything the Animator works out itself.

FieldTypeDefaultWhat it is
tagstd::string

The tag played while when says so

whenCondition<Object &>

Asked with the object, every update

State

struct State

One state of a StateMachine: what it does on the way in, every frame, on the way out, and which behaviors run while it is on.

FieldTypeDefaultWhat it is
namestd::string

What transitions and go() call it

on_enterCallback<Object &>

Once, as the machine moves into it

on_updateCallback<Object &, float>

(the object, delta)

on_exitCallback<Object &>

Once, as the machine moves out of it

enablesstd::vector<int>

The behaviors that run in this state: rmp::behavior::kinds<Patrol>(). Every behavior some state names is paused in the states that do not.

Transition

struct Transition

A move from one state to another, taken when when says so.

FieldTypeDefaultWhat it is
fromstd::string

"" = from any state

tostd::string

The state it moves to

whenCondition<Object &>

Asked with the object every update; yes takes the move

kinds

template <class... B> std::vector<int> kinds()

The behaviors a State turns on, by type: .enables = kinds<Patrol, Animator>().