Documentation
¶
Overview ¶
Package weapon is Linefire's weapon catalogue: what each weapon does, how often it can be used, what its shots look like and what they cost the target.
It holds the DEFINITIONS, not the firing. How a shot is spawned, aimed and resolved depends on the world it is fired into — a cave with walls, or a desktop overlay — so that stays with each game. What must not differ is the weapon itself: a missile has to hit as hard and reload as slowly in Linefire Skirmish as it does here, or the two are different games wearing the same art.
The numbers are in Linefire's units: world units, frames at 60 TPS, and hull points. A consumer on a different scale should convert them rather than reinterpret them.
Index ¶
Constants ¶
const ( // PoolMax is the default capacity. At the catalogue's prices that is dozens of // missiles, or about a minute of held beam. PoolMax = 1000 // RegenEvery is how many ticks pass before the pool recovers one point. Slow // on purpose: it covers a lull between fights so a ship is never permanently // disarmed, while leaning on the heavy weapons still runs it down. Refilling // properly is what a pickup is for. RegenEvery = 12 // EnergyPerLevel is what each stacked upgrade adds to a shot's price. A plain // front gun is free forever; an upgraded one draws power, which is what makes // the upgrades something to keep fed rather than something to hoard. EnergyPerLevel = 2 // PickupEnergy is what a power-up puts back — a quarter of a full pool, so // collecting is worth a detour without making the budget irrelevant. PickupEnergy = 250 )
const ( CatFront = iota CatMissile CatMine CatLaser CatDevourer )
Catalogue indices: which weapon TYPE, used to key an arsenal or a pickup.
Variables ¶
var Catalog = []Weapon{ CatFront: { Name: "Front Gun", Kind: KindProjectile, Aim: AimForward, Cooldown: 8, Damage: 1, Col: color.RGBA{0xff, 0xf0, 0xc0, 0xff}, Fire: Sound{"shot_soft", 101, 0.3}, Energy: 0, Speed: 9.0, Life: 90, Core: color.RGBA{0xe8, 0xff, 0xff, 0xff}, Glow: color.RGBA{0x80, 0xff, 0xff, 0xff}, Width: 1.6, GlowWidth: 2.0, }, CatMissile: { Name: "Missile", Kind: KindProjectile, Aim: AimCursor, Cooldown: 45, Damage: 4, Col: color.RGBA{0xff, 0xa0, 0x40, 0xff}, Fire: Sound{"shot_launch", 130, 0.5}, Energy: 12, Speed: 7.0, Life: 110, AOE: 70.0, Core: color.RGBA{0xff, 0xa0, 0x40, 0xff}, Glow: color.RGBA{0xff, 0x60, 0x20, 0xff}, Width: 2.4, GlowWidth: 5.0, }, CatMine: { Name: "Mine", Kind: KindMine, Aim: AimDrop, Cooldown: 16, Damage: 5, Col: color.RGBA{0xff, 0x80, 0x30, 0xff}, Fire: Sound{"shot_thunk", 140, 0.45}, Energy: 10, AOE: 64.0, ArmFrames: 45, TriggerRadius: 36.0, MaxLive: 5, }, CatLaser: { Name: "Laser", Kind: KindLaser, Aim: AimCursor, Cooldown: 4, Damage: 1, Col: color.RGBA{0x90, 0xff, 0x90, 0xff}, Fire: Sound{"beam", 150, 0.3}, Energy: 1, Reach: 2000, }, CatDevourer: { Name: "Devourer", Kind: KindDevourer, Aim: AimDrop, Cooldown: 90, Damage: 300, Col: color.RGBA{0xc0, 0x40, 0xff, 0xff}, Fire: Sound{"shot_thunk", 70, 0.7}, Energy: 120, }, }
Catalog is every weapon that can be collected and mounted.
Functions ¶
func Cost ¶ added in v0.0.14
Cost is what one use of w costs at the given stack level: the weapon's own price plus a surcharge for every upgrade riding on the shot.
A free weapon stays free at level zero and only then. That is the whole rule behind stepping down: a ship that cannot pay for its upgraded gun drops a level and fires a cheaper one, all the way back to the plain shot that always works.
Types ¶
type Pool ¶ added in v0.0.13
Pool is a ship's ammunition: one budget that every weapon but the front gun draws from. A single pool rather than a magazine per weapon is deliberate — it is one number to show, one number for a script to read, and it makes the interesting question "which weapon is this fight worth spending on" instead of "which of five counters is empty".
It is meant to last: a full pool is a long fight's worth of heavy fire, so running dry is a consequence of leaning on the big weapons, not a timer.
func NewPool ¶ added in v0.0.13
NewPool returns a full pool of the given capacity; zero or less uses PoolMax.
func (*Pool) Add ¶ added in v0.0.13
Add tops the pool up, never past its capacity. This is what a pickup does.
func (*Pool) CanAfford ¶ added in v0.0.13
CanAfford reports whether the pool covers a cost. A free shot is always affordable, including on an empty pool.
func (*Pool) Fraction ¶ added in v0.0.13
Fraction is how full the pool is, 0 to 1, for a gauge or an instrument reading.
type Sound ¶
Sound names the gion recipe a weapon plays when it fires. An empty Base is silent, which is what the laser wants — it hums on a loop instead.
type Weapon ¶
type Weapon struct {
Name string
Kind Kind
Aim Aim
Cooldown int // frames between uses
Damage int // hull damage (centre damage for an AOE weapon)
Col color.RGBA // floating damage-number colour
Fire Sound
// Energy is what one use costs, drawn from the ship's pool. Zero is free, and
// exactly one weapon is: the front gun. A ship that has run dry can still
// shoot — it just cannot reach for anything heavier, which is the point.
// Harder-hitting weapons cost more, so the pool is a budget over which weapon
// to spend a fight on rather than a timer on shooting at all.
Energy int
// Projectile.
Speed float64
Life int
AOE float64 // explosion radius; 0 = direct hit
Core color.RGBA // shot core colour
Glow color.RGBA // shot glow colour
Width float64 // crisp stroke width, logical px
GlowWidth float64 // glow stroke width, logical px
// Mine.
ArmFrames int
TriggerRadius float64
MaxLive int // cap on this weapon's live mines
// Laser.
Reach float64 // max beam length, world units
}
Weapon is a data-driven weapon definition. The same struct describes the gun, the missile and the mine: a new weapon is new data plus a case in whatever fires it, not a new fire function.