Ejemplo n.º 1
0
func (a *Action) DoFov(obj entity.Entity) {
	// TODO: Parametrisable radius
	const radius = 12
	if f, ok := obj.(entity.Fov); ok {
		fv := fov.New(
			func(loc space.Location) bool { return a.world.Terrain(loc).BlocksSight() },
			func(pt image.Point, loc space.Location) { f.MarkFov(pt, loc) },
			a.world.Manifold)
		fv.Run(a.query.Loc(obj), radius)
	}
}
Ejemplo n.º 2
0
func (q *Query) VisibleEntities(loc space.Location, radius int) []space.OffsetEntity {
	seen := map[space.OffsetEntity]bool{}
	fv := fov.New(
		func(loc space.Location) bool { return q.world.Terrain(loc).BlocksSight() },
		func(pt image.Point, loc space.Location) {
			for _, oe := range q.world.Spatial.At(loc) {
				seen[space.OffsetEntity{oe.Entity, pt.Add(oe.Offset)}] = true
			}
		},
		q.world.Manifold)
	fv.Run(loc, radius)

	result := []space.OffsetEntity{}
	for oe, _ := range seen {
		result = append(result, oe)
	}
	return result
}