Documentation ¶
Index ¶
- Constants
- func BlurExpandImage(img, tmp, out *ebiten.Image, blurSize, expandSize int, scale, darken float64)
- func BlurImage(img, tmp, out *ebiten.Image, size int, scale, darken, blurFade float64)
- func DrawPolyLine(src *ebiten.Image, thickness float64, points []m.Pos, img *ebiten.Image, ...)
- func LoadConfig() (*flag.Config, error)
- func Precache() error
- func RegisterEntityType(t EntityImpl)
- func SaveConfig() error
- type Entity
- type EntityImpl
- type EntityIncarnation
- type PlayerEntityImpl
- type Precacher
- type TraceOptions
- type TraceResult
- type TraceScore
- type World
- func (w *World) Despawn(e *Entity)
- func (w *World) Detach(e *Entity)
- func (w *World) Draw(screen *ebiten.Image)
- func (w *World) EntityIsAlive(incarnation EntityIncarnation) bool
- func (w *World) FindContents(c level.Contents) []*Entity
- func (w *World) FindName(name string) []*Entity
- func (w *World) ForEachEntity(f func(e *Entity))
- func (w *World) Init(saveState int) error
- func (w *World) Initialized() bool
- func (w *World) Load() error
- func (w *World) LoadTile(p, newPos m.Pos, d m.Delta) *level.Tile
- func (w *World) LoadTilesForRect(r m.Rect, tp m.Pos)
- func (w *World) LoadTilesForTileBox(tp0, tp1, tp m.Pos)
- func (w *World) MutateContents(e *Entity, mask, set level.Contents)
- func (w *World) MutateContentsBool(e *Entity, mask level.Contents, set bool)
- func (w *World) PlayerTouchedCheckpoint(cp *Entity)
- func (w *World) RespawnPlayer(checkpointName string) error
- func (w *World) Save() error
- func (w *World) SetOpaque(e *Entity, opaque bool)
- func (w *World) SetSolid(e *Entity, solid bool)
- func (w *World) SetWarpZoneState(name string, state bool)
- func (w *World) SetZIndex(e *Entity, index int)
- func (w *World) Spawn(s *level.Spawnable, tilePos m.Pos, t *level.Tile) (*Entity, error)
- func (w *World) Tile(pos m.Pos) *level.Tile
- func (w *World) TouchEvent(a *Entity, b *Entity)
- func (w *World) TraceBox(from m.Rect, to m.Pos, o TraceOptions) TraceResult
- func (w *World) TraceLine(from, to m.Pos, o TraceOptions) TraceResult
- func (w *World) Update() error
Constants ¶
const ( // GameWidth is the width of the displayed game area. GameWidth = 640 // GameHeight is the height of the displayed game area. GameHeight = 360 // GameTPS is the game ticks per second. GameTPS = 60 // MinEntitySize is the smallest allowed entity size. MinEntitySize = 8 )
Variables ¶
This section is empty.
Functions ¶
func BlurExpandImage ¶
func DrawPolyLine ¶
func DrawPolyLine(src *ebiten.Image, thickness float64, points []m.Pos, img *ebiten.Image, color color.Color, texM *ebiten.GeoM, options *ebiten.DrawTrianglesOptions)
DrawPolyLine draws a polygon line for the given points. The screen coords are mapped to texcoords using texM (NOT VICE VERSA).
func LoadConfig ¶
LoadConfig loads the current configuration.
func RegisterEntityType ¶
func RegisterEntityType(t EntityImpl)
RegisterEntityType adds an entity type to the spawn system. To be called from init() functions of entity implementations.
Types ¶
type Entity ¶
type Entity struct { Incarnation EntityIncarnation Rect m.Rect BorderPixels int // Border applied to ALL sides. Used for entity tracing only. Transform m.Orientation // Possibly needed for initialization. RequireTiles bool // Entity requires tiles to be loaded. // Info needed for rendering. Orientation m.Orientation Image *ebiten.Image RenderOffset m.Delta ResizeImage bool // Conceptually incompatible with RenderOffset. Alpha float64 ColorAdd [4]float64 ColorMod [4]float64 // Entity's own state. Impl EntityImpl // contains filtered or unexported fields }
An Entity is an object that exists in the game.
type EntityImpl ¶
type EntityImpl interface { // Spawn initializes the entity based on a Spawnable. // Receiver will be a zero struct of the entity type. // Will usually remember a reference to the World and Entity. // ID, Pos, Size and Orientation of the entity will be preset but may be changed. Spawn(w *World, s *level.Spawnable, e *Entity) error // Despawn notifies the entity that it will be deleted. Despawn() // Update asks the entity to update its state. Update() // Touch notifies the entity that it was hit by another entity moving. Touch(other *Entity) }
type EntityIncarnation ¶
EntityIncarnation represents a specific incarnation of an entity. Entities spawn more than once if their tile is seen more than once.
func (EntityIncarnation) IsValid ¶
func (e EntityIncarnation) IsValid() bool
type PlayerEntityImpl ¶
type PlayerEntityImpl interface { EntityImpl // EyePos is the location of the eye in world coordinates. EyePos() m.Pos // LookPos is the desired screen center position. LookPos() m.Pos // Respawned() notifies the entity that the world respawned it. Respawned() }
PlayerEntityImpl defines some additional methods player entities must have.
type Precacher ¶
type Precacher interface { // Precache gets called during level loading to preload anything the entity may need. Precache(s *level.Spawnable) error }
Some entities fulfill PrecacheImpl. These will get precached.
type TraceOptions ¶
type TraceOptions struct { // Contents is the OR'd set of contents to stop at (whether we want to do a visibility or collision trace). Contents level.Contents // If NoTiles is set, we ignore hits against tiles. NoTiles bool // If NoEntities is set, we ignore hits against entities. NoEntities bool // IgnoreEnt is the entity that shall be ignored when tracing. IgnoreEnt *Entity // ForEnt is the entity on whose behalf the trace is done. ForEnt *Entity // If LoadTiles is set, not yet known tiles will be loaded in by the trace operation. // Otherwise hitting a not-yet-loaded tile will end the trace. // Only valid on line traces. LoadTiles bool // If set, the trace path will be collected into this array. Provided here to reduce memory allocation. PathOut *[]m.Pos }
type TraceResult ¶
type TraceResult struct { // EndPos is the pixel the trace ended on (the last nonsolid pixel). EndPos m.Pos // HitDelta is the one-pixel delta that hit the obstacle. HitDelta m.Delta // // HitTilePos is the position of the tile that stopped the trace, if any (in this case, HitTile will also be set). // HitTilePos m.Pos // // HitTile is the tile that stopped the trace, if any. // HitTile *level.Tile // HitEntity is the entity that stopped the trace, if any. HitEntity *Entity // // HitFogOfWar is set if the trace ended by hitting an unloaded tile. // HitFogOfWar bool // Score is a number used to decide which of multiple traces to keep. // Typically related to the trace distance and which entity was hit if any. Score TraceScore }
TraceResult returns the status of a trace operation.
type TraceScore ¶
type TraceScore struct { // TraceDistance is the length of the trace. TraceDistance int // EntityZ is the Z index of the entity hit. EntityZ int // EntityDistance is the distance between entity centers of the traces. // This is used as a tie breaker. EntityDistance int }
TraceScore is a scoring value of a trace.
func (TraceScore) Less ¶
func (s TraceScore) Less(o TraceScore) bool
Less returns whether this score is smaller than the other.
type World ¶
type World struct { // Player is the player entity. Player *Entity // PlayerState is the managed persistent state of the player. PlayerState playerstate.PlayerState // Level is the current tilemap (universal covering with warpZones). Level *level.Level // Frame since last spawn. Used to let the world slowly "fade in". FramesSinceSpawn int // WarpZoneStates is the set of current overrides of warpzone state. // WarpZones can be turned on/off at will, as long as they are offscreen. WarpZoneStates map[string]bool // TimerStarted is set on first input after game launch or reset. TimerStarted bool // TimerStopped is set when game time is paused. TimerStopped bool // MaxVisiblePixels is the max amount of pixels displayed from player origin. MaxVisiblePixels int // ForceCredits is set when we want to jump to credits. ForceCredits bool // GlobalColorM is a color matrix to apply to everything. GlobalColorM ebiten.ColorM // contains filtered or unexported fields }
World represents the current game state including its entities.
func (*World) Detach ¶
Detach detaches an entity from its spawn origin. If the spawn origin is onscreen, this will respawn the entity from there this frame.
func (*World) EntityIsAlive ¶
func (w *World) EntityIsAlive(incarnation EntityIncarnation) bool
func (*World) ForEachEntity ¶
func (*World) Init ¶
Init brings a world into a working state. Can be called more than once to reset _everything_.
func (*World) Initialized ¶
Initialized returns whether Init() has been called on this World before.
func (*World) Load ¶
Load loads the current savegame. If this fails, the world may be in an undefined state; call w.Init() or w.Load() to resume.
func (*World) LoadTile ¶
LoadTile loads the next tile into the current world based on a currently known tile and its neighbor. Respects and applies warps.
func (*World) LoadTilesForRect ¶
LoadTilesForRect loads all tiles in the given box (p, d), assuming tile tp is already loaded.
func (*World) LoadTilesForTileBox ¶
LoadTilesForTileBox loads all tiles in the given tile based box, assuming tile tp is already loaded.
func (*World) MutateContents ¶
MutateContents mutates an entity's contents.
func (*World) MutateContentsBool ¶
MutateContentsBool mutates an entity's contents.
func (*World) PlayerTouchedCheckpoint ¶
func (*World) RespawnPlayer ¶
SpawnPlayer spawns the player in a newly initialized world. As a side effect, it unloads all tiles. Spawning at checkpoint "" means the initial player location.
func (*World) SetWarpZoneState ¶
SetWarpZoneState overrides the enabled/disabled state of a warpzone. This state resets on respawn.
func (*World) TouchEvent ¶
TouchEvent notifies both entities that they touched the other.
func (*World) TraceBox ¶
func (w *World) TraceBox(from m.Rect, to m.Pos, o TraceOptions) TraceResult
TraceBox moves from x,y size sx,sy by dx,dy in pixel coordinates.
func (*World) TraceLine ¶
func (w *World) TraceLine(from, to m.Pos, o TraceOptions) TraceResult
TraceLine moves from x,y by dx,dy in pixel coordinates.