Beispiel #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
}
Beispiel #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)
		}
	}
}
Beispiel #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
}
Beispiel #4
0
func warp(p draw.Point, x int) int {
	if !suspended && piece != nil {
		x = pos.X + piece.sz.X*pcsz/2
		if p.Y < rboard.Min.Y {
			p.Y = rboard.Min.Y
		}
		if p.Y >= rboard.Max.Y {
			p.Y = rboard.Max.Y - 1
		}
		//moveto(mousectl, draw.Pt(x, p.Y));
	}
	return x
}