Shooter
namespace Griff.Scenes;
public sealed class Shooter : ComponentFires copies of a Prefab with no code: turrets, cannons, a boss’s spread, or the player’s own gun (see Action). Each shot’s Body is sent off at Speed and it’s turned to face the way it’s going. With Beats set, it fires on the beat of a BeatClock.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”Action
Section titled “Action”public string? Action { get; set; }An input action, e.g. “Fire”: it then fires only while the player holds it, towards the right stick or the mouse (or Direction when neither aims anywhere). Empty fires by itself.
BeatOffset
Section titled “BeatOffset”public int BeatOffset { get; set; }Steps this many beats later: with two turrets on every 2 beats, one 1 beat later, they take turns.
public int Beats { get; set; }Steps to the music of a BeatClock: fires on every this many beats instead of every Interval seconds, once Delay has passed (and, with an Action, while it’s held). 0 goes by seconds.
public string? Clock { get; set; }The entity whose BeatClock it steps to. Empty follows the first in the scene.
public int Count { get; set; }Shots in each volley, fanned out across Spread.
public float Delay { get; set; }Seconds before the first shot.
Direction
Section titled “Direction”public Vector2 Direction { get; set; }Which way to fire without a target (or an aim, for the player).
Interval
Section titled “Interval”public float Interval { get; set; }Seconds between shots (unless it steps to the Beats).
NeedsSight
Section titled “NeedsSight”public bool NeedsSight { get; set; }With a Target, only fire when nothing solid is in the way: no shooting through walls.
Offset
Section titled “Offset”public Vector2 Offset { get; set; }Where shots appear relative to the entity, in world units.
Prefab
Section titled “Prefab”public string? Prefab { get; set; }The prefab to fire, e.g. “Bullet” (Assets/Prefabs/Bullet.prefab). It needs a Body to fly.
public float Range { get; set; }With a Target, only fire when it’s this close. 0 fires at any distance.
Running
Section titled “Running”public bool Running { get; set; }Untick it to hold fire. Switches tick and untick it.
public string? Sound { get; set; }A sound played with each volley, e.g. “Sounds/shoot.wav”.
public float Speed { get; set; }How fast shots fly, in world units per second.
Spread
Section titled “Spread”public float Spread { get; set; }Degrees the volley fans across; with one shot, how far off aim it may randomly go.
Target
Section titled “Target”public string? Target { get; set; }The name of an entity to aim at, e.g. “Player”. Empty fires in Direction.
Methods
Section titled “Methods”VolleyAround
Section titled “VolleyAround”public IEnumerable<Vector2> VolleyAround(Vector2 aim)The directions of one volley’s shots around aim (a unit vector).
Events
Section titled “Events”public event Action<Entity>? FiredRaised with each shot fired, e.g. to give it a damage or a color.