simvillage_tiles

package
v0.0.0-...-ce97658 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

README

SimVillage_Tiles

This package contains a very simple tile based renderer and will hopefully be a nifty village simulation soon.

Features

  • Simple tile based renderer
  • Player controlled character
  • NPC characters (rudimentary)
  • Drawable prefab objects (rudimentary)
  • Collision detection (rudimentary)
  • Chunk loading / chunk generation
  • Chunk caching (sorta)

TODO

  • Rendering
    • Improve tile render order
    • Find a better dungeon tile set
  • Map / world
    • Decouple chunk size from viewport size (?)
    • Generation or loading of larger maps
    • Persistent world (since we use procgen, this'll be interesting)
    • Per-Tile actions / events (doors, triggers, ...)
    • Objects / resources / etc.
  • [WIP] Better layer system / named layers
    • [DONE] Create new structs for handling map chunks and layers
    • [DONE] Migrate renderer to MapChunk and Layer types
    • Allow arbitrary layer names
    • Allow enabling per-layer collision detection via layer property
  • [WIP] Indoor maps
    • [DONE] Map (world) switching
    • [WIP] Doors with destination maps / worlds
    • Set player position when transitioning to new map
  • Creatures
    • Stats
      • Use gamesheet for stats
    • AI
      • Perception system
      • Pathfinding
      • Decision making (state machines)
    • Actions
      • Open doors / enter buildings
      • Attack, pick up, ...

alt text

Attribution

Dungeon Tile Set by Buch https://opengameart.org/users/buch Roguelike Items by https://twitter.com/joecreates

Documentation

Overview

Package simvillage_tiles is a tile based village simulation based on: https://ebiten.org/examples/tiles.html https://ebiten.org/examples/animation.html

Index

Constants

View Source
const (
	TileItemRock = 141
)

Tile IDs of items.

Variables

View Source
var (
	ItemTypeRock = &ItemType{
		Name: "Rock",
		Tile: TileItemRock,
	}
)

Functions

This section is empty.

Types

type Creature

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

Creature represents a moving entity in the game.

func NewCreature

func NewCreature(g *Game, w World, pos [2]int) *Creature

NewCreature returns a new creature with the given position.

func (*Creature) Draw

func (c *Creature) Draw(screen *ebiten.Image, cOffsX, cOffsY float64)

Draw renders the creature on the screen with the given offset.

type DefaultWorld

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

DefaultWorld is the default chunk source.

func (*DefaultWorld) FetchChunk

func (w *DefaultWorld) FetchChunk(x, y int) *MapChunk

FetchChunk is a function to fetch a chunk from the world.

func (*DefaultWorld) TileSet

func (w *DefaultWorld) TileSet() *TileSet

TileSet returns the tileset used for this world.

type Destination

type Destination struct {
	X, Y  int
	Chunk [2]int
}

Destination is a destination for a trigger. TODO: Add also destination map.

type Dimensions

type Dimensions struct {
	Width  int
	Height int
}

Dimensions represents the dimensions of a map.

func NewDimensions

func NewDimensions(width, height int) Dimensions

NewDimensions returns a new Dimensions struct.

type FakeIndoorWorld

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

FakeIndoorWorld is a fake indoor map.

func (*FakeIndoorWorld) FetchChunk

func (w *FakeIndoorWorld) FetchChunk(x, y int) *MapChunk

func (*FakeIndoorWorld) TileSet

func (w *FakeIndoorWorld) TileSet() *TileSet

TileSet returns the tileset used for this world.

type Game

type Game struct {
	*MapCache
	// contains filtered or unexported fields
}

Game represents the main game struct. TODO: Move creatures to the individual world structs. ... or add a pointer to each creature that points to its world, so all creatures everywhere are still updated.

func NewGame

func NewGame() *Game

func (*Game) Draw

func (g *Game) Draw(screen *ebiten.Image)

func (*Game) Layout

func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int)

func (*Game) Update

func (g *Game) Update() error

type Item

type Item struct {
	*ItemType
	Position [2]int
}

Item represents an item in the game.

This item has a base type but has additional properties like a position, etc.

type ItemType

type ItemType struct {
	Name string
	Tile int
}

ItemType represents an type of an item.

func (*ItemType) NewInstance

func (i *ItemType) NewInstance() *Item

NewInstance returns a new item with the given type.

type Layer

type Layer struct {
	Dimensions
	Tiles []int
}

Layer represents a layer on the map. TODO: Provide a (bool) Collidable property which will determine if the layer will be checked in the collision detection. Note: This code is in part inspired by cxong's fantastic map generator https://github.com/cxong/gomapgen

type MapCache

type MapCache struct {
	World // fetchChunk is a function to fetch a chunk from the source.
	// contains filtered or unexported fields
}

MapCache provides a caching layer for serving MapChunks.

type MapChunk

type MapChunk struct {
	Dimensions
	Ground        *Layer    // Ground or terrain.
	GroundOverlay *Layer    // Overlays like carpets, scratchmarks, etc.
	Objects       *Layer    // Objects like stones, flowers, etc.
	Structures    *Layer    // Structures like walls, gates, fences, etc.
	Roof          *Layer    // Roof or ceiling.
	Items         []*Item   // Items in the current chunk.
	Triggers      []Trigger // Position of the trigger in the current chunk.
}

MapChunk represents a chunk of the map.

type TileSet

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

TileSet is a convenience wrapper around locating tiles in a tileset. TODO: Add support for animations.

func NewTileSet

func NewTileSet(imgData []byte) (*TileSet, error)

func (*TileSet) TileImage

func (t *TileSet) TileImage(idx int) *ebiten.Image

type Trigger

type Trigger struct {
	Position    [2]int // Position of the trigger in the chunk.
	Destination        // Teleport the user to this destination.
}

Trigger represents an interaction trigger.

type World

type World interface {
	FetchChunk(x, y int) *MapChunk // returns a specific chunk
	TileSet() *TileSet             // returns the tileset for this world
}

World is an interface providing chunks at the given coordinates. TODO: Add a function that returns the active creatures in this world. TODO: Add a function that retrieves a specific tile. This would allow us to get information on doors to other maps etc.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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