game

package
v0.0.0-...-27af21b Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CHUNK_W int64 = 8
	CHUNK_H int64 = 8
)

Variables

This section is empty.

Functions

func SendAllToOne

func SendAllToOne(conn net.Conn, gs *GameState)

func SendOneToAll

func SendOneToAll[T protoreflect.ProtoMessage](gs *GameState, packet T)

func SendOneToOne

func SendOneToOne[T protoreflect.ProtoMessage](conn net.Conn, gs *GameState, packet T)

func UpdateCombatSystem

func UpdateCombatSystem(gs *GameState)

func UpdateZombiesSystem

func UpdateZombiesSystem(gs *GameState)

Types

type Chunk

type Chunk struct {
	X     int64
	Y     int64
	Stack [CHUNK_H][CHUNK_W][]byte
}

func NewChunk

func NewChunk(x, y int64) *Chunk

func ParseChunksFromBytes

func ParseChunksFromBytes(data []byte) []*Chunk

func (*Chunk) FillPerlin

func (c *Chunk) FillPerlin()

func (*Chunk) GetTopBlock

func (c *Chunk) GetTopBlock(x, y int64) byte

func (*Chunk) ToBytes

func (c *Chunk) ToBytes() []byte

type GameState

type GameState struct {
	EntityCounter      int64
	PlayerComponents   map[components.EntityId]*components.Player
	ZombieComponents   map[components.EntityId]*components.Zombie
	SpriteComponents   map[components.EntityId]*components.Sprite
	PositionComponents map[components.EntityId]*components.Position
	Mutex              sync.Mutex
	Logger             *log.Logger
	Chunks             map[int64]map[int64]*Chunk
	IntStore           map[string]int64
	TPS                int // ticks per second
}

func NewGameState

func NewGameState() *GameState

func (*GameState) AddChunks

func (gs *GameState) AddChunks(chunks []*Chunk)

func (*GameState) AddPlayer

func (gs *GameState) AddPlayer(p *components.Player)

func (*GameState) GetChunkAtCoords

func (gs *GameState) GetChunkAtCoords(x, y int64) *Chunk

func (*GameState) GetChunksAroundPlayer

func (gs *GameState) GetChunksAroundPlayer(p *components.Player) ([]*Chunk, []*Chunk)

func (*GameState) GetIntStore

func (gs *GameState) GetIntStore(key string) (int64, bool)

func (*GameState) GetPlayer

func (gs *GameState) GetPlayer(playerID int64) *components.Player

func (*GameState) GetPlayersAroundPlayer

func (gs *GameState) GetPlayersAroundPlayer(p *components.Player) []*components.Player

func (*GameState) GetTerrainAtCoords

func (gs *GameState) GetTerrainAtCoords(x, y int64) byte

func (*GameState) HandlePlayerAction

func (gs *GameState) HandlePlayerAction(player *components.Player, action int32)

func (*GameState) InitNewPlayer

func (gs *GameState) InitNewPlayer(newPlayer *components.Player)

func (*GameState) InitNewZombie

func (gs *GameState) InitNewZombie(newZombie *components.Zombie, x, y int64)

func (*GameState) MovePlayer

func (gs *GameState) MovePlayer(playerID components.EntityId, x, y int64)

func (*GameState) NextEntityId

func (gs *GameState) NextEntityId() components.EntityId

func (*GameState) RemovePlayer

func (gs *GameState) RemovePlayer(playerID components.EntityId)

func (*GameState) RemoveZombie

func (gs *GameState) RemoveZombie(zombieID components.EntityId)

func (*GameState) RunGameLoop

func (gs *GameState) RunGameLoop()

func (*GameState) SetIntStore

func (gs *GameState) SetIntStore(key string, value int64)

func (*GameState) UpdatePlayerChunks

func (gs *GameState) UpdatePlayerChunks(playerID components.EntityId, x, y int64)

func (*GameState) UpdatePositionComponent

func (gs *GameState) UpdatePositionComponent(entityId components.EntityId,
	position *components.Position)

func (*GameState) UpdateSpriteComponent

func (gs *GameState) UpdateSpriteComponent(entityId components.EntityId,
	sprite *components.Sprite)

func (*GameState) UseItem

func (gs *GameState) UseItem(p *components.Player, itemID int64)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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