Documentation ¶
Index ¶
- Constants
- Variables
- type AI
- type Being
- func (b *Being) Dead() bool
- func (b *Being) ID() int64
- func (b *Being) InMeleeRange(target Entity) bool
- func (b *Being) Pos() vectors.Vec2
- func (b *Being) String() string
- func (b *Being) TakeDamage(damage float64, attacker Entity)
- func (b *Being) Type() EntityType
- func (b *Being) Update(delta float64)
- type CompMoveable
- type CompStats
- type Config
- type Entity
- type EntityType
- type Event
- type EventAttackData
- type EventListener
- type EventType
- type Events
- type Item
- type List
- func (l *List) Add(nodes ...Node)
- func (l *List) All() []Node
- func (l *List) Clear()
- func (l *List) Contains(searchNode Node) bool
- func (l *List) GetIndex(searchNode Node) int
- func (l *List) GetIndexOfMinF() int
- func (l *List) GetMinFNode() (Node, error)
- func (l *List) IsEmpty() bool
- func (l *List) Remove(removeNode Node)
- type Need
- type Needs
- type Node
- type Notifiable
- type Pathfinding
- type PathfindingMode
- type Perception
- type World
- func (w *World) AddBeing()
- func (w *World) AddItem()
- func (w *World) CellIdxToPos(idx int) *vectors.Vec2
- func (w *World) CheckIdxReachable(idx int) error
- func (w World) ExportGif(path string) error
- func (m World) ExportWebp(name string) error
- func (w *World) GetEntitiesInRadius(pos vectors.Vec2, radius float64) []Entity
- func (w *World) GetItemsInRadius(pos vectors.Vec2, radius float64) []*Item
- func (w *World) Pathfind(start, end *vectors.Vec2) ([]int, error)
- func (w *World) PosToCellIdx(pos *vectors.Vec2) int
- func (w *World) Update(delta float64)
Constants ¶
const ( HungerPeckish = 20 HungerHungry = 40 HungerStarving = 60 HungerStarved = 100 HungerPerSecond = 1.0 )
const ( ExhaustionTired = 10 ExhaustionExhausted = 40 ExhaustionDead = 60 ExhaustionPerSecond = 1.0 )
Variables ¶
var ( ErrNoPathFound = errors.New("no path found") ErrNoNodeFound = errors.New("no node found") )
var ErrGridSize = errors.New("grid size must be at least 2x2")
Functions ¶
This section is empty.
Types ¶
type AI ¶
type AI struct { World *World // underlying world Being *Being // underlying being Perception *Perception // perception of the world Pathfinding *Pathfinding // steering behaviors Needs *Needs // basic needs Destination *vectors.Vec2 // current destination Home vectors.Vec2 // home position }
func (*AI) TakeDamage ¶
TakeDamage registers incoming damage from an attacker. TODO: Find a better way to do this. Maybe via an event system?
func (*AI) Type ¶
func (a *AI) Type() EntityType
Type returns the type of the being this AI is controlling.
type Being ¶
type Being struct { *CompMoveable // Position and speed. *CompStats // Stats. *EventListener // Event listener. World *World // contains filtered or unexported fields }
Being represents a being in the world.
func (*Being) InMeleeRange ¶
InMeleeRange returns true if the being is in melee range of the target.
func (*Being) TakeDamage ¶
TakeDamage reduces the health of the being. TODO: Find a better way to do this. Maybe via an event system?
type CompMoveable ¶
CompMoveable is a movable component.
func (*CompMoveable) Update ¶
func (c *CompMoveable) Update(delta float64)
Update moves the position in the component by the speed within the given time.
type CompStats ¶
type CompStats struct { Health float64 // Current health. HealthMax float64 // Maximum health. StarvationRate float64 // How fast we starve. Starvation float64 // Current level of starvation. ExhaustionRate float64 // How fast we get tired. Exhaustion float64 // Current level of exhaustion. }
CompStats is a stats component.
type Config ¶
Config holds important settings to perform the calculation
GridWidth and GridHeight are required and represents the size of the grid
InvalidNodes can be used to add not accessible nodes like obstacles etc. WeightedNodes can be used to add nodes to be avoided like mud or mountains
type Entity ¶
type Entity interface { ID() int64 // ID returns the ID of the entity. String() string // String returns a string representation of the entity. Type() EntityType // Type returns the type of the entity. Pos() vectors.Vec2 // Pos returns the momentary position of the entity. Update(delta float64) // Update updates the state of the entity. Dead() bool // Dead returns true if the entity is dead. TakeDamage(damage float64, attacker Entity) // TakeDamage applies damage to the entity. }
type EntityType ¶
type EntityType int
const ( EntityTypeBeing EntityType = iota EntityTypeItem EntityTypeObstacle )
type EventAttackData ¶
type EventAttackData struct {
Damage float64
}
EventAttackData represents the data for an EventAttack event.
type EventListener ¶
type EventListener struct {
Events []*Event
}
EventListener is an event listener that can be added to an Entity.
func (*EventListener) FindType ¶
func (l *EventListener) FindType(eventType EventType) *Event
FindType finds an event of a specific type. This is a temporary solution until we have a better event system.
func (*EventListener) Notify ¶
func (l *EventListener) Notify(event *Event)
Notify notifies the listener of an event.
func (*EventListener) Update ¶
func (l *EventListener) Update(delta float64)
Update updates the EventListener system.
type Events ¶
type Events struct {
Events []*Event // Recent events (will be cleared after each update).
}
Events is an event manager for communicating events like damage taken, a being killed, etc.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List represents a list of nodes
func (*List) GetIndex ¶
GetIndex returns the index of the node in the list if the node is not found the return value is -1
func (*List) GetIndexOfMinF ¶
GetIndexOfMinF returns the index of the nodes list with the smallest node.F value
if no node is found it returns -1
func (*List) GetMinFNode ¶
GetMinFNode returns the node with the smallest node.F value
type Needs ¶
type Needs struct { *AI Enemy Entity // current enemy Needs [NeedMax]bool // determines which needs need to be met Prioities []Need // determines the order of needs Aggression float64 // determines how aggressive the AI is }
Needs represents the basic needs of an AI.
func (*Needs) ActOnConflict ¶
func (n *Needs) ActOnConflict()
func (*Needs) ActOnExhaustion ¶
func (n *Needs) ActOnExhaustion()
func (*Needs) ActOnSurvival ¶
func (n *Needs) ActOnSurvival()
func (*Needs) EvalThreats ¶
func (n *Needs) EvalThreats()
type Node ¶
Node represents a simple node X and Y represents the nodes coordinates on the grid
IMPORTANT: The grid coordinates starts on the "bottom left" -> X:0 / Y:0
With the Weighting value you can set the nodes heavy grade so a node with mud or water are heavier as gras or street
type Notifiable ¶
type Notifiable interface {
Notify(event *Event)
}
Notifiable is an interface that can be implemented by entities that want to be notified of events.
type Pathfinding ¶
type Pathfinding struct { *AI Waypoints []int // Cell indices of the waypoints. WaypointIdx int // Current waypoint. Mode PathfindingMode // Current mode. }
Pathfinding represents the pathfinding of an AI.
func (*Pathfinding) SetDestination ¶
func (p *Pathfinding) SetDestination(dest *vectors.Vec2, mode PathfindingMode) error
SetDestination sets the destination of the AI, and calculates the path.
func (*Pathfinding) Update ¶
func (p *Pathfinding) Update(delta float64)
Update updates the pathfinding of the AI.
type PathfindingMode ¶
type PathfindingMode int
const ( PathfindingModeNone PathfindingMode = iota PathfindingModeMoveTo PathfindingModeFollow PathfindingModeChase PathfindingModeFleeTo )
type Perception ¶
type Perception struct { *AI Entities []Entity // All entities we can see. EntitiesNew []Entity // Newly appeared entities. Items []*Item // All items we can see. ItemsNew []*Item // Newly appeared items. }
Perception represents the perception of an AI of the world.
func (*Perception) CanSeeEntity ¶
func (p *Perception) CanSeeEntity(e Entity) bool
CanSeeEntity returns true if the AI can see the given entity. TODO: Instead we should just take a position and check if we have line of sight to that position, plus some modifier based on the entity's size or stealth.
func (*Perception) Update ¶
func (p *Perception) Update(delta float64)
Update updates the perception of the world. TODO: Based on insight, we should be able to gain an understanding of the motives of other beings. This will allow us to make better decisions, like whether to attack or flee from a threat.
type World ¶
type World struct { Beings []Entity Items []*Item Width int Height int Cells []bool Events *Events // contains filtered or unexported fields }
World represents the game world.
func (*World) CellIdxToPos ¶
CellIdxToPos returns the position for a cell index.
func (*World) CheckIdxReachable ¶
CheckIdxReachable checks if a cell is reachable.
func (World) ExportWebp ¶
func (*World) GetEntitiesInRadius ¶
GetEntitiesInRadius returns all entities within a radius of a position.
func (*World) GetItemsInRadius ¶
GetItemsInRadius returns all items within a radius of a position.
func (*World) PosToCellIdx ¶
PosToCellIdx returns the cell index for a position.