engine

package
v1.0.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2021 License: Apache-2.0 Imports: 21 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(img, tmp, out *ebiten.Image, blurSize, expandSize int, scale, darken float64)

func BlurImage

func BlurImage(img, tmp, 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 Precache

func Precache() 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 SaveConfig

func SaveConfig() error

SaveConfig writes the current configuration to a file.

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.

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, 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

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

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

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

func (w *World) RespawnPlayer(checkpointName string) 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) 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(s *level.Spawnable, tilePos m.Pos, t *level.Tile) (*Entity, error)

Spawn turns a Spawnable into an Entity.

func (*World) Tile

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

func (*World) TouchEvent

func (w *World) TouchEvent(a *Entity, b *Entity)

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.

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