Exemplo n.º 1
0
func TestFov(t *testing.T) {
	mf := space.NewManifold()

	mf.SetPortal(space.Loc(10, 11, 1), space.Port(20, 20, 20))
	seen := map[image.Point]space.Location{}

	// Impassable barrier on every zone at x == 11
	blockFn := func(loc space.Location) bool { return loc.X == 11 }
	markFn := func(pt image.Point, loc space.Location) {
		seen[pt] = loc
	}

	fov := New(blockFn, markFn, mf)

	fov.Run(space.Loc(10, 10, 1), 4)

	if _, ok := seen[image.Pt(-2, 0)]; !ok {
		t.Fail()
	}

	if _, ok := seen[image.Pt(2, 0)]; ok {
		// Should be stopped by blockFn barrier
		t.Fail()
	}

	if loc, ok := seen[image.Pt(0, 2)]; ok {
		// This one should be through the portal.
		if loc.Zone != 20 {
			t.Fail()
		}
	} else {
		t.Fail()
	}
}
Exemplo n.º 2
0
func New() (world *World) {
	world = new(World)
	world.Manifold = space.NewManifold()
	world.terrain = make(map[space.Location]Terrain)
	world.Spatial = space.NewIndex()
	world.actors = []entity.Entity{}
	world.nextActors = []entity.Entity{}
	return
}