From 87d49546f32b3dd5b1c2cfe906ad455756c7e67f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 18 Dec 2014 01:38:01 +0900 Subject: [PATCH] Enrich the example --- example/image/main.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/example/image/main.go b/example/image/main.go index e587feda0..e7e9b5c4b 100644 --- a/example/image/main.go +++ b/example/image/main.go @@ -30,16 +30,33 @@ const ( ) type Game struct { - count int - gophersTexture *ebiten.Texture + count int + horizontalCount int + verticalCount int + gophersTexture *ebiten.Texture } func (g *Game) Update(gr ebiten.GraphicsContext) error { g.count++ + if ebiten.IsKeyPressed(ebiten.KeyLeft) { + g.horizontalCount-- + } + if ebiten.IsKeyPressed(ebiten.KeyRight) { + g.horizontalCount++ + } + if ebiten.IsKeyPressed(ebiten.KeyDown) { + g.verticalCount-- + } + if ebiten.IsKeyPressed(ebiten.KeyUp) { + g.verticalCount++ + } w, h := g.gophersTexture.Size() geo := ebiten.TranslateGeometry(-float64(w)/2, -float64(h)/2) - geo.Concat(ebiten.ScaleGeometry(0.5, 0.5)) + scaleX := 0.5 * math.Pow(1.05, float64(g.horizontalCount)) + scaleY := 0.5 * math.Pow(1.05, float64(g.verticalCount)) + geo.Concat(ebiten.ScaleGeometry(scaleX, scaleY)) + geo.Concat(ebiten.RotateGeometry(float64(g.count%720) * 2 * math.Pi / 720)) geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2)) clr := ebiten.RotateHue(float64(g.count%180) * 2 * math.Pi / 180) ebiten.DrawWholeTexture(gr, g.gophersTexture, geo, clr)