Add game files

This commit is contained in:
Hajime Hoshi 2013-06-21 11:02:38 +09:00
parent d87df4979c
commit 5e2e0a0760
2 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,53 @@
package game
import (
"github.com/hajimehoshi/go.ebiten/graphics"
"github.com/hajimehoshi/go.ebiten/graphics/matrix"
"image"
"image/color"
_ "image/png"
"os"
)
type RotatingImage struct {
ebitenTexture graphics.Texture
x int
}
func NewRotatingImage() *RotatingImage {
return &RotatingImage{}
}
func (game *RotatingImage) Init(tf graphics.TextureFactory) {
file, err := os.Open("ebiten.png")
if err != nil {
panic(err)
}
defer file.Close()
img, _, err := image.Decode(file)
if err != nil {
panic(err)
}
game.ebitenTexture = tf.NewTextureFromImage(img)
}
func (game *RotatingImage) Update() {
game.x++
}
func (game *RotatingImage) Draw(g graphics.GraphicsContext, offscreen graphics.Texture) {
g.Fill(&color.RGBA{R: 128, G: 128, B: 255, A: 255})
geometryMatrix := matrix.IdentityGeometry()
tx, ty := float64(game.ebitenTexture.Width), float64(game.ebitenTexture.Height)
geometryMatrix.Translate(-tx/2, -ty/2)
geometryMatrix.Rotate(float64(game.x) / 60)
geometryMatrix.Translate(tx/2, ty/2)
centerX, centerY := float64(offscreen.Width) / 2, float64(offscreen.Height) / 2
geometryMatrix.Translate(centerX - tx/2, centerY - ty/2)
g.DrawTexture(game.ebitenTexture.ID,
0, 0, int(tx), int(ty),
geometryMatrix,
matrix.IdentityColor())
}

22
example/game/sprites.go Normal file
View File

@ -0,0 +1,22 @@
package game
import (
"github.com/hajimehoshi/go.ebiten/graphics"
)
type Sprites struct {
ebitenTexture graphics.Texture
}
func NewSprites() *Sprites {
return &Sprites{}
}
func (game *Sprites) Init(tf graphics.TextureFactory) {
}
func (game *Sprites) Update() {
}
func (game *Sprites) Draw(g graphics.GraphicsContext, offscreen graphics.Texture) {
}