예제 #1
0
func (p *paddle) draw(canvasEl *dom.HTMLCanvasElement) {
	newYPos := p.yPos + p.yMovement
	if newYPos > 5 && newYPos < (canvasEl.Height-p.height-5) {
		p.yPos = newYPos
	}

	ctx := canvasEl.GetContext2d()
	ctx.FillStyle = "#0000ff"
	ctx.FillRect(p.xPos, p.yPos, p.width, p.height)
}
예제 #2
0
func (b *ball) draw(canvasEl *dom.HTMLCanvasElement) {
	b.xPos += int(math.Floor(b.xMovement + 0.5))
	b.yPos += int(math.Floor(b.yMovement + 0.5))

	ctx := canvasEl.GetContext2d()
	ctx.FillStyle = "red"
	ctx.BeginPath()
	ctx.Arc(b.xPos, b.yPos, b.radius, 0, 6, false)
	ctx.Fill()
	ctx.ClosePath()
}