game

package
v0.0.0-...-dfb2563 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EntityKindPlayer = EntityKind(iota)
	EntityKindBiotic
	EntityKindWorldItem
)
View Source
const (
	INV_WIDTH  = 5
	INV_HEIGHT = 5
	MAX_STACK  = 50
)
View Source
const (
	ITEM_NIL = Item(iota)
	ITEM_DIRT
	ITEM_STONE
	ITEM_SHOVEL
	ITEM_GUN
	ITEM_SPAWN
	ITEM_GRASS
	ITEM_COAL
	ITEM_IRON
	ITEM_GOLD
	ITEM_SAPPHIRE
	ITEM_EMERALD
	ITEM_RUBY
	ITEM_DIAMOND
	ITEM_POUDRETTEITE
	ITEM_GLASS

	// Keep this last
	TOTAL_ITEMS
)
View Source
const (
	// Properties
	STACKABLE = 0x1 << iota
	SHOOTABLE
)

Variables

View Source
var PLAYER_MAX_LIFE = 100

Gameplay state defaults

View Source
var PlayerCenterOffset = vmath.Vec3{
	0,
	playerHeight/2 - playerEyeHeight,
	0,
}
View Source
var PlayerHalfExtents = vmath.Vec3{
	0.4,
	playerHeight / 2,
	0.4,
}
View Source
var WorldItemHalfExtents = vmath.Vec3{
	float64(1) / 8,
	float64(1) / 8,
	float64(1) / 8,
}

Functions

func EachChunkNearby

func EachChunkNearby(wc coords.World, cb func(cc coords.Chunk, priority int))

func EveryItem

func EveryItem() chan Item

Types

type Biotic

type Biotic interface {
	Entity
	Damageable
	Respawnable

	State() *BioticState
}

type BioticListener

type BioticListener interface {
	BioticCreated(id EntityId, biotic Biotic)
	BioticUpdated(id EntityId, biotic Biotic)
	BioticDamaged(id EntityId, biotic Biotic)
	BioticDied(id EntityId, biotic Biotic, killer string)
	BioticRemoved(id EntityId)
}

type BioticState

type BioticState struct {
	EntityState EntityState
	Health      Health
}

type BlockListener

type BlockListener interface {
	BlockChanged(bc coords.Block, old mapgen.Block, new mapgen.Block)
}

type ChunkGenerationResult

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

type ChunkGenerator

type ChunkGenerator struct {
	// Chunks are sent to this channel as they are generated
	Generated chan ChunkGenerationResult
	// contains filtered or unexported fields
}

func NewChunkGenerator

func NewChunkGenerator(generator mapgen.Generator) *ChunkGenerator

func (*ChunkGenerator) QueueChunksNearby

func (cm *ChunkGenerator) QueueChunksNearby(wc coords.World)

func (*ChunkGenerator) Run

func (cm *ChunkGenerator) Run()

func (*ChunkGenerator) Top

func (cm *ChunkGenerator) Top() (cc coords.Chunk, valid bool)

type ChunkListener

type ChunkListener interface {
	ChunkGenerated(cc coords.Chunk, data *mapgen.Chunk)
}

type ChunkStatus

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

type ControlState

type ControlState struct {
	ControlFlags int
	Lat          float64
	Lon          float64

	// JavaScript performance.now() timestamp.
	// TimeStamp is when it was sent, ViewTimestamp is
	// what time the client was displaying when it was sent
	// (with lag induction they may differ).
	Timestamp     float64 // In ms
	ViewTimestamp float64
}

func (*ControlState) ActivateLeft

func (cs *ControlState) ActivateLeft() bool

func (*ControlState) ActivateRight

func (cs *ControlState) ActivateRight() bool

func (*ControlState) Back

func (cs *ControlState) Back() bool

func (*ControlState) Forward

func (cs *ControlState) Forward() bool

func (*ControlState) Jump

func (cs *ControlState) Jump() bool

func (*ControlState) Left

func (cs *ControlState) Left() bool

func (*ControlState) Right

func (cs *ControlState) Right() bool

type Damageable

type Damageable interface {
	Life() int
	Dead() bool

	Damage(amount int)
}

type Entity

type Entity interface {
	EntityId() EntityId
	Body() physics.Body
	LastUpdated() float64
	Wpos() coords.World
	BoxAt(t float64) *physics.Box
}

type EntityId

type EntityId string

Should be an int someday...

type EntityKind

type EntityKind byte

type EntityState

type EntityState struct {
	EntityId    EntityId
	Body        physics.Body
	LastUpdated float64
}

func (*EntityState) Look

func (es *EntityState) Look() coords.Direction

func (*EntityState) Wpos

func (es *EntityState) Wpos() coords.World

type Health

type Health struct {
	Life int
}

type HistoryBuffer

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

func NewHistoryBuffer

func NewHistoryBuffer() *HistoryBuffer

func (*HistoryBuffer) Add

func (ph *HistoryBuffer) Add(t float64, body physics.Body)

func (*HistoryBuffer) BodyAt

func (ph *HistoryBuffer) BodyAt(t float64) *physics.Body

If t > most recent time added, return most recent position added. If t < ring buffer history, return oldest position stored. If t == an entry in the ring buffer, return that entry. If t is between two entries in the ring buffer, interpolate between them.

func (*HistoryBuffer) Clear

func (ph *HistoryBuffer) Clear()

type HistoryEntry

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

type Inventory

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

func NewInventory

func NewInventory() *Inventory

func (*Inventory) AddItem

func (inv *Inventory) AddItem(item Item) bool

Adds an item to the inventory. Returns true if the addition was successful, false if there is no room remaining in the inventory.

func (*Inventory) ItemsToByteArray

func (inv *Inventory) ItemsToByteArray() []byte

func (*Inventory) LeftItem

func (inv *Inventory) LeftItem() Item

func (*Inventory) MoveItems

func (inv *Inventory) MoveItems(from, to int)

func (*Inventory) RemoveItem

func (inv *Inventory) RemoveItem(item Item) bool

Removes an item from the inventory. Returns true if the removal was successful, false if the given item does not exist in the inventory.

func (*Inventory) RightItem

func (inv *Inventory) RightItem() Item

func (*Inventory) SetActiveItems

func (inv *Inventory) SetActiveItems(left, right int)

type Item

type Item byte

func ItemFromBlock

func ItemFromBlock(block mapgen.Block) Item

func (Item) Shootable

func (item Item) Shootable() bool

func (Item) Stackable

func (item Item) Stackable() bool

type Player

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

func NewPlayer

func NewPlayer(world *World, name string) *Player

func (*Player) Body

func (p *Player) Body() physics.Body

func (*Player) BoxAt

func (p *Player) BoxAt(t float64) *physics.Box

func (*Player) ClientInventoryUpdated

func (p *Player) ClientInventoryUpdated()

func (*Player) ClientTick

func (p *Player) ClientTick(controls ControlState) *coords.World

func (*Player) Collects

func (p *Player) Collects() bool

func (*Player) Damage

func (p *Player) Damage(amount int)

func (*Player) Dead

func (p *Player) Dead() bool

func (*Player) EntityId

func (p *Player) EntityId() EntityId

func (*Player) Give

func (p *Player) Give(item Item) bool

func (*Player) Inventory

func (p *Player) Inventory() *Inventory

func (*Player) LastUpdated

func (p *Player) LastUpdated() float64

Returns the last time this entity's state was updated (i.e. by a client sending a control-state packet).

func (*Player) Life

func (p *Player) Life() int

func (*Player) Look

func (p *Player) Look() coords.Direction

func (*Player) NeedsInventoryUpdate

func (p *Player) NeedsInventoryUpdate() bool

func (*Player) Respawn

func (p *Player) Respawn(pos coords.World)

func (*Player) State

func (p *Player) State() *BioticState

func (*Player) Take

func (p *Player) Take(item Item) bool

func (*Player) Wpos

func (p *Player) Wpos() coords.World

type Possessor

type Possessor interface {
	Inventory() *Inventory
	Give(item Item) bool
	Take(item Item) bool

	// Do items in the world gravitate towards this?
	Collects() bool
	// If Collects return true, then Body must return a value
	Body() physics.Body
}

type Respawnable

type Respawnable interface {
	Respawn(pos coords.World)
}

type Stack

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

func NewStack

func NewStack(item Item) Stack

func NewStackOf

func NewStackOf(item Item, num byte) Stack

type State

type State int
const (
	Queued     State = iota
	Generating State = iota
	Generated  State = iota
)

type World

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

func NewWorld

func NewWorld(generator mapgen.Generator) *World

func (*World) AddBioticListener

func (w *World) AddBioticListener(listener BioticListener)

func (*World) AddBlockListener

func (w *World) AddBlockListener(listener BlockListener)

func (*World) AddChunkListener

func (w *World) AddChunkListener(listener ChunkListener)

func (*World) AddEntity

func (w *World) AddEntity(e Entity)

func (*World) AddWorldItemListener

func (w *World) AddWorldItemListener(listener WorldItemListener)

func (*World) Biotics

func (w *World) Biotics() map[EntityId]Biotic

func (*World) Block

func (w *World) Block(bc coords.Block) mapgen.Block

func (*World) ChangeBlock

func (w *World) ChangeBlock(bc coords.Block, newBlock mapgen.Block)

func (*World) Chunk

func (w *World) Chunk(cc coords.Chunk) *mapgen.Chunk

func (*World) DamageBiotic

func (w *World) DamageBiotic(damager string, amount int, s Biotic)

func (*World) FindFirstIntersect

func (w *World) FindFirstIntersect(entity Biotic, t float64, ray *physics.Ray) (*coords.World, Biotic)

func (*World) FireBioticUpdated

func (w *World) FireBioticUpdated(id EntityId, biotic Biotic)

func (*World) RemoveBioticListener

func (w *World) RemoveBioticListener(listener BioticListener)

func (*World) RemoveBlockListener

func (w *World) RemoveBlockListener(listener BlockListener)

func (*World) RemoveChunkListener

func (w *World) RemoveChunkListener(listener ChunkListener)

func (*World) RemoveEntity

func (w *World) RemoveEntity(e Entity)

func (*World) RemoveWorldItemListener

func (w *World) RemoveWorldItemListener(listener WorldItemListener)

func (*World) Tick

func (w *World) Tick(dt int64)

func (*World) WorldItems

func (w *World) WorldItems() map[EntityId]*WorldItem

type WorldItem

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

func NewWorldItem

func NewWorldItem(kind Item, pos coords.World) *WorldItem

func (*WorldItem) Body

func (wi *WorldItem) Body() physics.Body

func (*WorldItem) BoxAt

func (wi *WorldItem) BoxAt(t float64) *physics.Box

func (*WorldItem) EntityId

func (wi *WorldItem) EntityId() EntityId

func (*WorldItem) LastUpdated

func (wi *WorldItem) LastUpdated() float64

func (*WorldItem) Look

func (wi *WorldItem) Look() coords.Direction

func (*WorldItem) State

func (wi *WorldItem) State() *WorldItemState

func (*WorldItem) Tick

func (wi *WorldItem) Tick(dt int64, w *World) (bool, bool)

Returns "updated" and "pickedUp", in that order

func (*WorldItem) Wpos

func (wi *WorldItem) Wpos() coords.World

type WorldItemListener

type WorldItemListener interface {
	WorldItemAdded(id EntityId, worldItem *WorldItem)
	WorldItemUpdated(id EntityId, worldItem *WorldItem)
	WorldItemRemoved(id EntityId)
}

type WorldItemState

type WorldItemState struct {
	EntityState EntityState
	ItemKind    Item
}

Jump to

Keyboard shortcuts

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