2013-10-18 19:58:00 +02:00
|
|
|
package testpattern
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hajimehoshi/go-ebiten"
|
|
|
|
"github.com/hajimehoshi/go-ebiten/graphics"
|
|
|
|
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
|
|
|
"image"
|
|
|
|
_ "image/png"
|
|
|
|
"math"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TestPattern struct {
|
2013-10-21 15:18:10 +02:00
|
|
|
textureId graphics.TextureId
|
2013-10-18 19:58:00 +02:00
|
|
|
textureWidth int
|
|
|
|
textureHeight int
|
|
|
|
geos []matrix.Geometry
|
|
|
|
}
|
|
|
|
|
|
|
|
func New() *TestPattern {
|
|
|
|
return &TestPattern{}
|
|
|
|
}
|
|
|
|
|
2013-10-20 08:51:26 +02:00
|
|
|
func (game *TestPattern) InitTextures(tf graphics.TextureFactory) {
|
2013-10-18 19:58:00 +02:00
|
|
|
file, err := os.Open("images/test_pattern.png")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
img, _, err := image.Decode(file)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if game.textureId, err = tf.NewTextureFromImage(img); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
size := img.Bounds().Size()
|
|
|
|
game.textureWidth = size.X
|
|
|
|
game.textureHeight = size.Y
|
|
|
|
}
|
|
|
|
|
|
|
|
func (game *TestPattern) Update(context ebiten.GameContext) {
|
|
|
|
geo := matrix.IdentityGeometry()
|
|
|
|
geo.Translate(13, 13)
|
|
|
|
game.geos = append(game.geos, geo)
|
|
|
|
|
|
|
|
geo = matrix.IdentityGeometry()
|
|
|
|
geo.Translate(float64(13+game.textureWidth), 13)
|
|
|
|
game.geos = append(game.geos, geo)
|
|
|
|
|
|
|
|
geo = matrix.IdentityGeometry()
|
|
|
|
geo.Translate(float64(13+game.textureWidth*2), 13)
|
|
|
|
game.geos = append(game.geos, geo)
|
|
|
|
|
|
|
|
geo = matrix.IdentityGeometry()
|
|
|
|
geo.Translate(float64(13+game.textureWidth*3), 13)
|
|
|
|
game.geos = append(game.geos, geo)
|
|
|
|
|
|
|
|
geo = matrix.IdentityGeometry()
|
|
|
|
geo.Scale(2, 2)
|
|
|
|
geo.Translate(13, float64(13+game.textureHeight))
|
|
|
|
game.geos = append(game.geos, geo)
|
|
|
|
|
|
|
|
geo = matrix.IdentityGeometry()
|
|
|
|
geo.Rotate(math.Pi)
|
|
|
|
geo.Scale(2, 2)
|
|
|
|
geo.Translate(float64(game.textureWidth*2),
|
|
|
|
float64(game.textureHeight*2))
|
|
|
|
geo.Translate(float64(13+game.textureWidth*2),
|
|
|
|
float64(13+game.textureHeight))
|
|
|
|
game.geos = append(game.geos, geo)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (game *TestPattern) Draw(g graphics.Context) {
|
|
|
|
for _, geo := range game.geos {
|
|
|
|
g.DrawTexture(game.textureId, geo, matrix.IdentityColor())
|
|
|
|
}
|
|
|
|
}
|