entity

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 5 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 entity is what every entity of a world carries: its Base (where it is, Position; how it moves, Velocity; its kind and what the space may do with it), its planes (Layers), in a world with heights its place in height (Z), where it looks from (Eye), the Drift it is carried at under gravity, how it lies flat (Lie) and how it casts its shadow ([Shadow]). No entity moves further in a tick than StepReach of its own shorter side.

Names and groups

An entity may be called something: its [Label] holds a name, its alone, and a group it is in with others. A command says whom it is for with a [Whom]: [Named], the entities bearing those names, [Group], all those in the groups, [ID], the entities of those identifiers, or [World], the world's own entity.

The package is gram's core, imported by no plugin it needs; the world re-exports its components, so a game and the plugins say world.Base, world.Position and kin.

Index

Constants

View Source
const StepReach = 0.5

StepReach is how far an entity may travel in one tick, as a share of its own shorter side. Half a body keeps two entities from ever crossing centres unseen.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	Pos    Position
	Vel    Velocity
	TypeID kind.ID
	Caps   aabbworld.Capability
}

Base is what every entity in the world is made of: where it is, how it moves, which kind it was spawned from and what the space may do with it.

type Drift

type Drift struct{ X, Y, Z float32 }

Drift is the velocity an entity is carried at beyond its walk (falling, thrown), in world units a second: X and Y along the ground, Z its rise. Gravity writes it.

type Eye

type Eye struct{ Height, Angle, Vertical, Tilt float32 }

Eye is where an entity looks from and how wide: Height above its bottom (Z.Altitude), zero its top; Angle the whole field of view across, radians; Vertical the field up and down, radians, zero every height; Tilt how far the eye is turned up, radians, down negative, which Vertical alone limits (a rider's camera writes it).

func (Eye) Level

func (e Eye) Level(z Z) float32

Level is the height the eye looks from for an entity standing as z says: Height above its bottom, its top for none.

func (Eye) Within

func (e Eye) Within(lo, hi float32) bool

Within reports whether something spanning the elevations lo to hi from the eye, radians up, lies in its vertical field; everything does for a Vertical of zero.

type Layers

type Layers uint8

Layers is the planes an entity is on, one bit each: two entities meet only where they share a bit, and one without Layers, or with none set, is on every plane. Collision and sight read it.

func LayersOf

func LayersOf(p *Layers) Layers

LayersOf is the Layers an entity carries, every plane for one carrying none.

func (Layers) Meets

func (l Layers) Meets(o Layers) bool

Meets reports whether the two are on a common plane, none set standing for all of them.

type Lie

type Lie struct {
	Length, Width float32
	Ahead         float32
	Edged         bool
	Edge          float32
}

Lie is how an entity lying flat lies: a rectangle Length along its heading (Velocity.Dir) and Width across, its middle Ahead of its box's, with edges Edge high along its long sides while Edged. Zero, it lies over its box.

func (Lie) Corners

func (l Lie) Corners(middle, dir geom.Vec) [4]geom.Vec

Corners are the corners of the rectangle the entity lies over, its box's middle at middle and headed dir, as a sprite authored facing east is laid over it: top-left, top-right, bottom-left, bottom-right.

type Position

type Position struct {
	plane.AABB
}

Position is an entity's world-space rectangle.

func (Position) Center

func (p Position) Center() geom.Vec

Center is the middle of the entity's rectangle.

func (Position) MaxSpeed

func (p Position) MaxSpeed(tps int) float32

MaxSpeed is the fastest this entity can travel, in world units a second, at tps ticks a second.

func (Position) MaxStep

func (p Position) MaxStep() float32

MaxStep is the furthest this entity moves in a single tick, whatever its Velocity says.

type Stand added in v0.22.0

type Stand struct{ Length, Width float32 }

Stand is the rectangle a thing standing turned covers on the ground: Length along its heading (Velocity.Dir) and Width across, round the middle of its box. Zero, it stands over its box.

func (Stand) Corners added in v0.22.0

func (s Stand) Corners(middle, dir geom.Vec) [4]geom.Vec

Corners are the corners of the rectangle, the box's middle at middle and headed dir, in the order of Lie's.

type Velocity

type Velocity struct {
	Dir   geom.Vec
	Value float32
	Side  float32
}

Velocity is an entity's heading (Dir, a unit vector, zero when stationary), speed (Value, world units a second; under zero it backs away, still facing Dir) and Side, its speed across Dir, to its right (the screen's y down) over zero: a strafe, still facing Dir.

func (Velocity) Delta

func (v Velocity) Delta() geom.Vec

Delta returns Velocity's current per-axis rate: Dir scaled by Value, and Side across it.

func (*Velocity) SetDelta

func (v *Velocity) SetDelta(d geom.Vec)

SetDelta sets Dir and Value from a per-axis rate, the strafe gone; an entity backing away (Value under zero) goes on backing, facing against the rate. A rate that is nothing against the speed held (what a wall leaves of it) is a stop, facing on.

func (*Velocity) Slow

func (v *Velocity) Slow(d geom.Vec)

Slow keeps Dir and takes of a per-axis rate only what runs along it, never past a stop.

type Z

type Z struct{ Altitude, Height, Step float32 }

Z is an entity's place in height: Altitude its bottom, Height its rise above that, Step how high it steps up without a leap (0: a quarter of its Height). Only a world with heights carries it; one with no Height spans every height.

func (Z) Reach

func (z Z) Reach() float32

Reach is how high the entity steps up: its Step, else a quarter of its Height.

func (Z) Top

func (z Z) Top() float32

Top is the entity's highest point.

Directories

Path Synopsis
Package kind is how a game says what its entities are.
Package kind is how a game says what its entities are.

Jump to

Keyboard shortcuts

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