Esempio n. 1
0
File: game.go Progetto: PieterD/crap
func (g *Game) Draw(d grid.DrawableGrid) {
	gridutil.SingleBox(d, d.GridSize(), grid.White, grid.Black)
	gridutil.Text(d, image.Point{X: 2, Y: 2}, "Hello moo", grid.Red, grid.Black)
	var arrow int
	switch g.dir {
	case 0:
		arrow = 24
	case 1:
		arrow = 26
	case 2:
		arrow = 25
	case 3:
		arrow = 27
	}
	d.Set(g.x, g.y, arrow, grid.Green, grid.Black)
}
Esempio n. 2
0
File: text.go Progetto: PieterD/crap
func Text(d grid.DrawableGrid, start image.Point, text string, fore, back grid.Color) {
	x := start.X
	y := start.Y
	for {
		r, l := utf8.DecodeRuneInString(text)
		if l == 0 {
			return
		}
		if l == 1 && r == utf8.RuneError {
			panic(fmt.Errorf("Invalid utf-8"))
		}
		if l > 1 {
			panic(fmt.Errorf("Non-ascii character: '%c (%d)'", r, r))
		}
		d.Set(x, y, int(r), fore, back)
		x++
		text = text[l:]
	}
}
Esempio n. 3
0
File: box.go Progetto: PieterD/crap
func drawBox(d grid.DrawableGrid, bounds image.Rectangle, fore, back grid.Color, parts []int) {
	for x := bounds.Min.X + 1; x < bounds.Max.X-1; x++ {
		d.Set(x, bounds.Min.Y, parts[0], fore, back)
		d.Set(x, bounds.Max.Y-1, parts[0], fore, back)
	}
	for y := bounds.Min.Y + 1; y < bounds.Max.Y-1; y++ {
		d.Set(0, y, parts[1], fore, back)
		d.Set(bounds.Max.X-1, y, parts[1], fore, back)
	}
	d.Set(bounds.Min.X, bounds.Min.Y, parts[2], fore, back)
	d.Set(bounds.Max.X-1, bounds.Min.Y, parts[3], fore, back)
	d.Set(bounds.Max.X-1, bounds.Max.Y-1, parts[4], fore, back)
	d.Set(bounds.Min.X, bounds.Max.Y-1, parts[5], fore, back)
}