Example #1
1
func update(screen *ebiten.Image) error {
	if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
		count++
	}

	mx, my := ebiten.CursorPosition()

	if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
		op := &ebiten.DrawImageOptions{}
		op.GeoM.Translate(float64(mx), float64(my))
		op.ColorM.Scale(1.0, 0.25, 0.25, 1.0)
		theta := 2.0 * math.Pi * float64(count%60) / 60.0
		op.ColorM.Concat(ebiten.RotateHue(theta))
		if err := canvasImage.DrawImage(brushImage, op); err != nil {
			return err
		}
	}

	if err := screen.DrawImage(canvasImage, nil); err != nil {
		return err
	}

	if err := ebitenutil.DebugPrint(screen, fmt.Sprintf("(%d, %d)", mx, my)); err != nil {
		return err
	}
	return nil
}
Example #2
0
func update(screen *ebiten.Image) error {
	readKeys()
	select {
	case <-simulationTimer:
		newSimulation := currentSimulation.Step()
		wires := currentSimulation.Circuit().Wires()
		for i, wire := range wires {
			oldCharge := currentSimulation.State(wire).Charge()
			charge := newSimulation.State(wire).Charge()
			if oldCharge == charge {
				continue
			}
			position := wire.Bounds().Min
			op := &ebiten.DrawImageOptions{}
			op.GeoM.Translate(float64(position.X), float64(position.Y))
			r, g, b, a := simulationImage.Palette[charge+1].RGBA()
			op.ColorM.Scale(float64(r)/0xFFFF, float64(g)/0xFFFF, float64(b)/0xFFFF, float64(a)/0xFFFF)
			if err := backgroundImage.DrawImage(wireImages[i], op); err != nil {
				return err
			}
		}
		currentSimulation = newSimulation
	default:
	}

	if err := screen.DrawImage(backgroundImage, &ebiten.DrawImageOptions{}); err != nil {
		return err
	}

	if err := handleCursor(screen); err != nil {
		return err
	}
	return nil
}
Example #3
0
func update(screen *ebiten.Image) error {
	drawn := false
	mx, my := ebiten.CursorPosition()
	if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
		if err := paint(screen, mx, my); err != nil {
			return err
		}
		drawn = true
	}
	for _, t := range ebiten.Touches() {
		x, y := t.Position()
		if err := paint(screen, x, y); err != nil {
			return err
		}
		drawn = true
	}
	if drawn {
		count++
	}

	if err := screen.DrawImage(canvasImage, nil); err != nil {
		return err
	}

	msg := fmt.Sprintf("(%d, %d)", mx, my)
	for _, t := range ebiten.Touches() {
		x, y := t.Position()
		msg += fmt.Sprintf("\n(%d, %d) touch %d", x, y, t.ID())
	}
	if err := ebitenutil.DebugPrint(screen, msg); err != nil {
		return err
	}
	return nil
}
Example #4
0
func (s *GamepadScene) Draw(screen *ebiten.Image) error {
	screen.Fill(color.Black)

	if s.buttonStates == nil {
		return nil
	}

	f := `GAMEPAD CONFIGURATION
(PRESS ESC TO CANCEL)


MOVE LEFT:    %s

MOVE RIGHT:   %s

DROP:         %s

ROTATE LEFT:  %s

ROTATE RIGHT: %s



%s`
	msg := ""
	if s.currentIndex == len(gamepadStdButtons) {
		msg = "OK!"
	}
	str := fmt.Sprintf(f, s.buttonStates[0], s.buttonStates[1], s.buttonStates[2], s.buttonStates[3], s.buttonStates[4], msg)
	if err := common.ArcadeFont.DrawTextWithShadow(screen, str, 16, 16, 1, color.White); err != nil {
		return err
	}
	return nil
}
Example #5
0
func update(screen *ebiten.Image) error {
	count++
	count %= 600
	diff := float64(count) * 0.2
	switch {
	case 480 < count:
		diff = 0
	case 240 < count:
		diff = float64(480-count) * 0.2
	}

	if err := tmpRenderTarget.Clear(); err != nil {
		return err
	}
	for i := 0; i < 10; i++ {
		op := &ebiten.DrawImageOptions{}
		op.GeoM.Translate(15+float64(i)*diff, 20)
		op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
		if err := tmpRenderTarget.DrawImage(ebitenImage, op); err != nil {
			return err
		}
	}

	screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
	for i := 0; i < 10; i++ {
		op := &ebiten.DrawImageOptions{}
		op.GeoM.Translate(0, float64(i)*diff)
		if err := screen.DrawImage(tmpRenderTarget, op); err != nil {
			return err
		}
	}

	return nil
}
Example #6
0
func drawGroundImage(screen *ebiten.Image, ground *ebiten.Image) error {
	op := &ebiten.DrawImageOptions{}
	if err := screen.DrawImage(ground, op); err != nil {
		return err
	}
	return nil
}
Example #7
0
func (s *SceneManager) Draw(r *ebiten.Image) error {
	if s.transitionCount == -1 {
		return s.current.Draw(r)
	}
	if err := transitionFrom.Clear(); err != nil {
		return err
	}
	if err := s.current.Draw(transitionFrom); err != nil {
		return err
	}

	if err := transitionTo.Clear(); err != nil {
		return err
	}
	if err := s.next.Draw(transitionTo); err != nil {
		return err
	}

	if err := r.DrawImage(transitionFrom, nil); err != nil {
		return err
	}

	alpha := float64(s.transitionCount) / float64(transitionMaxCount)
	op := &ebiten.DrawImageOptions{}
	op.ColorM.Scale(1, 1, 1, alpha)
	return r.DrawImage(transitionTo, op)
}
Example #8
0
func update(screen *ebiten.Image) error {
	if ebiten.IsKeyPressed(ebiten.KeySpace) {
		thePlayer.MoveForward()
	}
	rotated := false
	if ebiten.IsKeyPressed(ebiten.KeyRight) {
		thePlayer.RotateRight()
		rotated = true
	}
	if ebiten.IsKeyPressed(ebiten.KeyLeft) {
		thePlayer.RotateLeft()
		rotated = true
	}
	if !rotated {
		thePlayer.Stabilize()
	}

	if err := screen.Fill(skyColor); err != nil {
		return err
	}
	if err := updateGroundImage(groundImage); err != nil {
		return err
	}
	if err := drawGroundImage(screen, groundImage); err != nil {
		return err
	}

	tutrial := "Space: Move forward\nLeft/Right: Rotate"
	msg := fmt.Sprintf("FPS: %0.2f\n%s", ebiten.CurrentFPS(), tutrial)
	if err := ebitenutil.DebugPrint(screen, msg); err != nil {
		return err
	}
	return nil
}
Example #9
0
func update(screen *ebiten.Image) error {
	if ebiten.IsKeyPressed(ebiten.KeyLeft) {
		sprites.num -= 20
		if sprites.num < MinSprites {
			sprites.num = MinSprites
		}
	}
	if ebiten.IsKeyPressed(ebiten.KeyRight) {
		sprites.num += 20
		if MaxSprites < sprites.num {
			sprites.num = MaxSprites
		}
	}
	sprites.Update()

	if ebiten.IsRunningSlowly() {
		return nil
	}
	op := &ebiten.DrawImageOptions{
		ImageParts: sprites,
	}
	op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
	if err := screen.DrawImage(ebitenImage, op); err != nil {
		return err
	}
	msg := fmt.Sprintf(`FPS: %0.2f
Num of sprites: %d
Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.Len())
	if err := ebitenutil.DebugPrint(screen, msg); err != nil {
		return err
	}
	return nil
}
Example #10
0
func (s *GameScene) drawBackground(r *ebiten.Image) error {
	if err := r.Fill(color.White); err != nil {
		return err
	}

	w, h := imageGameBG.Size()
	scaleW := ScreenWidth / float64(w)
	scaleH := ScreenHeight / float64(h)
	scale := scaleW
	if scale < scaleH {
		scale = scaleH
	}

	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
	op.GeoM.Scale(scale, scale)
	op.GeoM.Translate(ScreenWidth/2, ScreenHeight/2)

	a := 0.7
	m := ebiten.Monochrome()
	m.Scale(a, a, a, a)
	op.ColorM.Scale(1-a, 1-a, 1-a, 1-a)
	op.ColorM.Add(m)
	op.ColorM.Translate(0.3, 0.3, 0.3, 0)
	return r.DrawImage(imageGameBG, op)
}
Example #11
0
func drawBlocks(r *ebiten.Image, blocks [][]BlockType, x, y int, clr ebiten.ColorM) error {
	op := &ebiten.DrawImageOptions{
		ImageParts: blocksImageParts(blocks),
		ColorM:     clr,
	}
	op.GeoM.Translate(float64(x), float64(y))
	return r.DrawImage(imageBlocks, op)
}
Example #12
0
func update(screen *ebiten.Image) error {
	world.Progress()
	world.DrawImage(noiseImage)
	if err := screen.ReplacePixels(noiseImage.Pix); err != nil {
		return err
	}
	return nil
}
Example #13
0
func drawWindow(r *ebiten.Image, x, y, width, height int) error {
	op := &ebiten.DrawImageOptions{}
	w, h := imageEmpty.Size()
	op.GeoM.Scale(float64(width)/float64(w), float64(height)/float64(h))
	op.GeoM.Translate(float64(x), float64(y))
	op.ColorM.Scale(0, 0, 0, 0.75)
	return r.DrawImage(imageEmpty, op)
}
Example #14
0
func (t *Tile) Draw(boardImage *ebiten.Image) error {
	i, j := t.current.x, t.current.y
	ni, nj := t.next.x, t.next.y
	v := t.current.value
	if v == 0 {
		return nil
	}
	op := &ebiten.DrawImageOptions{}
	x := i*tileSize + (i+1)*tileMargin
	y := j*tileSize + (j+1)*tileMargin
	nx := ni*tileSize + (ni+1)*tileMargin
	ny := nj*tileSize + (nj+1)*tileMargin
	switch {
	case 0 < t.movingCount:
		rate := 1 - float64(t.movingCount)/maxMovingCount
		x = mean(x, nx, rate)
		y = mean(y, ny, rate)
	case 0 < t.startPoppingCount:
		rate := 1 - float64(t.startPoppingCount)/float64(maxPoppingCount)
		scale := meanF(0.0, 1.0, rate)
		op.GeoM.Translate(float64(-tileSize/2), float64(-tileSize/2))
		op.GeoM.Scale(scale, scale)
		op.GeoM.Translate(float64(tileSize/2), float64(tileSize/2))
	case 0 < t.poppingCount:
		const maxScale = 1.2
		rate := 0.0
		if maxPoppingCount*2/3 <= t.poppingCount {
			// 0 to 1
			rate = 1 - float64(t.poppingCount-2*maxPoppingCount/3)/float64(maxPoppingCount/3)
		} else {
			// 1 to 0
			rate = float64(t.poppingCount) / float64(maxPoppingCount*2/3)
		}
		scale := meanF(1.0, maxScale, rate)
		op.GeoM.Translate(float64(-tileSize/2), float64(-tileSize/2))
		op.GeoM.Scale(scale, scale)
		op.GeoM.Translate(float64(tileSize/2), float64(tileSize/2))
	}
	op.GeoM.Translate(float64(x), float64(y))
	r, g, b, a := colorToScale(tileBackgroundColor(v))
	op.ColorM.Scale(r, g, b, a)
	if err := boardImage.DrawImage(tileImage, op); err != nil {
		return err
	}
	str := strconv.Itoa(v)
	scale := 2
	if 2 < len(str) {
		scale = 1
	}
	w := common.ArcadeFont.TextWidth(str) * scale
	h := common.ArcadeFont.TextHeight(str) * scale
	x = x + (tileSize-w)/2
	y = y + (tileSize-h)/2
	if err := common.ArcadeFont.DrawText(boardImage, str, x, y, scale, tileColor(v)); err != nil {
		return err
	}
	return nil
}
Example #15
0
func update(screen *ebiten.Image) error {
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Scale(1.0/mosaicRatio, 1.0/mosaicRatio)
	gophersRenderTarget.DrawImage(gophersImage, op)
	op = &ebiten.DrawImageOptions{}
	op.GeoM.Scale(mosaicRatio, mosaicRatio)
	screen.DrawImage(gophersRenderTarget, op)
	return nil
}
Example #16
0
func (s *GameScene) Draw(r *ebiten.Image) error {
	if err := s.drawBackground(r); err != nil {
		return err
	}

	if err := r.DrawImage(imageWindows, nil); err != nil {
		return err
	}

	// Draw score
	x, y := scoreTextBoxPosition()
	if err := drawTextBoxContent(r, strconv.Itoa(s.score), x, y, textBoxWidth()); err != nil {
		return err
	}

	// Draw level
	x, y = levelTextBoxPosition()
	if err := drawTextBoxContent(r, strconv.Itoa(s.level()), x, y, textBoxWidth()); err != nil {
		return err
	}

	// Draw lines
	x, y = linesTextBoxPosition()
	if err := drawTextBoxContent(r, strconv.Itoa(s.lines), x, y, textBoxWidth()); err != nil {
		return err
	}

	// Draw blocks
	fieldX, fieldY := fieldWindowPosition()
	if err := s.field.Draw(r, fieldX, fieldY); err != nil {
		return err
	}
	if s.currentPiece != nil && !s.field.Flushing() {
		x := fieldX + s.currentPieceX*blockWidth
		y := fieldY + s.currentPieceY*blockHeight
		if err := s.currentPiece.Draw(r, x, y, s.currentPieceAngle); err != nil {
			return err
		}
	}
	if s.nextPiece != nil {
		// TODO: Make functions to get these values.
		x := fieldX + fieldWidth + blockWidth*2
		y := fieldY + blockHeight
		if err := s.nextPiece.DrawAtCenter(r, x, y, blockWidth*5, blockHeight*5, 0); err != nil {
			return err
		}
	}

	if s.gameover {
		if err := r.DrawImage(imageGameover, nil); err != nil {
			return err
		}
	}

	return nil
}
Example #17
0
func update(screen *ebiten.Image) error {
	op := &ebiten.DrawImageOptions{
		ImageParts: &parts{gophersImage},
	}
	w, h := gophersImage.Size()
	maxWidth := float64(w) + float64(h)*0.75
	op.GeoM.Translate(-maxWidth/2, -float64(h)/2)
	op.GeoM.Translate(screenWidth/2, screenHeight/2)
	screen.DrawImage(gophersImage, op)
	return nil
}
Example #18
0
func update(screen *ebiten.Image) error {
	count++
	w, h := gophersImage.Size()
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2)
	op.ColorM.RotateHue(float64(count%360) * 2 * math.Pi / 360)
	if err := screen.DrawImage(gophersImage, op); err != nil {
		return err
	}
	return nil
}
Example #19
0
func updateGroundImage(ground *ebiten.Image) error {
	if err := ground.Clear(); err != nil {
		return err
	}
	x16, y16 := theViewport.Position()
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(float64(-x16)/16, float64(-y16)/16)
	if err := ground.DrawImage(repeatedBgImage, op); err != nil {
		return err
	}
	return nil
}
Example #20
0
func handleCursor(screen *ebiten.Image) error {
	mx, my := ebiten.CursorPosition()
	cursorMoved := image.Point{mx, my}.In(screen.Bounds()) && (mx != oldMouseCursorPosition.X || my != oldMouseCursorPosition.Y)
	oldMouseCursorPosition = image.Point{mx, my}
	if cursorMoved {
		cursorPosition = oldMouseCursorPosition
	} else {
		const cursorInterval = 6
		switch {
		case keyStates[ebiten.KeyUp]%cursorInterval == 0:
			cursorPosition = cursorPosition.Add(image.Point{0, -1})
			cursorMoved = true
		case keyStates[ebiten.KeyDown]%cursorInterval == 0:
			cursorPosition = cursorPosition.Add(image.Point{0, +1})
			cursorMoved = true
		case keyStates[ebiten.KeyLeft]%cursorInterval == 0:
			cursorPosition = cursorPosition.Add(image.Point{-1, 0})
			cursorMoved = true
		case keyStates[ebiten.KeyRight]%cursorInterval == 0:
			cursorPosition = cursorPosition.Add(image.Point{+1, 0})
			cursorMoved = true
		}
	}
	if cursorBlinking == 127 {
		cursorBlinking = 0
	} else {
		cursorBlinking++
	}
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Scale(0.25, .25)
	op.GeoM.Translate(float64(cursorPosition.X), float64(cursorPosition.Y))
	if cursorBlinking > 64 {
		op.ColorM.Scale(1, 1, 1, 0.25+float64(127-cursorBlinking)/255.0)
	} else {
		op.ColorM.Scale(1, 1, 1, 0.25+float64(cursorBlinking)/255.0)
	}
	if err := screen.DrawImage(cursorImage, op); err != nil {
		return err
	}
	if keyStates[ebiten.KeySpace] >= 0 ||
		ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
		if cursorMoved || !wasMouseButtonPressed {
			if err := togglePixel(cursorPosition); err != nil {
				return err
			}
			wasMouseButtonPressed = true
		}
	} else {
		wasMouseButtonPressed = false
	}
	return nil
}
Example #21
0
func update(screen *ebiten.Image) error {
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Scale(1.0/mosaicRatio, 1.0/mosaicRatio)
	if err := gophersRenderTarget.DrawImage(gophersImage, op); err != nil {
		return err
	}
	op = &ebiten.DrawImageOptions{}
	op.GeoM.Scale(mosaicRatio, mosaicRatio)
	if err := screen.DrawImage(gophersRenderTarget, op); err != nil {
		return err
	}
	return nil
}
Example #22
0
func update(screen *ebiten.Image) error {
	updateInput()
	for i, key := range keys {
		if keyStates[key] != 1 {
			continue
		}
		addNote(220*math.Exp2(float64(i-1)/12.0), 1.0)
	}

	screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})
	screen.DrawImage(pianoImage, nil)

	ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
	return nil
}
Example #23
0
func update(screen *ebiten.Image) error {
	const l = screenWidth * screenHeight
	for i := 0; i < l; i++ {
		x := randInstance.next()
		noiseImage.Pix[4*i] = uint8(x >> 24)
		noiseImage.Pix[4*i+1] = uint8(x >> 16)
		noiseImage.Pix[4*i+2] = uint8(x >> 8)
		noiseImage.Pix[4*i+3] = 0xff
	}
	if err := screen.ReplacePixels(noiseImage.Pix); err != nil {
		return err
	}
	if err := ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %f", ebiten.CurrentFPS())); err != nil {
		return err
	}
	return nil
}
Example #24
0
func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c color.Color) {
	ur, ug, ub, ua := c.RGBA()
	const max = math.MaxUint16
	r := float64(ur) / max
	g := float64(ug) / max
	b := float64(ub) / max
	a := float64(ua) / max
	if 0 < a {
		r /= a
		g /= a
		b /= a
	}
	op := &ebiten.DrawImageOptions{
		ImageParts: debugPrintImageParts(str),
	}
	op.GeoM.Translate(float64(x+1), float64(y))
	op.ColorM.Scale(r, g, b, a)
	rt.DrawImage(d.textImage, op)
}
Example #25
0
func update(screen *ebiten.Image) error {
	if ebiten.IsKeyPressed(ebiten.KeyQ) {
		hueInt--
	}
	if ebiten.IsKeyPressed(ebiten.KeyW) {
		hueInt++
	}
	if ebiten.IsKeyPressed(ebiten.KeyA) {
		saturationInt--
	}
	if ebiten.IsKeyPressed(ebiten.KeyS) {
		saturationInt++
	}
	if ebiten.IsKeyPressed(ebiten.KeyZ) {
		valueInt--
	}
	if ebiten.IsKeyPressed(ebiten.KeyX) {
		valueInt++
	}
	hueInt = clamp(hueInt, -256, 256)
	saturationInt = clamp(saturationInt, 0, 256)
	valueInt = clamp(valueInt, 0, 256)

	w, h := gophersImage.Size()
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2)
	hue := float64(hueInt) * 2 * math.Pi / 128
	saturation := float64(saturationInt) / 128
	value := float64(valueInt) / 128
	op.ColorM.ChangeHSV(hue, saturation, value)
	if err := screen.DrawImage(gophersImage, op); err != nil {
		return err
	}

	msg := fmt.Sprintf(`Hue:        %0.2f [Q][W]
Saturation: %0.2f [A][S]
Value:      %0.2f [Z][X]`, hue, saturation, value)
	if err := ebitenutil.DebugPrint(screen, msg); err != nil {
		return err
	}
	return nil
}
Example #26
0
func update(screen *ebiten.Image) error {
	const offsetX, offsetY = 24, 40
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(offsetX, offsetY)
	op.ColorM.Scale(0.5, 0.5, 0.5, 1)
	if err := screen.DrawImage(keyboardImage, op); err != nil {
		return err
	}

	pressed := []string{}
	for i := 0; i <= 9; i++ {
		if ebiten.IsKeyPressed(ebiten.Key(i) + ebiten.Key0) {
			pressed = append(pressed, string(i+'0'))
		}
	}
	for c := 'A'; c <= 'Z'; c++ {
		if ebiten.IsKeyPressed(ebiten.Key(c) - 'A' + ebiten.KeyA) {
			pressed = append(pressed, string(c))
		}
	}
	for i := 1; i <= 12; i++ {
		if ebiten.IsKeyPressed(ebiten.Key(i) + ebiten.KeyF1 - 1) {
			pressed = append(pressed, "F"+strconv.Itoa(i))
		}
	}
	for key, name := range keyNames {
		if ebiten.IsKeyPressed(key) {
			pressed = append(pressed, name)
		}
	}

	op = &ebiten.DrawImageOptions{
		ImageParts: pressedKeysParts(pressed),
	}
	op.GeoM.Translate(offsetX, offsetY)
	if err := screen.DrawImage(keyboardImage, op); err != nil {
		return err
	}

	return nil
}
Example #27
0
func update(screen *ebiten.Image) error {
	count++

	m = mandelbrot.New(*width, *height, iterations(),
		mandelbrot.Colors(hex(*inside), hex(*outside))).Image()

	mandelbrotImage, err := ebiten.NewImageFromImage(m, ebiten.FilterLinear)
	if err == nil {
		op := &ebiten.DrawImageOptions{}

		op.GeoM.Translate(-float64(*width)/2, -float64(*height)/2)
		op.GeoM.Rotate(float64(count%360) * 2 * math.Pi / 360)
		op.GeoM.Translate(float64(*width)/2, float64(*height)/2)

		if err := screen.DrawImage(mandelbrotImage, op); err != nil {
			return err
		}
	}

	return nil
}
Example #28
0
func (g *Game) Draw(screen *ebiten.Image) error {
	if g.boardImage == nil {
		var err error
		w, h := g.board.Size()
		g.boardImage, err = ebiten.NewImage(w, h, ebiten.FilterNearest)
		if err != nil {
			return err
		}
	}
	if err := screen.Fill(backgroundColor); err != nil {
		return err
	}
	if err := g.board.Draw(g.boardImage); err != nil {
		return err
	}
	op := &ebiten.DrawImageOptions{}
	sw, sh := screen.Size()
	bw, bh := g.boardImage.Size()
	x := (sw - bw) / 2
	y := (sh - bh) / 2
	op.GeoM.Translate(float64(x), float64(y))
	if err := screen.DrawImage(g.boardImage, op); err != nil {
		return err
	}
	return nil
}
Example #29
0
func (b *Board) Draw(boardImage *ebiten.Image) error {
	if err := boardImage.Fill(frameColor); err != nil {
		return err
	}
	for j := 0; j < b.size; j++ {
		for i := 0; i < b.size; i++ {
			v := 0
			op := &ebiten.DrawImageOptions{}
			x := i*tileSize + (i+1)*tileMargin
			y := j*tileSize + (j+1)*tileMargin
			op.GeoM.Translate(float64(x), float64(y))
			r, g, b, a := colorToScale(tileBackgroundColor(v))
			op.ColorM.Scale(r, g, b, a)
			if err := boardImage.DrawImage(tileImage, op); err != nil {
				return err
			}
		}
	}
	animatingTiles := map[*Tile]struct{}{}
	nonAnimatingTiles := map[*Tile]struct{}{}
	for t := range b.tiles {
		if t.IsMoving() {
			animatingTiles[t] = struct{}{}
		} else {
			nonAnimatingTiles[t] = struct{}{}
		}
	}
	for t := range nonAnimatingTiles {
		if err := t.Draw(boardImage); err != nil {
			return err
		}
	}
	for t := range animatingTiles {
		if err := t.Draw(boardImage); err != nil {
			return err
		}
	}
	return nil
}
Example #30
0
func (f *Font) DrawText(rt *ebiten.Image, str string, ox, oy, scale int, c color.Color) error {
	options := &ebiten.DrawImageOptions{
		ImageParts: &fontImageParts{str, f},
	}
	options.GeoM.Scale(float64(scale), float64(scale))
	options.GeoM.Translate(float64(ox), float64(oy))

	ur, ug, ub, ua := c.RGBA()
	const max = math.MaxUint16
	r := float64(ur) / max
	g := float64(ug) / max
	b := float64(ub) / max
	a := float64(ua) / max
	if 0 < a {
		r /= a
		g /= a
		b /= a
	}
	options.ColorM.Scale(r, g, b, a)

	return rt.DrawImage(f.image, options)
}