コード例 #1
0
ファイル: gamepadscene.go プロジェクト: DrJosh9000/ebiten
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
}
コード例 #2
0
ファイル: gamescene.go プロジェクト: DrJosh9000/ebiten
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)
}
コード例 #3
0
ファイル: main.go プロジェクト: hajimehoshi/ebiten
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
}
コード例 #4
0
ファイル: main.go プロジェクト: DrJosh9000/ebiten
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
}
コード例 #5
0
ファイル: game.go プロジェクト: hajimehoshi/ebiten
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
}
コード例 #6
0
ファイル: main.go プロジェクト: DrJosh9000/ebiten
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
}
コード例 #7
0
ファイル: main.go プロジェクト: carriercomm/ebiten
func update(screen *ebiten.Image) error {
	spotLightX += spotLightVX
	spotLightY += spotLightVY
	if spotLightX < 0 {
		spotLightX = -spotLightX
		spotLightVX = -spotLightVX
	}
	if spotLightY < 0 {
		spotLightY = -spotLightY
		spotLightVY = -spotLightVY
	}
	w, h := spotLightImage.Size()
	maxX, maxY := screenWidth-w, screenHeight-h
	if maxX < spotLightX {
		spotLightX = -spotLightX + 2*maxX
		spotLightVX = -spotLightVX
	}
	if maxY < spotLightY {
		spotLightY = -spotLightY + 2*maxY
		spotLightVY = -spotLightVY
	}

	if err := maskImage.Clear(); err != nil {
		return err
	}

	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(float64(spotLightX), float64(spotLightY))
	if err := maskImage.DrawImage(spotLightImage, op); err != nil {
		return err
	}

	op = &ebiten.DrawImageOptions{}
	op.CompositeMode = ebiten.CompositeModeSourceOut
	if err := maskImage.DrawImage(fiveyearsImage, op); err != nil {
		return err
	}

	if err := screen.Fill(color.RGBA{0x00, 0x00, 0x80, 0xff}); err != nil {
		return err
	}
	if err := screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{}); err != nil {
		return err
	}
	if err := screen.DrawImage(maskImage, &ebiten.DrawImageOptions{}); err != nil {
		return err
	}

	return nil
}
コード例 #8
0
ファイル: main.go プロジェクト: DrJosh9000/ebiten
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
}
コード例 #9
0
ファイル: main.go プロジェクト: hajimehoshi/ebiten
func update(screen *ebiten.Image) error {
	w, _ := ebitenImage.Size()
	const ox = 10
	const oy = 10

	if err := screen.Fill(color.NRGBA{0x00, 0x40, 0x80, 0xff}); err != nil {
		return err
	}
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(ox, oy)
	if err := screen.DrawImage(ebitenImage, op); err != nil {
		return err
	}
	op = &ebiten.DrawImageOptions{}
	op.GeoM.Translate(ox+float64(w), oy)
	op.CompositeMode = ebiten.CompositeModeLighter
	if err := screen.DrawImage(ebitenImage, op); err != nil {
		return err
	}
	return nil
}
コード例 #10
0
ファイル: board.go プロジェクト: hajimehoshi/ebiten
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
}
コード例 #11
0
ファイル: main.go プロジェクト: hajimehoshi/ebiten
func update(screen *ebiten.Image) error {
	count++
	count %= ebiten.FPS * 10
	diff := float64(count) * 0.2
	switch {
	case 480 < count:
		diff = 0
	case 240 < count:
		diff = float64(480-count) * 0.2
	}

	if err := screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff}); err != nil {
		return err
	}
	op := &ebiten.DrawImageOptions{}
	op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
	op.ImageParts = &imageParts{
		diff: diff,
	}
	if err := screen.DrawImage(ebitenImage, op); err != nil {
		return err
	}
	return nil
}