Clean up drawing; add rotation with arrows
This commit is contained in:
parent
53af30d6fb
commit
976d3b2cd8
23
main.go
23
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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user