res

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buildable

type Buildable struct {
	Grid[uint16]
}

Buildable resource

func NewBuildable

func NewBuildable(w, h int) Buildable

func (*Buildable) NeighborsMask

func (b *Buildable) NeighborsMask(x, y int) (terr.Directions, terr.Directions)

type EditorMode added in v0.2.0

type EditorMode struct {
	IsEditor bool
}

EditorMode resource, indicating editor mode.

type EntityFactory

type EntityFactory struct {
	// contains filtered or unexported fields
}

EntityFactory is a helper to create game entities.

func NewEntityFactory

func NewEntityFactory(world *ecs.World) EntityFactory

NewEntityFactory creates a new EntityFactory for a given world.

func (*EntityFactory) RemoveLandUse

func (f *EntityFactory) RemoveLandUse(world *ecs.World, x, y int)

RemoveLandUse removes land use from a given position, and updates the game grids.

func (*EntityFactory) Set

func (f *EntityFactory) Set(world *ecs.World, x, y int, value terr.Terrain, randSprite uint16, randomize bool) ecs.Entity

Set creates an entity of the given terrain type, placing it in the world and updating the game grids.

func (*EntityFactory) SetBuildable

func (f *EntityFactory) SetBuildable(x, y, r int, build bool)

SetBuildable updates the build-ability grid. Only used for initialization, not required when using EntityFactory.Set or EntityFactory.RemoveLandUse.

type Fonts

type Fonts struct {
	Default font.Face
	Title   font.Face
}

Fonts resource for access to UI fonts.

func NewFonts

func NewFonts(fSys fs.FS) Fonts

type GameSpeed

type GameSpeed struct {
	// Is the game paused?
	Pause bool
	// Game speed as an exponent for base 2. s = 2^Speed
	Speed int8
	// Minimum game speed, as an exponent for base 2.
	MinSpeed int8
	// Maximum game speed, as an exponent for base 2.
	MaxSpeed int8
}

GameSpeed resource.

type GameTick

type GameTick struct {
	// Current update tick. Stops when the game is paused.
	Tick int64
	// Current render tick. Does not stop when the game is paused.
	RenderTick int64
}

GameTick resource.

type Grid

type Grid[T comparable] struct {
	// contains filtered or unexported fields
}

Grid data structure

func NewGrid

func NewGrid[T comparable](width, height int) Grid[T]

NewGrid returns a new Grid.

func (*Grid[T]) Clamp

func (g *Grid[T]) Clamp(x, y int) (int, int)

Clamp coordinates to be inside the grid.

func (*Grid[T]) Contains

func (g *Grid[T]) Contains(x, y int) bool

Contains returns whether the grid contains the given cell.

func (*Grid[T]) Fill

func (g *Grid[T]) Fill(value T)

Fill the grid with a value.

func (*Grid[T]) Get

func (g *Grid[T]) Get(x, y int) T

Get a value from the Grid.

func (*Grid[T]) GetPointer

func (g *Grid[T]) GetPointer(x, y int) *T

Get a pointer to a value from the Grid.

func (*Grid[T]) Height

func (g *Grid[T]) Height() int

Height of the Grid.

func (*Grid[T]) MarshalJSON

func (g *Grid[T]) MarshalJSON() ([]byte, error)

func (*Grid[T]) Set

func (g *Grid[T]) Set(x, y int, value T)

Set a value in the grid.

func (*Grid[T]) UnmarshalJSON

func (g *Grid[T]) UnmarshalJSON(data []byte) error

func (*Grid[T]) Width

func (g *Grid[T]) Width() int

Width of the Grid.

type LandUse

type LandUse struct {
	TerrainGrid
}

LandUse resource

func NewLandUse

func NewLandUse(w, h int) LandUse

type LandUseEntities

type LandUseEntities struct {
	Grid[ecs.Entity]
}

LandUseEntities resource

type Mouse

type Mouse struct {
	// whether the mouse is inside the game window.
	IsInside bool
}

Mouse resource.

type Production

type Production struct {
	// Current production, indexed by [resource.Resource].
	Prod []int
	// Current consumption, indexed by [resource.Resource].
	Cons []int
}

Production, accumulated globally.

func NewProduction

func NewProduction() Production

NewProduction creates a new Production resource.

func (*Production) Reset

func (p *Production) Reset()

Reset all production and consumption zo zero.

type RandomTerrains added in v0.2.0

type RandomTerrains struct {
	Terrains       []terr.Terrain
	AllowRemove    []bool
	TotalAvailable int
	TotalPlaced    int
}

type Rules

type Rules struct {
	// World extent in X and Y direction, in number of tiles.
	WorldSize int
	// Initial build radius around the starting position.
	InitialBuildRadius int
	// Initial population limit.
	InitialPopulation int
	// Initial number of placable terrains.
	InitialRandomTerrains int
	// Number of random terrains/cards.
	RandomTerrainsCount int
	// List of terrains to draw cards from.
	RandomTerrains []terr.Terrain
	// Initial resources of the player.
	InitialResources []int
	// Probability of special cards/terrains that can be placed over existing terrain.
	SpecialCardProbability float64
}

Rules resource, holding game rules read from JSON.

func NewRules

func NewRules(f fs.FS, file string) Rules

NewRules reads rules from the given file.

type SaveEvent

type SaveEvent struct {
	// Whether the save button was clicked in this tick.
	ShouldSave bool
	// Whether the game should quit and show the main menu.
	ShouldQuit bool
	// Whether the save as map button was clicked in this tick.
	ShouldSaveMap bool
}

SaveEvent resource

type SaveTime added in v0.2.0

type SaveTime struct {
	Time time.Time
}

SaveTime resource, containing the time when the game was saved.

type Screen added in v0.2.0

type Screen struct {
	// The screen image.
	Image *ebiten.Image
	// Current screen width.
	Width int
	// Current screen height.
	Height int
}

Screen resource for drawing.

type Selection

type Selection struct {
	// Selected terrain type.
	BuildType terr.Terrain
	// ID of the selected button.
	ButtonID int
	// Random sprite index of the selected button.
	RandSprite uint16
	// Whether a new random sprite index should be draw on placement.
	Randomize bool
	// Whether a special tile has been selected.
	AllowRemove bool
}

Selection from the build toolbar.

func (*Selection) Reset

func (s *Selection) Reset()

Reset to select nothing.

func (*Selection) SetBuild

func (s *Selection) SetBuild(build terr.Terrain, button int, randSprite uint16, randomize, allowRemove bool)

SetBuild sets all fields to the given selection.

type Sprites

type Sprites struct {
	// Tile width for rendering.
	TileWidth int
	// Tile height for rendering.
	TileHeight int
	// Game background color
	Background color.RGBA
	// UI text color
	TextColor color.RGBA
	// UI text color for highlight/warning
	TextHighlightColor color.RGBA
	// contains filtered or unexported fields
}

Sprites holds all tileset data.

func NewSprites

func NewSprites(fSys fs.FS, dir, tileSet string) Sprites

NewSprites creates a new Sprites resource from the given tileset folder.

func (*Sprites) Get

func (s *Sprites) Get(idx int) *ebiten.Image

Get returns the sprite image for an index.

func (*Sprites) GetIndex

func (s *Sprites) GetIndex(name string) int

GetIndex returns the sprite index for a sprite or terrain ID.

func (*Sprites) GetInfo

func (s *Sprites) GetInfo(idx int) *util.Sprite

GetInfo returns the sprite info for an index.

func (*Sprites) GetMultiTileIndex

func (s *Sprites) GetMultiTileIndex(idx int, dirs terr.Directions, frame int, rand int) int

GetMultiTileTerrainIndex returns the sprite index for an index, using multitile.

func (*Sprites) GetMultiTileTerrainIndex

func (s *Sprites) GetMultiTileTerrainIndex(t terr.Terrain, dirs terr.Directions, frame int, rand int) int

GetMultiTileTerrainIndex returns the sprite index for a terrain ID, using multitile.

func (*Sprites) GetRand

func (s *Sprites) GetRand(idx int, frame int, rand int) *ebiten.Image

GetRand returns the sprite image for an index, with animation and random variations.

func (*Sprites) GetSprite

func (s *Sprites) GetSprite(idx int) *ebiten.Image

GetSprite returns the sprite image for an index, including sub-index.

func (*Sprites) GetTerrainIndex

func (s *Sprites) GetTerrainIndex(t terr.Terrain) int

GetTerrainIndex returns the sprite index for a terrain ID.

type Stock

type Stock struct {
	// Total storage capacity, indexed by [resource.Resource].
	Cap []int
	// Total storage, indexed by [resource.Resource].
	Res []int
	// Total production ever delivered to storage, indexed by [resource.Resource].
	Total []int

	// Total population.
	Population int
	// Total population limit.
	MaxPopulation int
}

Stock resource, holding global stock information.

func NewStock

func NewStock(initial []int) Stock

NewStock creates a new Stock resource with the given initial resources.

func (*Stock) AddResources added in v0.2.0

func (s *Stock) AddResources(res resource.Resource, amount int)

func (*Stock) CanPay

func (s *Stock) CanPay(cost []terr.ResourceAmount) bool

CanPay checks whether there are sufficient resources in the stock to pay the given amounts.

func (*Stock) Pay

func (s *Stock) Pay(cost []terr.ResourceAmount)

Pay the given amounts be subtracting them from the stock.

type Terrain

type Terrain struct {
	TerrainGrid
}

Terrain resource

func NewTerrain

func NewTerrain(w, h int) Terrain

type TerrainEntities

type TerrainEntities struct {
	Grid[ecs.Entity]
}

TerrainEntities resource

type TerrainGrid

type TerrainGrid struct {
	Grid[terr.Terrain]
}

func (*TerrainGrid) CountNeighbors4

func (g *TerrainGrid) CountNeighbors4(x, y int, tp terr.Terrain) int

func (*TerrainGrid) CountNeighbors8

func (g *TerrainGrid) CountNeighbors8(x, y int, tp terr.Terrain) int

func (*TerrainGrid) CountNeighborsMask4

func (g *TerrainGrid) CountNeighborsMask4(x, y int, tp terr.Terrains) int

func (*TerrainGrid) CountNeighborsMask8

func (g *TerrainGrid) CountNeighborsMask8(x, y int, tp terr.Terrains) int

func (*TerrainGrid) NeighborsMask

func (g *TerrainGrid) NeighborsMask(x, y int, tp terr.Terrain) terr.Directions

func (*TerrainGrid) NeighborsMaskMulti

func (g *TerrainGrid) NeighborsMaskMulti(x, y int, tp terr.Terrains) terr.Directions

func (*TerrainGrid) NeighborsMaskMultiReplace

func (g *TerrainGrid) NeighborsMaskMultiReplace(x, y int, tp terr.Terrains, rx, ry int, rt terr.Terrain) terr.Directions

type UI

type UI struct {
	// contains filtered or unexported fields
}

UI resource.Represents the complete game UI.

func NewUI

func NewUI(world *ecs.World,
	selection *Selection, fonts *Fonts, sprts *Sprites,
	randomTerrains *RandomTerrains, save *SaveEvent, editor *EditorMode) UI

func (*UI) ClearSelection

func (ui *UI) ClearSelection()

func (*UI) CreateRandomButtons

func (ui *UI) CreateRandomButtons(randomTerrains int)

func (*UI) DisableButton added in v0.2.0

func (ui *UI) DisableButton(id terr.Terrain, message string)

func (*UI) Draw added in v0.2.0

func (ui *UI) Draw(screen *ebiten.Image)

func (*UI) EnableButton added in v0.2.0

func (ui *UI) EnableButton(id terr.Terrain)

func (*UI) MouseInside

func (ui *UI) MouseInside(x, y int) bool

func (*UI) ReplaceAllButtons

func (ui *UI) ReplaceAllButtons(rules *Rules)

func (*UI) ReplaceButton

func (ui *UI) ReplaceButton(stock *Stock, rules *Rules, randTerrains *RandomTerrains, renderTick int64, target stdimage.Point) bool

func (*UI) SetPopulationLabel

func (ui *UI) SetPopulationLabel(text string, warning bool)

func (*UI) SetRandomTilesLabel added in v0.2.0

func (ui *UI) SetRandomTilesLabel(text string)

func (*UI) SetResourceLabel

func (ui *UI) SetResourceLabel(id resource.Resource, text string, warning bool)

func (*UI) SetSpeedLabel

func (ui *UI) SetSpeedLabel(text string)

func (*UI) SetStatusLabel added in v0.2.0

func (ui *UI) SetStatusLabel(text string)

func (*UI) SetTimerLabel

func (ui *UI) SetTimerLabel(text string)

func (*UI) UI

func (ui *UI) UI() *ebitenui.UI

func (*UI) Update added in v0.2.0

func (ui *UI) Update()

type UpdateInterval

type UpdateInterval struct {
	// The interval between updates of entities, in game ticks. Usually equal to TPS.
	Interval int64
	// Number of intervals used in (production) countdowns. Usually 60, resulting in 1 minute.
	Countdown int
}

UpdateInterval resource.

type View

type View struct {
	// Tile width and height, for convenient access.
	TileWidth, TileHeight int
	// Current global coordinates of the top-left corner of the screen, in pixels.
	X, Y int
	// Y offset used to determine the mouse position.
	MouseOffset int
	// Current zoom factor.
	Zoom float64
}

View resource, holding the game's view state.

func NewView

func NewView(tileWidth, tileHeight int) View

func (*View) Bounds

func (v *View) Bounds(w, h int) image.Rectangle

func (*View) BoundsToGlobal

func (v *View) BoundsToGlobal(b *WorldBounds) image.Rectangle

func (*View) Center

func (v *View) Center(cell image.Point, screenWidth, screenHeight int)

func (*View) GlobalToTile

func (v *View) GlobalToTile(x, y int) image.Point

func (*View) MapBounds

func (v *View) MapBounds(screenWidth, screenHeight int) image.Rectangle

func (*View) Offset

func (v *View) Offset() image.Point

func (*View) ScreenToGlobal

func (v *View) ScreenToGlobal(x, y int) (int, int)

func (*View) SubtileToGlobal

func (v *View) SubtileToGlobal(x, y float64) image.Point

func (*View) TileToGlobal

func (v *View) TileToGlobal(x, y int) image.Point

type WorldBounds

type WorldBounds struct {
	image.Rectangle
}

WorldBounds contain the bounding box of the currently built world. Used to limit scrolling/panning.

func (*WorldBounds) AddPoint

func (b *WorldBounds) AddPoint(p image.Point)

AddPoint extends the bounds sp that they contain the given point.

func (*WorldBounds) Contains

func (b *WorldBounds) Contains(p image.Point) bool

Contains checks whether a pont is inside the bounds.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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