game

package
v0.0.0-...-4d737b0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnitSpeed = 0.1
)

Variables

View Source
var ZeroPoint = image.Pt(0, 0)
View Source
var ZeroUnitId = UnitIdType(uuid.Nil)

Functions

func Dist

func Dist(p1 image.Point, p2 image.Point) float64

func NextStep

func NextStep(s image.Point, target image.Point) image.Point

Types

type Action

type Action interface {
	GetType() ActionType
	GetPayload() any
}

func UnmarshalAction

func UnmarshalAction(bytes []byte) (Action, error)

type ActionType

type ActionType string
const (
	PlayerJoinActionType        ActionType = "PlayerJoin"
	PlayerJoinSuccessActionType ActionType = "PlayerJoinSuccess"
	SpawnUnitActionType         ActionType = "SpawnUnit"
	MoveStartActionType         ActionType = "MoveStart"
	MoveStepActionType          ActionType = "MoveStep"
	MoveStopActionType          ActionType = "MoveStop"
	MapLoadActionType           ActionType = "MapLoad"
	MapLoadSuccessActionType    ActionType = "MapLoadSuccess"
)

type ActionsHandler

type ActionsHandler interface {
	HandleAction(Action, DispatchFunc)
}

type DispatchFunc

type DispatchFunc func(Action)

type GameLogic

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

func NewGameLogic

func NewGameLogic(store Store) *GameLogic

func (*GameLogic) HandleAction

func (g *GameLogic) HandleAction(action Action, dispatch DispatchFunc)

type GenericAction

type GenericAction[T any] struct {
	Type    ActionType
	Payload T
}

func (GenericAction[T]) GetPayload

func (a GenericAction[T]) GetPayload() any

func (GenericAction[T]) GetType

func (a GenericAction[T]) GetType() ActionType

type MapLoadAction

type MapLoadAction = GenericAction[MapLoadPayload]

func NewMapLoadAction

func NewMapLoadAction(rect image.Rectangle, playerId PlayerIdType) MapLoadAction

type MapLoadPayload

type MapLoadPayload struct {
	world.WorldRequest
	PlayerId PlayerIdType
}

type MapLoadSuccessAction

type MapLoadSuccessAction = GenericAction[MapLoadSuccessPayload]

type MapLoadSuccessPayload

type MapLoadSuccessPayload struct {
	world.WorldResponse
	PlayerId PlayerIdType
}

type MoveStartAction

type MoveStartAction = GenericAction[MoveStartPayload]

type MoveStartPayload

type MoveStartPayload struct {
	UnitId UnitIdType
	Point  image.Point
}

type MoveStepAction

type MoveStepAction = GenericAction[MoveStepPayload]

type MoveStepPayload

type MoveStepPayload struct {
	UnitId   UnitIdType
	Position PF
	Path     []image.Point
	Step     int
}

type MoveStopAction

type MoveStopAction = GenericAction[UnitIdType]

type PF

type PF struct {
	X float64
	Y float64
}

func NewPF

func NewPF(x, y float64) PF

func ToPF

func ToPF(p image.Point) PF

func (PF) Add

func (p PF) Add(p2 PF) PF

func (PF) Dist

func (p PF) Dist(target PF) float64

func (PF) ImagePoint

func (p PF) ImagePoint() image.Point

func (PF) Ints

func (p PF) Ints() (int, int)

func (PF) Mul

func (p PF) Mul(a float64) PF

func (PF) Round

func (p PF) Round() PF

func (PF) Step

func (p PF) Step(target PF) PF

type Player

type Player struct {
	Id    PlayerIdType
	Name  string
	Color color.RGBA
	Start PF
}

func NewPlayer

func NewPlayer(name string) *Player

type PlayerIdType

type PlayerIdType uuid.UUID

func NewPlayerId

func NewPlayerId() PlayerIdType

type PlayerJoinAction

type PlayerJoinAction = GenericAction[Player]

type PlayerJoinSuccessAction

type PlayerJoinSuccessAction = GenericAction[PlayerJoinSuccessPayload]

type PlayerJoinSuccessPayload

type PlayerJoinSuccessPayload struct {
	PlayerId PlayerIdType
	Units    []Unit
	Players  []Player
}

type SpawnUnitAction

type SpawnUnitAction = GenericAction[Unit]

type Store

type Store interface {
	StoreUnit(unit *Unit)
	GetUnitById(id UnitIdType) *Unit
	GetAllUnits() []*Unit
	GetUnitsByPlayerId(id PlayerIdType) []*Unit

	GetPlayer(id PlayerIdType) (*Player, bool)
	GetAllPlayers() []*Player
	StorePlayer(player Player)

	GetTilesByUnitId(id UnitIdType) []*Tile
	StoreTile(tile world.Tile) *Tile
	GetTile(image.Point) (*Tile, bool)
	CreateTile(image.Point) *Tile
	GetTilesByRect(rect image.Rectangle) map[image.Point]*Tile
}

type StoreImpl

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

func NewStoreImpl

func NewStoreImpl() *StoreImpl

func (*StoreImpl) CreateTile

func (s *StoreImpl) CreateTile(point image.Point) *Tile

func (*StoreImpl) GetAllPlayers

func (s *StoreImpl) GetAllPlayers() []*Player

func (*StoreImpl) GetAllUnits

func (s *StoreImpl) GetAllUnits() []*Unit

func (*StoreImpl) GetPlayer

func (s *StoreImpl) GetPlayer(id PlayerIdType) (*Player, bool)

func (*StoreImpl) GetTile

func (s *StoreImpl) GetTile(point image.Point) (*Tile, bool)

func (*StoreImpl) GetTilesByRect

func (s *StoreImpl) GetTilesByRect(rect image.Rectangle) map[image.Point]*Tile

func (*StoreImpl) GetTilesByUnitId

func (s *StoreImpl) GetTilesByUnitId(id UnitIdType) []*Tile

func (*StoreImpl) GetUnitById

func (s *StoreImpl) GetUnitById(id UnitIdType) *Unit

func (*StoreImpl) GetUnitsByPlayerId

func (s *StoreImpl) GetUnitsByPlayerId(id PlayerIdType) []*Unit

func (*StoreImpl) StorePlayer

func (s *StoreImpl) StorePlayer(player Player)

func (*StoreImpl) StoreTile

func (s *StoreImpl) StoreTile(tile world.Tile) *Tile

func (*StoreImpl) StoreUnit

func (s *StoreImpl) StoreUnit(unit *Unit)

type Tile

type Tile struct {
	*world.Tile
	Unit    *Unit
	Visible bool
}

type Unit

type Unit struct {
	Id       UnitIdType
	Owner    PlayerIdType
	Color    color.RGBA
	Position PF
	Size     image.Point
	Selected bool
	Velocity PF `json:"-"`
	Path     []image.Point
	Step     int
	ISee     []image.Point
}

func NewUnit

func NewUnit(owner PlayerIdType, c color.RGBA, position PF, width, height int) *Unit

func (*Unit) MoveTo

func (u *Unit) MoveTo(target image.Point)

func (*Unit) Set

func (u *Unit) Set(unit Unit)

func (*Unit) Update

func (u *Unit) Update(dispatch DispatchFunc)

type UnitIdType

type UnitIdType uuid.UUID

func NewUnitId

func NewUnitId() UnitIdType

Jump to

Keyboard shortcuts

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