Documentation ¶
Index ¶
- Constants
- func BlurExpandImage(name string, img, out *ebiten.Image, blurSize, expandSize int, ...)
- func BlurImage(name string, img, 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 PaletteChanged() error
- func Precache(s *splash.State) (splash.Status, error)
- func RegisterEntityType(t EntityImpl)
- func SaveConfig() error
- type Entity
- type EntityImpl
- type EntityIncarnation
- type PlayerEntityImpl
- type PreDespawner
- type Precacher
- type TraceOptions
- type TraceResult
- type World
- func (w *World) AssumeChanged()
- func (w *World) Despawn(e *Entity)
- func (w *World) Detach(e *Entity)
- func (w *World) Draw(screen *ebiten.Image, blurFactor float64)
- 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) PreDespawn()
- func (w *World) RespawnPlayer(checkpointName string, newGameSection bool) error
- func (w *World) Save() error
- func (w *World) ScrollPos() m.Pos
- 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(sp *level.Spawnable, tilePos m.Pos, t *level.Tile) (*Entity, error)
- func (w *World) SpawnDetached(sp *level.SpawnableProps, rect m.Rect, orientation m.Orientation, by *Entity) (*Entity, error)
- func (w *World) Tile(pos m.Pos) *level.Tile
- func (w *World) TouchEvent(a *Entity, bs []*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 PaletteChanged ¶ added in v1.2.141
func PaletteChanged() error
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 { // Info needed for management. Incarnation EntityIncarnation SpawnTilesGrowth m.Delta 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, sp *level.SpawnableProps, 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 PreDespawner ¶
type PreDespawner interface {
// PreDespawn gets called when the game enters the menu. After this, either Despawn or Update will happen eventually.
PreDespawn()
}
Some entities get a pre-despawn notification.
type Precacher ¶
type Precacher interface { // Precache gets called during level loading to preload anything the entity may need. Precache(id level.EntityID, sp *level.SpawnableProps) 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 // HitEntities are all the entities that stopped the trace simultaneously, if any. // They are sorted in decreasing order of closeness to the player; be aware that some code will only consider the first member. HitEntities []*Entity }
TraceResult returns the status of a trace operation.
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. Reset on every frame. GlobalColorM ebiten.ColorM // contains filtered or unexported fields }
World represents the current game state including its entities.
func (*World) AssumeChanged ¶ added in v1.2.331
func (w *World) AssumeChanged()
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) PreDespawn ¶
func (w *World) PreDespawn()
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) SpawnDetached ¶ added in v1.0.140
func (w *World) SpawnDetached(sp *level.SpawnableProps, rect m.Rect, orientation m.Orientation, by *Entity) (*Entity, error)
SpawnDetached spawns a detached new entity. Note that it will inherit the spawning entity's transform; sp.Orientation should be set to the same as the transform if one wants to undo that.
func (*World) TouchEvent ¶
TouchEvent notifies both entities that they touched the other. nil entities will be skipped as LHS of touches, and if bs is empty, it's treated as touching a nil (which inidcates touching world).
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.