update 05 guide code
This commit is contained in:
parent
9a401948ae
commit
d5f7088b7d
|
@ -46,8 +46,8 @@ func run() {
|
||||||
batch := pixel.NewBatch(&pixel.TrianglesData{}, spritesheet)
|
batch := pixel.NewBatch(&pixel.TrianglesData{}, spritesheet)
|
||||||
|
|
||||||
var treesFrames []pixel.Rect
|
var treesFrames []pixel.Rect
|
||||||
for x := spritesheet.Bounds().Min.X(); x < spritesheet.Bounds().Max.X(); x += 32 {
|
for x := spritesheet.Bounds().Min.X; x < spritesheet.Bounds().Max.X; x += 32 {
|
||||||
for y := spritesheet.Bounds().Min.Y(); y < spritesheet.Bounds().Max.Y(); y += 32 {
|
for y := spritesheet.Bounds().Min.Y; y < spritesheet.Bounds().Max.Y; y += 32 {
|
||||||
treesFrames = append(treesFrames, pixel.R(x, y, x+32, y+32))
|
treesFrames = append(treesFrames, pixel.R(x, y, x+32, y+32))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,28 +69,27 @@ func run() {
|
||||||
dt := time.Since(last).Seconds()
|
dt := time.Since(last).Seconds()
|
||||||
last = time.Now()
|
last = time.Now()
|
||||||
|
|
||||||
cam := pixel.IM.Scaled(camPos, camZoom).Moved(win.Bounds().Center() - camPos)
|
cam := pixel.IM.Scaled(camPos, camZoom).Moved(win.Bounds().Center().Sub(camPos))
|
||||||
win.SetMatrix(cam)
|
win.SetMatrix(cam)
|
||||||
|
|
||||||
if win.Pressed(pixelgl.MouseButtonLeft) {
|
if win.Pressed(pixelgl.MouseButtonLeft) {
|
||||||
tree := pixel.NewSprite(spritesheet, treesFrames[rand.Intn(len(treesFrames))])
|
tree := pixel.NewSprite(spritesheet, treesFrames[rand.Intn(len(treesFrames))])
|
||||||
mouse := cam.Unproject(win.MousePosition())
|
mouse := cam.Unproject(win.MousePosition())
|
||||||
tree.SetMatrix(pixel.IM.Scaled(0, 4).Moved(mouse))
|
tree.Draw(batch, pixel.IM.Scaled(pixel.ZV, 4).Moved(mouse))
|
||||||
tree.Draw(batch)
|
|
||||||
}
|
}
|
||||||
if win.Pressed(pixelgl.KeyLeft) {
|
if win.Pressed(pixelgl.KeyLeft) {
|
||||||
camPos -= pixel.X(camSpeed * dt)
|
camPos.X -= camSpeed * dt
|
||||||
}
|
}
|
||||||
if win.Pressed(pixelgl.KeyRight) {
|
if win.Pressed(pixelgl.KeyRight) {
|
||||||
camPos += pixel.X(camSpeed * dt)
|
camPos.X += camSpeed * dt
|
||||||
}
|
}
|
||||||
if win.Pressed(pixelgl.KeyDown) {
|
if win.Pressed(pixelgl.KeyDown) {
|
||||||
camPos -= pixel.Y(camSpeed * dt)
|
camPos.Y -= camSpeed * dt
|
||||||
}
|
}
|
||||||
if win.Pressed(pixelgl.KeyUp) {
|
if win.Pressed(pixelgl.KeyUp) {
|
||||||
camPos += pixel.Y(camSpeed * dt)
|
camPos.Y += camSpeed * dt
|
||||||
}
|
}
|
||||||
camZoom *= math.Pow(camZoomSpeed, win.MouseScroll().Y())
|
camZoom *= math.Pow(camZoomSpeed, win.MouseScroll().Y)
|
||||||
|
|
||||||
win.Clear(colornames.Forestgreen)
|
win.Clear(colornames.Forestgreen)
|
||||||
batch.Draw(win)
|
batch.Draw(win)
|
||||||
|
|
Loading…
Reference in New Issue