bullet

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 31 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bullet fires shots and flies them: entities of the world a Shoot spawns at a unit's muzzle, flown every step past the world's step cap and swept by collision, so what lies on the path is struck. A weapon — which ammo, how often, who carries it — is the game's rules and effects.

Body, Shots and Ammo

Body is what a kind of shot is: its Size, Speed, Range, its Gravity if thrown and whether it Lands. Shots (Plugin.Shots) defines the kinds: Define(name, body, extra...) registers an ammo, Named is the Ammo a Shoot names. A shot is a kind of the world like any other, drawn from its sprite, carrying a Collider without Physics (a sensor), a Sweep ignoring its shooter, its Body, its Flight and its shooter's owners. The game must use collision: without it nothing is struck.

Shoot

Shoot is the command: by a player, from the unit its Camera is fastened to, else from every Selected unit it owns; by an entity, through act.Self.Do in a rule or a plan, from itself. The shot goes towards At when Targeted, towards the moment's Subject when aimed, else the way the shooter faces. A thrown shot comes down where it goes to, on the ground Plugin.WithGround gives, untargeted as far as its Power says.

Landing, Resting and Blast

Landing is told once as a flight ends: whom it Struck (its Subject), which Wall, whether it came down or Left. Resting is told every step for a landed shot that Lands; Burst is the command such a shot gives itself, and Blast what every entity within the Burst's Radius is to the pair rules, Within its word of the other. A Flight is a plan's fact, Lying its word of a shot come to rest: a fuse. The Meeting of a shot and what it struck is collision's.

Dressing a shot

A shot is dressed on the world's atlas as any entity: a look Under an effect, and Turning for one drawn the way it flies, the sprite authored facing east.

Limits

A wrapping world is refused. Shots do not penetrate: the nearest contact ends the flight. A landed shot touches nothing. A shot flies every step at every level of the world's sectors but L6, keeping its sector and those round it at L4 at most (sector.Keen) till it rests, at L3 when aimed at an aggregate (world.Aggregate), so a fight unfolds it as the shot comes.

Figures

A Figure is a kind of ammo in one piece: Define its Body on the plugin's Shots, Look its look on the world's atlas, and, Stateful or Ruled, its own effects and rules. Plugin.Figures, called in the Stage's Figures link, hands them on to the world's figures, which the Stage leads through its sections; Plugin.World is the world the shots fly in.

Vocabulary

Moments, for a role's rules: Landing (a shot landing, its subject what it struck), Resting (a landed shot, every step), Blast (a pair, host.Met, its subject the shot; its word Within of the other). Facts, for plans: Flight (every shot's, its word Lying). Knobs, for an effect's Alter: Body (its Speed and Gravity felt every step, its Range at the shot). Commands: Shoot (a player's or an entity's own, aimed at the moment's subject, host.Aimed); Burst (an entity's own).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lying

func Lying() cond.Word[Flight]

Lying is the word of a shot that has landed and lies where it came down.

func Within

func Within(d float32) cond.Word[Blast]

Within is the word of the one reached being within d of the shot, of the other.

Types

type Ammo

type Ammo struct {
	// contains filtered or unexported fields
}

Ammo is a kind of shot, as Shoot names it.

func (Ammo) Body

func (a Ammo) Body() Body

Body is what this kind of shot is.

func (Ammo) Entry

func (a Ammo) Entry(shot Shot) kind.Entry

Entry is one shot of this kind, for the world to spawn.

func (Ammo) ID

func (a Ammo) ID() kind.ID

ID is the kind's id, carried by every shot of it.

func (Ammo) SpriteID

func (a Ammo) SpriteID() render.SpriteID

SpriteID is the atlas slot the shots of this kind are drawn from.

type Blast

type Blast struct {
	Self, Other uid.UID64
	Distance    float32
}

Blast is the moment told for each entity within the Radius of a Burst: the shot bursting (Self), the one reached (Other) and how far off its centre is.

func (Blast) Subject

func (b Blast) Subject() (uid.UID64, bool)

Subject is the shot bursting, whom an Aimed command given on the moment is about.

func (Blast) Who

func (b Blast) Who() uid.UID64

Who is the shot bursting.

func (Blast) Whom

func (b Blast) Whom(each func(uid.UID64))

Whom tells each the one reached.

type Body

type Body struct {
	Size, Speed, Range, Gravity float32
	Lands                       bool
}

Body is what a kind of shot is, a knob on every shot: its Size (a square box), how fast and far it flies, whether it is thrown (Gravity > 0) and whether it Lands where its flight ends. A shot that is to Burst must Land.

func (Body) Knob

func (Body) Knob()

Knob: an effect may turn it (effect.Knob).

type Burst

type Burst struct{ Radius float32 }

Burst is the command a landed shot gives itself to burst: every entity within Radius of its centre is told a Blast, and the shot is gone.

func (Burst) Command

func (Burst) Command()

type End

type End uint8

End is how a flight ends: not yet (Flying), its Range flown (Spent), a thrown shot come down (Grounded), stopped at a closed edge (Edge), flown out by an open one (Left), on an entity (Struck), on the solid ground (Wall).

const (
	Flying End = iota
	Spent
	Grounded
	Edge
	Left
	Struck
	Wall
)

type Figure

type Figure interface {
	Define(p *Plugin)
	Look(a *world.Atlas, p *Plugin)
}

Figure is a kind of ammo in one piece: its Body defined on the plugin's Shots in the Kinds section, its look declared on the world's atlas in a scene. One with states of its own is Stateful, one with roles and rules of its own Ruled.

type Flight

type Flight struct {
	At, Dir             geom.Vec
	Range, Flown, Climb float32
	Shooter             uid.UID64
	Ending              End
	Other               uid.UID64
	Cell                uint64
	Landed              bool
}

Flight is a shot in the air: where it is, which way and how far it goes, who shot it, how its flight ends and whether it lies Landed.

func (Flight) Fact

func (Flight) Fact()

Fact: told to the unit, carried until it goes (fact.Fact).

type Landing

type Landing struct {
	ID       uid.UID64
	At       geom.Vec
	Struck   bool
	Other    uid.UID64
	Wall     bool
	Cell     uint64
	Grounded bool
	Left     bool
}

Landing is the moment a shot's flight ends: where, and why — Struck an entity (Other), hit a Wall of the ground (Cell), Grounded (come down, or its Range flown) or Left by an open edge.

func (Landing) Subject

func (l Landing) Subject() (uid.UID64, bool)

Subject is the entity struck; false for a flight ending on nobody.

func (Landing) Who

func (l Landing) Who() uid.UID64

Who is the shot landing.

type Plugin

type Plugin struct {
	*world.Self
	// contains filtered or unexported fields
}

Plugin fires shots and flies them, hosting the rules of their Landing, Resting and Blast.

func NewPlugin

func NewPlugin(w *world.Plugin, m *motion.Plugin, sel *selection.Plugin) *Plugin

NewPlugin builds the bullet plugin over w, firing a player's Shoot from the units sel marks Selected, a shot gone past an open edge m's leaver.

func (*Plugin) DefaultBindings

func (p *Plugin) DefaultBindings() []control.Binding

DefaultBindings are none: a Shoot names its Ammo, which is the game's to bind.

func (*Plugin) EventHandler

func (p *Plugin) EventHandler() control.EventHandler

EventHandler is nil: bullet handles no input of its own.

func (*Plugin) Figures

func (p *Plugin) Figures(figures ...Figure)

Figures notes the kinds of ammo among the world's figures, which the Stage leads through its sections. Called in the Stage's Figures link.

func (*Plugin) Install

func (p *Plugin) Install(ctx plugin.Installer) error

Install refuses a wrapping world: a shot's step must not cross a seam.

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Queues

func (p *Plugin) Queues() []command.CommandQueue

Queues are the plugin's command queues, Shoot and Burst.

func (*Plugin) RunPlan

func (p *Plugin) RunPlan(ctx goke.RunCtx, d time.Duration)

RunPlan fires the Shoots given and hands the flights to the simulation. Call it before the world's RunPlan, so a step's flights are tested by collision in the same step.

func (*Plugin) Serializable

func (p *Plugin) Serializable() plugin.Serializable

Serializable is nil: a shot's state is on its entity.

func (*Plugin) Shots

func (p *Plugin) Shots() *Shots

Shots is the plugin's register of the kinds of shots.

func (*Plugin) WithGround

func (p *Plugin) WithGround(heights func() ground.Heights) *Plugin

WithGround gives the plugin the ground a thrown shot comes down on, read as needed; without it the ground lies at 0.

func (*Plugin) World

func (p *Plugin) World() *world.Plugin

World is the world the shots fly in.

type Resting

type Resting struct {
	ID uid.UID64
	At geom.Vec
}

Resting is the moment told every step a landed shot lies where it ended.

func (Resting) Who

func (r Resting) Who() uid.UID64

Who is the shot resting.

type Ruled

type Ruled interface{ Rules(p *Plugin) }

Ruled is a Figure with roles and rules of its own, defined in the Rules section.

type Shoot

type Shoot struct {
	Ammo     Ammo
	At       geom.Vec
	Targeted bool
	Camera   camera.Camera
	Power    float32
	// contains filtered or unexported fields
}

Shoot is the command to fire a shot of Ammo: by a player from the unit Camera is fastened to, else from every selected unit it owns; by an entity from itself. It goes towards At when Targeted, at the moment's Subject when aimed, else the way the shooter faces, a thrown shot as far as Power says, a share of its Range (0 the whole).

func (*Shoot) Aim

func (s *Shoot) Aim(who uid.UID64)

Aim tells the command whom to shoot at.

func (Shoot) Command

func (Shoot) Command()

type Shot

type Shot struct {
	From, Dir geom.Vec
	Altitude  float32
	Climb     float32
	Range     float32
	Shooter   uid.UID64
	Owners    tag.Tags[owner.Family]
	// contains filtered or unexported fields
}

Shot is the row a kind of shot spawns from; the plugin builds it as it fires.

type Shots

type Shots struct {
	// contains filtered or unexported fields
}

Shots is the register of the kinds of shots, defined on a world's kinds.

func NewShots

func NewShots(w *world.Plugin) *Shots

NewShots is a register of shots over w, for a test without the plugin.

func (*Shots) Define

func (s *Shots) Define(name string, body Body, extra ...comp.Comp)

Define registers the kind of shot named name with body and extra. extra may carry tags and Layers, never the owners' family nor what the kind gives itself.

func (*Shots) Named

func (s *Shots) Named(name string) Ammo

Named is the kind of shot defined as name; an unknown name panics.

type Stateful

type Stateful interface{ Effects(p *Plugin) }

Stateful is a Figure with effects of its own, defined in the Effects section.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL