From d87df4979c7493354f41cf2c6210a972b8156852 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 21 Jun 2013 10:45:00 +0900 Subject: [PATCH] Create game package --- {examples => example}/glut/ebiten.png | Bin {examples => example}/glut/main.go | 47 ++------------------------ 2 files changed, 2 insertions(+), 45 deletions(-) rename {examples => example}/glut/ebiten.png (100%) rename {examples => example}/glut/main.go (59%) diff --git a/examples/glut/ebiten.png b/example/glut/ebiten.png similarity index 100% rename from examples/glut/ebiten.png rename to example/glut/ebiten.png diff --git a/examples/glut/main.go b/example/glut/main.go similarity index 59% rename from examples/glut/main.go rename to example/glut/main.go index a363afd47..54163695c 100644 --- a/examples/glut/main.go +++ b/example/glut/main.go @@ -16,11 +16,8 @@ package main import "C" import ( "github.com/hajimehoshi/go.ebiten" + "github.com/hajimehoshi/go.ebiten/example/game" "github.com/hajimehoshi/go.ebiten/graphics" - "github.com/hajimehoshi/go.ebiten/graphics/matrix" - "image" - "image/color" - _ "image/png" "os" "runtime" "unsafe" @@ -92,52 +89,12 @@ func (ui *GlutUI) Run(device graphics.Device) { C.glutMainLoop() } -type DemoGame struct { - ebitenTexture graphics.Texture - x int -} - -func (game *DemoGame) 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 *DemoGame) Update() { - game.x++ -} - -func (game *DemoGame) 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()) -} - func main() { runtime.GOMAXPROCS(runtime.NumCPU()) - game := &DemoGame{} + game := game.NewRotatingImage() currentUI = &GlutUI{} currentUI.Init() ebiten.OpenGLRun(game, currentUI) - }