game

package
v0.0.0-...-d85e1bb Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemovePlayer

func RemovePlayer(g *Game, socketID int)

func SetPlayerInput

func SetPlayerInput(g *Game, socketID int, flags uint8)

Types

type Camera

type Camera struct {
	Position        *util.Vector2D
	FOV             float64
	ShipsSeen       map[uint64]bool
	ProjectilesSeen map[uint64]bool
}

func NewCamera

func NewCamera(fov float32) (c *Camera)

func (*Camera) IsInView

func (c *Camera) IsInView(aabb *util.AABB) (inside bool)

func (*Camera) See

func (c *Camera) See(g *Game, player *Player, w *protocol.Writer)

func (*Camera) SeeShip

func (c *Camera) SeeShip(w *protocol.Writer, o *Ship)

type Candidate

type Candidate struct {
	Ship *Ship
	Dist float64
}

func ClosestShip

func ClosestShip(ships []*Candidate) (closest *Candidate)

func SelectShipsAroundMe

func SelectShipsAroundMe(me *Ship, closedSearchRange float64) []*Candidate

type CircularCollisionPlugin

type CircularCollisionPlugin struct {
	GenericObject
	AABB *util.AABB
}

func (*CircularCollisionPlugin) GetAABB

func (ccp *CircularCollisionPlugin) GetAABB() (aabb *util.AABB)

func (*CircularCollisionPlugin) Insert

func (ccp *CircularCollisionPlugin) Insert()

type CollidableObject

type CollidableObject interface {
	util.Identifiable
	GetAABB() *util.AABB
	Insert()
	Collide()
}

type Control

type Control struct {
	Game                *Game
	Body                *Ship
	Goal, PrimaryTarget *util.Vector2D
}

Bound to a body. Assumes Game and Body are not nil

func NewControl

func NewControl(game *Game, body *Ship) (ctrl *Control)

func (*Control) Update

func (c *Control) Update()

type Faction

type Faction struct {
	ID               uint64
	Name             string
	Color            color.RGBA
	ShipsSpatialHash *util.SpatialHash[*Ship]
}

func NewFaction

func NewFaction(g *Game, name string) (f *Faction)

func (*Faction) Update

func (f *Faction) Update()

type Game

type Game struct {
	Factions   map[uint64]*Faction
	FactionsMu sync.RWMutex
	Ships      *util.SafeStorage[*Ship]
	Planes     *util.SafeStorage[*Plane]

	ShipCache                      map[uint64]*ShipCache
	ProjectileCache                map[uint64]*GenericObjectCache
	ShipCacheMu, ProjectileCacheMu sync.RWMutex
	Players                        map[int]*Player
	PlayersMu                      sync.RWMutex
	// contains filtered or unexported fields
}

func NewGame

func NewGame() (g *Game)

func (*Game) BeginUpdateLoop

func (g *Game) BeginUpdateLoop(tps int)

func (*Game) Init

func (g *Game) Init()

func (*Game) Update

func (g *Game) Update()

type GenericObject

type GenericObject struct {
	ID                                             uint64
	Game                                           *Game
	Position, Velocity                             *util.Vector2D
	Size, Rotation, Friction, Density, Pushability float64
	Faction                                        *Faction
}

All game object should embed this either directly or through another embedded struct

func NewGameObject

func NewGameObject(game *Game, position *util.Vector2D, f *Faction) (o *GenericObject)

func (*GenericObject) Collide

func (o *GenericObject) Collide()

func (*GenericObject) GetAABB

func (o *GenericObject) GetAABB() (aabb *util.AABB)

func (*GenericObject) GetID

func (o *GenericObject) GetID() (id uint64)

func (*GenericObject) Insert

func (o *GenericObject) Insert()

func (*GenericObject) PushWeight

func (o *GenericObject) PushWeight() (weight float64)

func (*GenericObject) Update

func (o *GenericObject) Update()

type GenericObjectCache

type GenericObjectCache struct {
	AsOf                                int // Corresponds with Game.time
	New, Old                            *protocol.Writer
	ID                                  uint64
	X, Y, Size, Rotation                float64
	PosChanged, SizeChanged, RotChanged bool
}

type HealthComponent

type HealthComponent struct {
	Health, MaxHealth float64
	CanBeRepaired     bool
}

func NewHealth

func NewHealth(health float64, canBeRepaired bool) (hc *HealthComponent)

func (*HealthComponent) Damage

func (hc *HealthComponent) Damage(amount float64)

func (*HealthComponent) IsAlive

func (hc *HealthComponent) IsAlive() (alive bool)

func (*HealthComponent) Ratio

func (hc *HealthComponent) Ratio() (ratio float64)

type Plane

type Plane struct {
	CircularCollisionPlugin
}

type Player

type Player struct {
	Socket       *web.Socket
	Body         *Ship
	Camera       *Camera
	InputFlags   uint8
	LastFireTick int
	InputMu      sync.RWMutex
	Faction      *Faction
}

func NewPlayer

func NewPlayer(game *Game, socket *web.Socket, name string) (p *Player)

func (*Player) GetInputFlags

func (p *Player) GetInputFlags() (flags uint8)

func (*Player) SetInputFlags

func (p *Player) SetInputFlags(flags uint8)

type PolygonalCollisionPlugin

type PolygonalCollisionPlugin struct {
	GenericObject
	Polygon *util.Polygon
}

func (*PolygonalCollisionPlugin) GetAABB

func (pcp *PolygonalCollisionPlugin) GetAABB() (aabb *util.AABB)

func (*PolygonalCollisionPlugin) Insert

func (pcp *PolygonalCollisionPlugin) Insert()

type Ship

type Ship struct {
	PolygonalCollisionPlugin
	Name    string
	Cfg     *definitions.Ship
	Health  *HealthComponent
	Control *Control
}

func NewShip

func NewShip(g *Game, position *util.Vector2D, def *definitions.Ship, f *Faction) (s *Ship)

func (*Ship) Collide

func (s *Ship) Collide()

func (*Ship) GetAABB

func (s *Ship) GetAABB() (aabb *util.AABB)

func (*Ship) Insert

func (s *Ship) Insert()

func (*Ship) Think

func (s *Ship) Think()

func (*Ship) Update

func (s *Ship) Update()

type ShipAI

type ShipAI struct {
	Ship   *Ship
	Target *Ship
}

type ShipCache

type ShipCache struct {
	GenericObjectCache
	Health                                                        float64
	Shields                                                       [][2]float64 // [][hardpoint health ratio, shield health ratio]
	Engines                                                       []float64    // []engine health ratio
	Turrets                                                       [][2]float64 // [][hardpoint health ratio, turret facing (absolute)]
	HealthChanged, ShieldsChanged, EnginesChanged, TurretsChanged bool
}

Jump to

Keyboard shortcuts

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