예제 #1
0
func writeMapLayout() {
	var l sortMap

	layout.AllTiles(func(c layout.Coord, t layout.MultiTile) {
		if t.Space() {
			return
		}
		l = append(l, struct {
			C layout.Coord
			T layout.MultiTile
		}{c, t})
	})

	sort.Sort(l)

	f, err := os.Create("map.go")
	if err != nil {
		panic(err)
	}
	fmt.Fprint(f, beforeLayout)
	for _, t := range l {
		fmt.Fprintf(f, "\n\tCoord{%d, %d}: %s,", t.C.X, t.C.Y, t.T)
	}
	fmt.Fprint(f, afterLayout)
	f.Close()
}
예제 #2
0
func (l *Lighting) recalculateLightmap() {
	layout.AllTiles(func(c layout.Coord, tile layout.MultiTile) {
		for _, t := range tile {
			if brightness := t.LightLevel(); brightness != 0 && power.Powered(c.X, c.Y, t) {
				l.spread(c, brightness)
			}
		}
	})
}
예제 #3
0
func writeMapTest() {
	minX, minY, maxX, maxY := 0, 0, 0, 0
	layout.AllTiles(func(c layout.Coord, t layout.MultiTile) {
		if t.Space() {
			return
		}
		if c.X < minX {
			minX = c.X
		}
		if c.Y < minY {
			minY = c.Y
		}
		if c.X > maxX {
			maxX = c.X
		}
		if c.Y > maxY {
			maxY = c.Y
		}
	})
	minX--
	minY--
	maxX++
	maxY++

	dx := maxX - minX
	dy := maxY - minY
	dx++
	dy++

	buf := make([]byte, dx*dy+dy-1)
	i := 0
	for y := minY; y <= maxY; y++ {
		if i != 0 {
			buf[i] = '\n'
			i++
		}
		for x := minX; x <= maxX; x++ {
			t := layout.Get(x, y)
			if t.Space() {
				buf[i] = ' '
			} else if t.Door() {
				if t.Passable() {
					buf[i] = 'd'
				} else {
					buf[i] = 'D'
				}
			} else if t.Passable() {
				buf[i] = '_'
			} else if t.BlocksVision() {
				buf[i] = 'W'
			} else {
				buf[i] = 'G'
			}
			i++
		}
	}

	f, err := os.Create("map_test.go")
	if err != nil {
		panic(err)
	}
	fmt.Fprint(f, beforeTest)
	fmt.Fprint(f, "\n\ttop   = ", minY)
	fmt.Fprint(f, "\n\tleft  = ", minX)
	fmt.Fprint(f, "\n\tcheck = `", string(buf), "`\n")
	fmt.Fprint(f, afterTest)
	f.Close()
}