Пример #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
}
Пример #2
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
}
Пример #3
0
func update(screen *ebiten.Image) error {
	// TODO: API to get the available, lowest ID
	const gamepadID = 0
	axes := []string{}
	pressedButtons := []string{}

	maxAxis := ebiten.GamepadAxisNum(gamepadID)
	for a := 0; a < maxAxis; a++ {
		v := ebiten.GamepadAxis(gamepadID, a)
		axes = append(axes, fmt.Sprintf("%d: %0.6f", a, v))
	}

	maxButton := ebiten.GamepadButton(ebiten.GamepadButtonNum(gamepadID))
	for b := ebiten.GamepadButton(gamepadID); b < maxButton; b++ {
		if ebiten.IsGamepadButtonPressed(gamepadID, b) {
			pressedButtons = append(pressedButtons, strconv.Itoa(int(b)))
		}
	}

	str := `Gamepad
  Axes:
    {{.Axes}}
  Pressed Buttons: {{.Buttons}}`
	str = strings.Replace(str, "{{.Axes}}", strings.Join(axes, "\n    "), -1)
	str = strings.Replace(str, "{{.Buttons}}", strings.Join(pressedButtons, ", "), -1)
	ebitenutil.DebugPrint(screen, str)
	return nil
}
Пример #4
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
}
Пример #5
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
}
Пример #6
0
func update(screen *ebiten.Image) error {
	defer func() {
		frames++
	}()
	if frames%30 == 0 {
		addNote()
	}
	ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
	return nil
}
Пример #7
0
func update(screen *ebiten.Image) error {
	for key, _ := range keyStates {
		if !ebiten.IsKeyPressed(key) {
			keyStates[key] = 0
			continue
		}
		keyStates[key]++
	}
	d := 0
	switch screenScale {
	case 1:
		d = 32
	case 2:
		d = 16
	}

	if keyStates[ebiten.KeyUp] == 1 {
		screenHeight += d
	}
	if keyStates[ebiten.KeyDown] == 1 {
		if 16 < screenHeight {
			screenHeight -= d
		}
	}
	if keyStates[ebiten.KeyLeft] == 1 {
		if 16 < screenWidth {
			screenWidth -= d
		}
	}
	if keyStates[ebiten.KeyRight] == 1 {
		screenWidth += d
	}
	if keyStates[ebiten.KeyS] == 1 {
		screenScale = 3 - screenScale // Swap 1 and 2
	}
	ebiten.SetScreenSize(screenWidth, screenHeight)
	ebiten.SetScreenScale(screenScale)

	screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})
	w, h := gophersImage.Size()
	w2, h2 := screen.Size()
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(float64(-w+w2)/2, float64(-h+h2)/2)
	if err := screen.DrawImage(gophersImage, op); err != nil {
		return err
	}

	x, y := ebiten.CursorPosition()
	msg := fmt.Sprintf(`Press arrow keys to change the window size
Press S key to change the window scale
Cursor: (%d, %d)
FPS: %0.2f`, x, y, ebiten.CurrentFPS())
	ebitenutil.DebugPrint(screen, msg)
	return nil
}
Пример #8
0
func update(screen *ebiten.Image) error {
	defer func() {
		frames++
	}()
	if frames%30 == 0 {
		if err := addNote(); err != nil {
			return err
		}
	}
	ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
	if err := audioContext.Update(); err != nil {
		return err
	}
	return nil
}
Пример #9
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
}
Пример #10
0
func update(screen *ebiten.Image) error {
	theViewport.Move()

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

	msg := fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS())
	if err := ebitenutil.DebugPrint(screen, msg); err != nil {
		return err
	}
	return nil
}
Пример #11
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
}
Пример #12
0
func update(screen *ebiten.Image) error {
	if player == nil {
		var err error
		player, err = audio.NewPlayer(audioContext, &stream{})
		if err != nil {
			return err
		}
		if err := player.Play(); err != nil {
			return err
		}
	}
	ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
	if err := audioContext.Update(); err != nil {
		return err
	}
	return nil
}
Пример #13
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
}
Пример #14
0
func update(screen *ebiten.Image) error {
	if player == nil {
		var err error
		player, err = audio.NewPlayer(audioContext, &stream{})
		if err != nil {
			return err
		}
		if err := player.Play(); err != nil {
			return err
		}
	}
	msg := fmt.Sprintf("FPS: %0.2f\nThis is an example using infinite audio stream.", ebiten.CurrentFPS())
	if err := ebitenutil.DebugPrint(screen, msg); err != nil {
		return err
	}
	if err := audioContext.Update(); err != nil {
		return err
	}
	return nil
}
Пример #15
0
func update(screen *ebiten.Image) error {
	if musicPlayer == nil {
		select {
		case musicPlayer = <-musicCh:
		default:
		}
	}
	if seBytes == nil {
		select {
		case seBytes = <-seCh:
		default:
		}
	}
	if musicPlayer != nil {
		if err := musicPlayer.updateBar(); err != nil {
			return err
		}
		if err := musicPlayer.updatePlayPause(); err != nil {
			return err
		}
		if err := musicPlayer.updateSE(); err != nil {
			return err
		}
		if err := musicPlayer.updateVolume(); err != nil {
			return err
		}
	}

	op := &ebiten.DrawImageOptions{}
	x, y, w, h := playerBarRect()
	op.GeoM.Translate(float64(x), float64(y))
	if err := screen.DrawImage(playerBarImage, op); err != nil {
		return err
	}
	currentTimeStr := "00:00"
	if musicPlayer != nil {
		c := musicPlayer.audioPlayer.Current()

		// Current Time
		m := (c / time.Minute) % 100
		s := (c / time.Second) % 60
		currentTimeStr = fmt.Sprintf("%02d:%02d", m, s)

		// Bar
		cw, ch := playerCurrentImage.Size()
		cx := int(time.Duration(w)*c/musicPlayer.total) + x - cw/2
		cy := y - (ch-h)/2
		op := &ebiten.DrawImageOptions{}
		op.GeoM.Translate(float64(cx), float64(cy))
		if err := screen.DrawImage(playerCurrentImage, op); err != nil {
			return err
		}
	}

	msg := fmt.Sprintf(`FPS: %0.2f
Press S to toggle Play/Pause
Press P to play SE
Press Z or X to change volume of the music
%s`, ebiten.CurrentFPS(), currentTimeStr)
	if musicPlayer == nil {
		msg += "\nNow Loading..."
	} else if musicPlayer.seekedCh != nil {
		select {
		case err := <-musicPlayer.seekedCh:
			if err != nil {
				return err
			}
			close(musicPlayer.seekedCh)
			musicPlayer.seekedCh = nil
		default:
			msg += "\nSeeking..."
		}
	}
	if err := ebitenutil.DebugPrint(screen, msg); err != nil {
		return err
	}
	if err := audioContext.Update(); err != nil {
		return err
	}
	return nil
}