engine

package
v1.5.220 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
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 BlurExpandImage(name string, img, out *ebiten.Image, blurSize, expandSize int, scale, darken float64)

func BlurImage

func BlurImage(name string, img, out *ebiten.Image, size int, scale, darken, blurFade float64)

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

func LoadConfig() (*flag.Config, error)

LoadConfig loads the current configuration.

func PaletteChanged added in v1.2.141

func PaletteChanged() error

func Precache

func Precache(s *splash.State) (splash.Status, 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.

func ReloadLevel added in v1.3.103

func ReloadLevel() error

func SaveConfig

func SaveConfig() error

SaveConfig writes the current configuration to a file.

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.

func (*Entity) Contents

func (e *Entity) Contents() level.Contents

func (*Entity) Detached

func (e *Entity) Detached() bool

func (*Entity) Name

func (e *Entity) Name() string

func (*Entity) ZIndex

func (e *Entity) ZIndex() int

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

type EntityIncarnation struct {
	ID      level.EntityID
	TilePos m.Pos
}

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

	// DebugPos64 returns the position and velocity for debug purposes, in subpixels.
	DebugPos64() (x int64, y int64, vx int64, vy int64)

	// 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(sp *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
	// 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 colorm.ColorM
	// GlobalColorMSet is true whenever GlobalColorM is set to anything.
	GlobalColorMSet bool
	// 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) Despawn

func (w *World) Despawn(e *Entity)

func (*World) Detach

func (w *World) Detach(e *Entity)

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) Draw

func (w *World) Draw(screen *ebiten.Image, blurFactor float64)

func (*World) EntityIsAlive

func (w *World) EntityIsAlive(incarnation EntityIncarnation) bool

func (*World) FindContents

func (w *World) FindContents(c level.Contents) []*Entity

func (*World) FindName

func (w *World) FindName(name string) []*Entity

func (*World) ForEachEntity

func (w *World) ForEachEntity(f func(e *Entity))

func (*World) Init

func (w *World) Init(saveState int) error

Init brings a world into a working state. Can be called more than once to reset _everything_.

func (*World) Initialized

func (w *World) Initialized() bool

Initialized returns whether Init() has been called on this World before.

func (*World) Load

func (w *World) Load() error

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

func (w *World) LoadTile(p, newPos m.Pos, d m.Delta) *level.Tile

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

func (w *World) LoadTilesForRect(r m.Rect, tp m.Pos)

LoadTilesForRect loads all tiles in the given box (p, d), assuming tile tp is already loaded.

func (*World) LoadTilesForTileBox

func (w *World) LoadTilesForTileBox(tp0, tp1, tp m.Pos)

LoadTilesForTileBox loads all tiles in the given tile based box, assuming tile tp is already loaded.

func (*World) MutateContents

func (w *World) MutateContents(e *Entity, mask, set level.Contents)

MutateContents mutates an entity's contents.

func (*World) MutateContentsBool

func (w *World) MutateContentsBool(e *Entity, mask level.Contents, set bool)

MutateContentsBool mutates an entity's contents.

func (*World) PlayerTouchedCheckpoint

func (w *World) PlayerTouchedCheckpoint(cp *Entity)

func (*World) PreDespawn

func (w *World) PreDespawn()

func (*World) RespawnPlayer

func (w *World) RespawnPlayer(checkpointName string, newGameSection bool) error

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) Save

func (w *World) Save() error

Save saves the current savegame.

func (*World) ScrollPos added in v1.0.183

func (w *World) ScrollPos() m.Pos

func (*World) SetOpaque

func (w *World) SetOpaque(e *Entity, opaque bool)

SetOpaque makes an entity opaque (or not).

func (*World) SetSolid

func (w *World) SetSolid(e *Entity, solid bool)

SetSolid makes an entity solid (or not).

func (*World) SetWarpZoneState

func (w *World) SetWarpZoneState(name string, state bool)

SetWarpZoneState overrides the enabled/disabled state of a warpzone. This state resets on respawn.

func (*World) SetZIndex

func (w *World) SetZIndex(e *Entity, index int)

SetZIndex sets an entity's Z index.

func (*World) Spawn

func (w *World) Spawn(sp *level.Spawnable, tilePos m.Pos, t *level.Tile) (*Entity, error)

Spawn turns a Spawnable into an Entity.

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) Tile

func (w *World) Tile(pos m.Pos) *level.Tile

func (*World) TouchEvent

func (w *World) TouchEvent(a *Entity, bs []*Entity)

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.

func (*World) Update

func (w *World) Update() error

Jump to

Keyboard shortcuts

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