Example #1
1
func collide(pt draw.Point, p *Piece) bool {
	pt.X = (pt.X - rboard.Min.X) / pcsz
	pt.Y = (pt.Y - rboard.Min.Y) / pcsz
	for _, q := range p.d {
		pt.X += q.X
		pt.Y += q.Y
		if pt.X < 0 || pt.X >= NX || pt.Y < 0 || pt.Y >= NY {
			return true
			continue
		}
		if board[pt.Y][pt.X] != 0 {
			return true
		}
	}
	return false
}
Example #2
0
func (t *Tiler) Draw(dst draw.Image, clipr draw.Rectangle) {
	if t.current == nil {
		panic("no current")
	}
	min := draw.Point{
		roundDown(clipr.Min.X, t.tileSize),
		roundDown(clipr.Min.Y, t.tileSize),
	}
	var p draw.Point
	for p.Y = min.Y; p.Y < clipr.Max.Y; p.Y += t.tileSize {
		for p.X = min.X; p.X < clipr.Max.X; p.X += t.tileSize {
			tile := t.all.Get(p.X, p.Y, t.calc)
			if tile == nil {
				tile = NewTile(
					draw.Rect(p.X, p.Y, p.X+t.tileSize, p.Y+t.tileSize),
					t.calc,
					nil,
					false,
				)
				t.all.Set(p.X, p.Y, t.calc, tile)
				t.current[tile] = true
				tile.Go(t.updatec)
			} else if !t.current[tile] {
				tile.Go(t.updatec)
			}
			tile.Draw(dst, clipr)
		}
	}
}
Example #3
0
func canfit(p *Piece) bool {
	var dx = [...]int{0, -1, 1, -2, 2, -3, 3, 4, -4}
	j := N + 1
	if j >= 4 {
		j = p.sz.X
		if j < p.sz.Y {
			j = p.sz.Y
		}
		j = 2*j - 1
	}
	for i := 0; i < j; i++ {
		var z draw.Point
		z.X = pos.X + dx[i]*pcsz
		z.Y = pos.Y
		if !collide(z, p) {
			z.Y = pos.Y + pcsz - 1
			if !collide(z, p) {
				undrawpiece()
				pos.X = z.X
				return true
			}
		}
	}
	return false
}