Documentation
¶
Overview ¶
Package tilemap provides tile-based coordinate conversion and occupancy tracking.
TileCoord represents integer tile coordinates. WorldPositionToTile and TileToWorldPosition convert between continuous world space (Vector2) and discrete tile space. TileOccupancyManager tracks which entity occupies each tile, used by movement and pathfinding to avoid collisions.
SpatialGrid partitions the world into configurable-size cells keyed by TileCoord for efficient spatial neighbor queries.
Index ¶
- func TileToWorldPosition(tile TileCoord) geometry.Vector2
- type EntitySet
- type SpatialGrid
- func (sg *SpatialGrid) AddEntity(entity ecs.EntityId, position geometry.Vector2)
- func (sg *SpatialGrid) GetRange(rect geometry.Rectangle) []ecs.EntityId
- func (sg *SpatialGrid) RemoveEntity(entity ecs.EntityId, position geometry.Vector2)
- func (sg *SpatialGrid) UpdateEntityPosition(entity ecs.EntityId, oldPosition, newPosition geometry.Vector2)
- type TileCoord
- type TileOccupancyManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TileToWorldPosition ¶
TileToWorldPosition converts tile coordinates to world coordinates (tile centers)
Types ¶
type SpatialGrid ¶
type SpatialGrid struct {
// contains filtered or unexported fields
}
SpatialGrid divides the game world into cells, allowing for efficient spatial queries.
func NewSpatialGrid ¶
func NewSpatialGrid(cellSize float64) *SpatialGrid
NewSpatialGrid creates a new SpatialGrid with the specified cell size. cellSize determines the size of each cell in world units.
func (*SpatialGrid) AddEntity ¶
func (sg *SpatialGrid) AddEntity(entity ecs.EntityId, position geometry.Vector2)
AddEntity adds an entity to the SpatialGrid at the given position. entity is the ID of the entity, and position is its world position.
func (*SpatialGrid) GetRange ¶
func (sg *SpatialGrid) GetRange(rect geometry.Rectangle) []ecs.EntityId
GetRange returns all entities within the specified rectangular area. It iterates through the cells that intersect with the rectangle and collects entities from those cells.
Parameters:
- rect: The rectangular area to search within.
Returns:
- A slice of EntityId containing all entities within the rectangle.
func (*SpatialGrid) RemoveEntity ¶
func (sg *SpatialGrid) RemoveEntity(entity ecs.EntityId, position geometry.Vector2)
RemoveEntity removes an entity from the SpatialGrid at the given position. entity is the ID of the entity, and position is its world position.
func (*SpatialGrid) UpdateEntityPosition ¶
func (sg *SpatialGrid) UpdateEntityPosition(entity ecs.EntityId, oldPosition, newPosition geometry.Vector2)
UpdateEntityPosition moves an entity from its old position to a new position within the SpatialGrid. entity is the ID of the entity, oldPosition is the entity's previous position, and newPosition is the entity's updated position.
type TileCoord ¶
type TileCoord struct {
X, Y int
}
TileCoord represents integer tile coordinates in the game world
func WorldPositionToTile ¶
WorldPositionToTile converts world coordinates to tile coordinates (1.0-unit tiles)
type TileOccupancyManager ¶
type TileOccupancyManager struct {
// contains filtered or unexported fields
}
TileOccupancyManager tracks which entity occupies each tile
func NewTileOccupancyManager ¶
func NewTileOccupancyManager() *TileOccupancyManager
NewTileOccupancyManager creates a new tile occupancy manager
func (*TileOccupancyManager) ClearOccupant ¶
func (tom *TileOccupancyManager) ClearOccupant(tile TileCoord)
ClearOccupant removes any entity from the given tile
func (*TileOccupancyManager) GetOccupant ¶
func (tom *TileOccupancyManager) GetOccupant(tile TileCoord) (ecs.EntityId, bool)
GetOccupant returns the entity ID occupying the given tile and whether it's occupied
func (*TileOccupancyManager) IsOccupied ¶
func (tom *TileOccupancyManager) IsOccupied(tile TileCoord) bool
IsOccupied returns true if the tile is occupied by any entity
func (*TileOccupancyManager) SetOccupant ¶
func (tom *TileOccupancyManager) SetOccupant(tile TileCoord, entityId ecs.EntityId)
SetOccupant sets the entity occupying the given tile