rmp::behavior
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-upNONE 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
rmp::behavior::TopDown— Eight directions, and the sprite chosen from the one you are facing.rmp::behavior::Platformer— Gravity, jumping, ground, coyote time and a buffered jump.rmp::behavior::Runner— Constant forward motion that SPEEDS UP over time, with a jump and a duck.rmp::behavior::Ball— Bounces, keeps its pace, and leaves a paddle at an angle that depends on where it hit.rmp::behavior::Projectile— Travels the way you pushed it and is discarded when it leaves or hits.rmp::behavior::Follow— Chases a handle, with a speed and a distance it stops at.rmp::behavior::Tween— Moves one property of its object fromfromtotooverseconds, along an Ease.rmp::behavior::GridSnap— Squares the position with a grid, AFTER everything that moves it.rmp::behavior::Parallax— A background layer that scrolls at its own factor and repeats itself with no seam.rmp::behavior::Spawner— Produces objects every N seconds, or every N units TRAVELLED.rmp::behavior::Timer— Calls you every N seconds.rmp::behavior::Lifespan— Discarded after N seconds.rmp::behavior::Health— Hit points, a window of invulnerability with a blink, and death.rmp::behavior::Area— A region that says who comes and goes: a trigger, a door's sensor, a pit, a shop's counter.rmp::behavior::Hitbox— What hurts: a sword's swing, a spike, a bullet, an explosion.rmp::behavior::Talker— Someone to talk to.rmp::behavior::Collectible— A coin, a key, a heart.rmp::behavior::Shooter— Fires.rmp::behavior::Patrol— Goes from waypoint to waypoint — round in a loop, or back and forth withping_pong— waitingwaitseconds at each.rmp::behavior::Pathfind— Walks to a target, or to a point, around the map's walls:rmp::find_path(), asked again everyrepath_everyseconds, and followed atspeed.rmp::behavior::Chase— Sees a target and goes after it.rmp::behavior::Orbit— Circles a handle or a point: a shield of blades, a moon, a fairy.rmp::behavior::Animator— Plays the tag that fits what the object is doing:dieonce its Health is dead,hurtwhile it is invulnerable after a hit,jumpandfallin the air (with gravity),runwhile it moves andidlewhile it does not — and mirrors it with flip_x by the way it moves.rmp::behavior::Draggable— Picked up with the pointer and put down somewhere.rmp::behavior::StateMachine— Named states and the moves between them: an enemy that idles, patrols, chases and flees; a boss's phases.
Tween: animate one property, with easing, looping and ping-pong
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.
| Value | Means | |
|---|---|---|
LINEAR | ||
IN | ||
OUT | ||
IN_OUT |
Property
Which field of its object a Tween writes, on every update it runs. ALPHA takes 0 to 255 and clamps to that range.
| Value | Means | |
|---|---|---|
POSITION_X | Position.x, the centre | |
POSITION_Y | Position.y, the centre | |
SCALE_X | Scale.x | |
SCALE_Y | Scale.y | |
ROTATION | Rotation, in degrees | |
ALPHA | The shape's colour, or the sprite's tint |
World and production
MAX_SPAWNED
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
Which way an Orbit turns its object.
| Value | Means | |
|---|---|---|
NONE | Its rotation is left alone | |
CENTRE | It looks at what it circles | |
OUTWARD | It looks away from it |
The sprite, the pointer and the brain
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.
| Field | Type | Default | What it is |
|---|---|---|---|
tag | std::string | The tag played while | |
when | Condition<Object &> | Asked with the object, every update |
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.
| Field | Type | Default | What it is |
|---|---|---|---|
name | std::string | What transitions and | |
on_enter | Callback<Object &> | Once, as the machine moves into it | |
on_update | Callback<Object &, float> | (the object, delta) | |
on_exit | Callback<Object &> | Once, as the machine moves out of it | |
enables | std::vector<int> | The behaviors that run in this state: |
Transition
A move from one state to another, taken when when says so.
| Field | Type | Default | What it is |
|---|---|---|---|
from | std::string | "" = from any state | |
to | std::string | The state it moves to | |
when | Condition<Object &> | Asked with the object every update; yes takes the move |
kinds
The behaviors a State turns on, by type: .enables = kinds<Patrol, Animator>().