On this page
  1. Fields
    1. fire
    2. shots
    3. from

rmp::behavior::Shooter

behavior #include <rmp/behavior.h> include/rmp/behavior.h:723
struct Shooter

Fires. On an action held down, on its own every every seconds, or at a target — one bullet or a pattern of them: count spread over spread degrees, the whole pattern turned by rotate_per_shot after each volley, which is how a spiral is made.

THE BULLET is a circle of bullet_radius in bullet_color, with a Projectile (gone at a wall or a hit), a Lifespan of bullet_life and a Hitbox of damage on the layers of hits. Or it is whatever on_shoot makes, handed the scene, where it leaves from and its velocity:

.on_shoot = [](rmp::Scene &s, Vector2 at, Vector2 velocity) {
    auto &arrow = s.spawn({ .position = at, .velocity = velocity });
    arrow.sprite.texture = rmp::assets::load_texture("arrow.png");
}

From the editor: "every" (Float), "speed" (Float), "count" (Int), "spread" (Float), "rotate" (Float, rotate_per_shot), "range" (Float).

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

Fields

FieldTypeDefaultWhat it is
actionstd::string

Fires while it is held; "" = never on input

automaticboolfalse

Fires every every seconds on its own

everyfloat0.25f

The least time between two volleys, in seconds

targetHandle<Object>

Aims at it; while it is set and gone, it does not fire

rangefloat0

With a target: fires only when it is this close; 0 = any distance

directionVector2{}

Where it aims without a target; {0,0} = the way it faces

speedfloat360

The bullets', in units per second

countint1

Bullets per volley

spreadfloat0

Degrees the volley covers; 360 = all around, evenly

rotate_per_shotfloat0

Degrees the pattern turns after each volley

offsetVector2{}

Where the bullets leave from, from its centre

soundstd::string

Played by rmp::audio on each volley; "" = silent

bullet_radiusfloat4

The default bullet's

bullet_colorColorWHITE

The default bullet's fill

bullet_lifefloat2

Seconds before it is discarded

damageint1

What the default bullet's Hitbox costs

hitsunsigned0

The layers the bullets hit; 0 = its own mask, less its own layer

on_shootCallback<Scene &, Vector2, Vector2>

Makes the bullet instead: (the scene, where it leaves from, its velocity).

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.

fire

bool fire(Object &self)

Fires a volley now, if every has passed since the last; true if it did.

shots

int shots() const

How many volleys it has fired.

from

static Shooter from(const MapObject &object)

A Shooter with the fields the map's entity has by these names — every, speed, count, spread, rotate, range — and the defaults for the rest. See "FROM THE EDITOR" at the top of this file.