level

package
v1.0.0-rc.104 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TileSize is the size of each tile graphics.
	TileSize = 16
)

Variables

View Source
var AllCheckpointDirs = []m.Delta{
	m.North(),
	m.East(),
	m.South(),
	m.West(),
}

Functions

func FetchTileset

func FetchTileset(ts *tmx.TileSet) error

func ParseImageSrcByOrientation

func ParseImageSrcByOrientation(defaultSrc string, properties map[string]string) (map[m.Orientation]string, error)

ParseImageSrcByOrientation parses the imgSrcByOrientation map.

func ResolveImage

func ResolveImage(transform, orientation m.Orientation, defaultImageSrc string, imageSrcByOrientation map[m.Orientation]string) (string, m.Orientation)

ResolveImage applies the given imageSrcByOrientation map.

Types

type CheckpointEdge

type CheckpointEdge struct {
	Other    string
	Forward  bool
	Optional bool
}

type CheckpointLocation

type CheckpointLocation struct {
	MapPos       m.Pos
	NextByDir    map[m.Delta]CheckpointEdge // Note: two sided.
	NextDeadEnds []CheckpointEdge
}

type CheckpointLocations

type CheckpointLocations struct {
	Locs map[string]*CheckpointLocation
	Rect m.Rect
}

type Contents

type Contents int

Contents indicates what kind of tiles/objects we want to hit.

const (
	NoContents          Contents = 0
	OpaqueContents      Contents = 1
	PlayerSolidContents Contents = 2
	ObjectSolidContents Contents = 4
	SolidContents       Contents = PlayerSolidContents | ObjectSolidContents
)

func (Contents) Empty

func (c Contents) Empty() bool

func (Contents) ObjectSolid

func (c Contents) ObjectSolid() bool

func (Contents) Opaque

func (c Contents) Opaque() bool

func (Contents) PlayerSolid

func (c Contents) PlayerSolid() bool

type EntityID

type EntityID int

EntityID represents an unique ID of an entity.

const InvalidEntityID EntityID = 0

InvalidEntityID is an ID that cannot be used in Tiled. Tiled's first entity has ID 1.

func (EntityID) IsValid

func (e EntityID) IsValid() bool

IsValid returns whether an EntityID is valid for an actual entity.

type JSONCheckpointGraph

type JSONCheckpointGraph struct {
	Objects []JSONCheckpointObject
}

type JSONCheckpointObject

type JSONCheckpointObject struct {
	Name string
	Pos  string
}

func (*JSONCheckpointObject) MapPos

func (o *JSONCheckpointObject) MapPos() (m.Pos, error)

type Level

type Level struct {
	Player                *Spawnable
	Checkpoints           map[string]*Spawnable
	TnihSignsByCheckpoint map[string][]*Spawnable
	CheckpointLocations   *CheckpointLocations
	SaveGameVersion       int
	CreditsMusic          string
	Hash                  uint64 `hash:"-"`
	// contains filtered or unexported fields
}

Level is a parsed form of a loaded level.

func Load

func Load(filename string) (*Level, error)

func (*Level) Clone

func (l *Level) Clone() *Level

Clone clones the given Level to a new Level struct sharing no persistent state data.

func (*Level) ForEachTile

func (l *Level) ForEachTile(f func(pos m.Pos, t *LevelTile))

ForEachTile iterates over all tiles in the level.

func (*Level) LoadCheckpointLocations

func (l *Level) LoadCheckpointLocations(filename string) (*CheckpointLocations, error)

func (*Level) LoadGame

func (l *Level) LoadGame(save *SaveGame) error

LoadGame loads the given SaveGame into the map. Note that when this returns an error, the SaveGame might have been partially loaded and the world may need to be reset.

func (*Level) SaveGame

func (l *Level) SaveGame() (*SaveGame, error)

SaveGame returns the current state as a SaveGame.

func (*Level) Tile

func (l *Level) Tile(pos m.Pos) *LevelTile

Tile returns the tile at the given position.

func (*Level) VerifyHash

func (l *Level) VerifyHash() error

VerifyHash returns an error if the level hash changed.

type LevelTile

type LevelTile struct {
	Tile      Tile
	WarpZones []*WarpZone
	Valid     bool
}

LevelTile is a single tile in the level.

type PersistentState

type PersistentState map[string]string

PersistentState is how entities retain values across loading/unloading and in save games.

type SaveGame

type SaveGame struct {
	SaveGameDataV1
	InfoHash  uint64
	StateHash uint64

	// Legacy hash for v0 save games.
	Hash uint64 `json:",omitempty"`
}

SaveGame is the data structure we save game state with. It contains all needed (in addition to loading the level) to reset to the last visited checkpoint. Separate hashes govern the info parts and the state itself so demo regression testing can work across version changes.

type SaveGameData

type SaveGameData struct {
	State        map[EntityID]PersistentState
	LevelVersion int
	LevelHash    uint64
}

SaveGameData is a not-yet-hashed SaveGame.

type SaveGameDataV1

type SaveGameDataV1 struct {
	State        map[EntityID]PersistentState `hash:"-"`
	GameVersion  string
	LevelVersion int
	LevelHash    uint64
}

SaveGameDataV1 is a not-yet-hashed SaveGame.

type Spawnable

type Spawnable struct {
	ID EntityID

	// Type.
	EntityType string

	// Location.
	LevelPos    m.Pos
	RectInTile  m.Rect
	Orientation m.Orientation

	// Other properties.
	Properties map[string]string

	// Persistent entity state, if any, shall be kept in this map.
	PersistentState map[string]string `hash:"-"`
}

A Spawnable is a blueprint to create an Entity.

func (*Spawnable) Clone

func (sp *Spawnable) Clone() *Spawnable

type Tile

type Tile struct {
	// Info needed for gameplay.
	Contents   Contents
	Spawnables []*Spawnable // NOTE: not adjusted for transform!

	// Info needed for loading more tiles.
	LevelPos        m.Pos
	Transform       m.Orientation
	VisibilityFlags VisibilityFlags

	// Info needed for rendering.
	Orientation m.Orientation
	ImageSrc    string

	// Debug info.
	LoadedFromNeighbor m.Pos
	// contains filtered or unexported fields
}

A Tile is a single game tile.

func (*Tile) ResolveImage

func (t *Tile) ResolveImage()

ResolveImage applies imageSrcByOrientation data to Image, and possibly changes Orientation when it did.

type VisibilityFlags

type VisibilityFlags int
const (
	FrameVis  VisibilityFlags = 1
	TracedVis VisibilityFlags = 2
)

type WarpZone

type WarpZone struct {
	Name       string
	Invert     bool
	Switchable bool
	PrevTile   m.Pos
	ToTile     m.Pos
	Transform  m.Orientation
}

WarpZone represents a warp tile. Whenever anything enters this tile, it gets moved to "to" and the direction transformed by "transform". For the game to work, every warpZone must be paired with an exact opposite elsewhere. This is ensured at load time. Warpzones can be temporarily toggled by name; this state is lost on checkpoint restore.

Jump to

Keyboard shortcuts

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