Exemplo n.º 1
0
func horiz() bool {
	var lev [MAXN]int
	h := 0
	for i := 0; i < NY; i++ {
		for j := 0; board[i][j] != 0; j++ {
			if j == NX-1 {
				lev[h] = i
				h++
				break
			}
		}
	}
	if h == 0 {
		return false
	}
	r := rboard
	newscreen = false
	for j := 0; j < h; j++ {
		r.Min.Y = rboard.Min.Y + lev[j]*pcsz
		r.Max.Y = r.Min.Y + pcsz
		draw.DrawMask(screen, r, image.White, image.ZP, whitemask, image.ZP, draw.Over)
		display.FlushImage()
	}
	PlaySound(whoosh)
	for i := 0; i < 3; i++ {
		pause(250)
		if newscreen {
			drawboard()
			break
		}
		for j := 0; j < h; j++ {
			r.Min.Y = rboard.Min.Y + lev[j]*pcsz
			r.Max.Y = r.Min.Y + pcsz
			draw.DrawMask(screen, r, image.White, image.ZP, whitemask, image.ZP, draw.Over)
		}
		display.FlushImage()
	}
	r = rboard
	for j := 0; j < h; j++ {
		i := NY - lev[j] - 1
		score(250 + 10*i*i)
		r.Min.Y = rboard.Min.Y
		r.Max.Y = rboard.Min.Y + lev[j]*pcsz
		draw.Draw(screen, r.Add(image.Pt(0, pcsz)), screen, r.Min)
		r.Max.Y = rboard.Min.Y + pcsz
		draw.Draw(screen, r, image.White, image.ZP)
		for k := lev[j] - 1; k >= 0; k-- {
			board[k+1] = board[k]
		}
		board[0] = [NX]byte{}
	}
	display.FlushImage()
	return true
}
Exemplo n.º 2
0
func undrawpiece() {
	var mask image.Image
	if collider(pos, br.Max) {
		mask = bbmask
	}
	draw.DrawMask(screen, br.Add(pos), image.White, bbr.Min, mask, bbr.Min, draw.Over)
}
Exemplo n.º 3
0
func setpiece(p *Piece) {
	draw.Draw(bb, bbr, image.White, image.ZP)
	draw.Draw(bbmask, bbr, image.Transparent, image.ZP)
	br = image.Rect(0, 0, 0, 0)
	br2 = br
	piece = p
	if p == nil {
		return
	}
	var op image.Point
	var r image.Rectangle
	r.Min = bbr.Min
	for i, pt := range p.d {
		r.Min.X += pt.X * pcsz
		r.Min.Y += pt.Y * pcsz
		r.Max.X = r.Min.X + pcsz
		r.Max.Y = r.Min.Y + pcsz
		if i == 0 {
			draw.Draw(bb, r, image.Black, image.ZP)
			draw.Draw(bb, r.Inset(1), txpix[piece.tx], image.ZP)
			draw.Draw(bbmask, r, image.Opaque, image.ZP)
			op = r.Min
		} else {
			draw.Draw(bb, r, bb, op)
			draw.Draw(bbmask, r, bbmask, op)
		}
		if br.Max.X < r.Max.X {
			br.Max.X = r.Max.X
		}
		if br.Max.Y < r.Max.Y {
			br.Max.Y = r.Max.Y
		}
	}
	br.Max = br.Max.Sub(bbr.Min)
	delta := image.Pt(0, DY)
	br2.Max = br.Max.Add(delta)
	r = br.Add(bb2r.Min)
	r2 := br2.Add(bb2r.Min)
	draw.Draw(bb2, r2, image.White, image.ZP)
	draw.Draw(bb2, r.Add(delta), bb, bbr.Min)
	draw.Draw(bb2mask, r2, image.Transparent, image.ZP)
	draw.DrawMask(bb2mask, r, image.Opaque, bbr.Min, bbmask, image.ZP, draw.Over)
	draw.DrawMask(bb2mask, r.Add(delta), image.Opaque, bbr.Min, bbmask, image.ZP, draw.Over)
}
Exemplo n.º 4
0
func movepiece() bool {
	var mask image.Image
	if collide(image.Pt(pos.X, pos.Y+pcsz), piece) {
		return false
	}
	if collider(pos, br2.Max) {
		mask = bb2mask
	}
	draw.DrawMask(screen, br2.Add(pos), bb2, bb2r.Min, mask, bb2r.Min, draw.Over)
	pos.Y += DY
	display.FlushImage()
	return true
}
Exemplo n.º 5
0
func (c *conn) FlushImageRect(r image.Rectangle) {
	c.flushLock.Lock()
	draw.DrawMask(c.bufimg, r, c.img, r.Min, nil, image.ZP, draw.Src)
	c.dirty = c.dirty.Union(r)
	// We do the send (the <- operator) in an expression context, rather than in
	// a statement context, so that it does not block, and fails if the buffered
	// channel is full (in which case there already is a flush request pending).
	// We send with the lock held to avoid the flusher picking up our flush
	// notification after it has actually dealt with it.
	select {
	case c.flush <- false:
	default:
	}
	c.flushLock.Unlock()
}
Exemplo n.º 6
0
func drawboard() {
	draw.Border(screen, rboard.Inset(-2), 2, image.Black, image.ZP)
	draw.Draw(screen, image.Rect(rboard.Min.X, rboard.Min.Y-2, rboard.Max.X, rboard.Min.Y),
		image.White, image.ZP)
	for i := 0; i < NY; i++ {
		for j := 0; j < NX; j++ {
			if board[i][j] != 0 {
				drawsq(screen, image.Pt(rboard.Min.X+j*pcsz, rboard.Min.Y+i*pcsz), int(board[i][j]-16))
			}
		}
	}
	score(0)
	if suspended {
		draw.DrawMask(screen, screenr, image.White, image.ZP, whitemask, image.ZP, draw.Over)
	}
}
Exemplo n.º 7
0
func (t *Tile) Draw(dst draw.Image, clipr draw.Rectangle) {
	r := t.r.Clip(clipr)
	draw.DrawMask(dst, r, t.image, r.Min.Sub(t.r.Min), nil, draw.ZP, draw.Src)
}
Exemplo n.º 8
0
func drawpiece() {
	draw.DrawMask(screen, br.Add(pos), bb, bbr.Min, bbmask, image.ZP, draw.Over)
	if suspended {
		draw.DrawMask(screen, br.Add(pos), image.White, image.ZP, whitemask, image.ZP, draw.Over)
	}
}