Change tree sprite to character sprite; use wasd instead of arrow keys

This commit is contained in:
mollusk 2018-01-19 08:47:25 -07:00
parent 373f5800ea
commit 69977a3096

12
main.go
View File

@ -38,7 +38,7 @@ func run() {
panic(err)
}
spritesheet, err := loadPicture("trees.png")
spritesheet, err := loadPicture("sprites.png")
if err != nil {
panic(err)
}
@ -50,17 +50,17 @@ func run() {
}
//batch := pixel.NewBatch(&pixel.TrianglesData{}, spritesheet)
var treesFrames []pixel.Rect
var spritesFrames []pixel.Rect
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 {
treesFrames = append(treesFrames, pixel.R(x, y, x+32, y+32))
spritesFrames = append(spritesFrames, pixel.R(x, y, x+79, y+92))
}
}
var (
camPos = pixel.ZV
camSpeed = 500.0
camZoom = 1.0
camZoom = 0.3
camZoomSpeed = 1.2
)
@ -90,11 +90,11 @@ func run() {
cam := pixel.IM.Scaled(camPos, camZoom).Moved(win.Bounds().Center().Sub(camPos))
win.SetMatrix(cam)
bg := pixel.NewSprite(background, background.Bounds())
tree := pixel.NewSprite(spritesheet, treesFrames[0])
Sprite := pixel.NewSprite(spritesheet, spritesFrames[3])
//mouse := cam.Unproject(win.MousePosition())
win.Clear(colornames.Forestgreen)
bg.Draw(win, pixel.IM.Moved(win.Bounds().Center()))
tree.Draw(win, pixel.IM.Scaled(pixel.ZV, 4).Moved(playerXY))
Sprite.Draw(win, pixel.IM.Scaled(pixel.ZV, 4).Moved(playerXY))
if win.Pressed(pixelgl.KeyA) {
playerX -= camSpeed * dt