rmp::behavior::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
| Field | Type | Default | What it is |
|---|---|---|---|
action | std::string | Fires while it is held; "" = never on input | |
automatic | bool | false | Fires every |
every | float | 0.25f | The least time between two volleys, in seconds |
target | Handle<Object> | Aims at it; while it is set and gone, it does not fire | |
range | float | 0 | With a target: fires only when it is this close; 0 = any distance |
direction | Vector2 | {} | Where it aims without a target; {0,0} = the way it faces |
speed | float | 360 | The bullets', in units per second |
count | int | 1 | Bullets per volley |
spread | float | 0 | Degrees the volley covers; 360 = all around, evenly |
rotate_per_shot | float | 0 | Degrees the pattern turns after each volley |
offset | Vector2 | {} | Where the bullets leave from, from its centre |
sound | std::string | Played by | |
bullet_radius | float | 4 | The default bullet's |
bullet_color | Color | WHITE | The default bullet's fill |
bullet_life | float | 2 | Seconds before it is discarded |
damage | int | 1 | What the default bullet's Hitbox costs |
hits | unsigned | 0 | The layers the bullets hit; 0 = its own mask, less its own layer |
on_shoot | Callback<Scene &, Vector2, Vector2> | Makes the bullet instead: (the scene, where it leaves from, its velocity). | |
ours | struct { … } | 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 |
fire
Fires a volley now, if every has passed since the last; true if it did.
shots
How many volleys it has fired.
from
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.