mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
Rotate ebiten
This commit is contained in:
parent
889e3356a2
commit
e10bac5a8a
@ -1,11 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hajimehoshi/go-ebiten/graphics"
|
"github.com/hajimehoshi/go-ebiten/graphics"
|
||||||
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
||||||
"github.com/hajimehoshi/go-ebiten/ui"
|
"github.com/hajimehoshi/go-ebiten/ui"
|
||||||
|
"image/color"
|
||||||
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
var TexturePaths = map[string]string{
|
var TexturePaths = map[string]string{
|
||||||
@ -16,6 +17,9 @@ var TexturePaths = map[string]string{
|
|||||||
type drawInfo struct {
|
type drawInfo struct {
|
||||||
textures map[string]graphics.TextureId
|
textures map[string]graphics.TextureId
|
||||||
inputStr string
|
inputStr string
|
||||||
|
textureX int
|
||||||
|
textureY int
|
||||||
|
textureAngle float64
|
||||||
textureGeo matrix.Geometry
|
textureGeo matrix.Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,6 +41,9 @@ func NewGame() *Game {
|
|||||||
counter: 0,
|
counter: 0,
|
||||||
drawInfo: drawInfo{
|
drawInfo: drawInfo{
|
||||||
textures: map[string]graphics.TextureId{},
|
textures: map[string]graphics.TextureId{},
|
||||||
|
textureX: 0,
|
||||||
|
textureY: 0,
|
||||||
|
textureAngle: 0,
|
||||||
textureGeo: matrix.IdentityGeometry(),
|
textureGeo: matrix.IdentityGeometry(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -54,6 +61,9 @@ func (game *Game) OnInputStateUpdated(e ui.InputStateUpdatedEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (game *Game) Update() {
|
func (game *Game) Update() {
|
||||||
|
const textureWidth = 57
|
||||||
|
const textureHeight = 26
|
||||||
|
|
||||||
game.counter++
|
game.counter++
|
||||||
game.drawInfo.inputStr = fmt.Sprintf(`Input State:
|
game.drawInfo.inputStr = fmt.Sprintf(`Input State:
|
||||||
X: %d
|
X: %d
|
||||||
@ -62,8 +72,19 @@ func (game *Game) Update() {
|
|||||||
if game.inputPrevX != -1 && game.inputPrevY != -1 &&
|
if game.inputPrevX != -1 && game.inputPrevY != -1 &&
|
||||||
game.inputX != -1 && game.inputY != -1 {
|
game.inputX != -1 && game.inputY != -1 {
|
||||||
dx, dy := game.inputX-game.inputPrevX, game.inputY-game.inputPrevY
|
dx, dy := game.inputX-game.inputPrevX, game.inputY-game.inputPrevY
|
||||||
game.drawInfo.textureGeo.Translate(float64(dx), float64(dy))
|
game.textureX += dx
|
||||||
|
game.textureY += dy
|
||||||
|
|
||||||
}
|
}
|
||||||
|
game.drawInfo.textureAngle = 2 * math.Pi * float64(game.counter) / 600
|
||||||
|
|
||||||
|
game.drawInfo.textureGeo = matrix.IdentityGeometry()
|
||||||
|
|
||||||
|
game.drawInfo.textureGeo.Translate(-textureWidth/2, -textureHeight/2)
|
||||||
|
game.drawInfo.textureGeo.Rotate(game.drawInfo.textureAngle)
|
||||||
|
game.drawInfo.textureGeo.Translate(textureWidth, textureHeight)
|
||||||
|
|
||||||
|
game.drawInfo.textureGeo.Translate(float64(game.textureX), float64(game.textureY))
|
||||||
|
|
||||||
// Update for the next frame.
|
// Update for the next frame.
|
||||||
game.inputPrevX, game.inputPrevY = game.inputX, game.inputY
|
game.inputPrevX, game.inputPrevY = game.inputX, game.inputY
|
||||||
|
Loading…
Reference in New Issue
Block a user