From 976d3b2cd8f0c2a7ce6bd8304b9d8c5596236a5d Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Wed, 17 Jan 2018 12:36:37 -0700 Subject: [PATCH] Clean up drawing; add rotation with arrows --- main.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 20ccff5..df56753 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "image" _ "image/png" "os" + "time" "github.com/faiface/pixel" "github.com/faiface/pixel/pixelgl" @@ -57,12 +58,28 @@ func run() { player := pixel.NewSprite(spritesheet, shipFrames[0]) + angle := 0.0 + + last := time.Now() for !win.Closed() { - //dt := time.Since(last).Seconds() - //last = time.Now() + dt := time.Since(last).Seconds() + last = time.Now() + win.Clear(colornames.Whitesmoke) - player.Draw(win, pixel.IM.Scaled(pixel.ZV, 0.25).Moved(win.Bounds().Center())) + mat := pixel.IM + mat = mat.Rotated(pixel.ZV, angle) + mat = mat.Scaled(pixel.ZV, 0.25).Moved(win.Bounds().Center()) + + player.Draw(win, mat) + + if win.Pressed(pixelgl.KeyLeft) { + angle += 3 * dt + } + if win.Pressed(pixelgl.KeyRight) { + angle -= 3 * dt + + } win.Update() }