From 431d2c7f781f423925b55f851989554833be6d65 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 22 Mar 2018 12:41:32 +0000 Subject: [PATCH] Fix Y-rendering and the camera view --- cmd/view-map/main.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/cmd/view-map/main.go b/cmd/view-map/main.go index 6465cfa..752db4a 100644 --- a/cmd/view-map/main.go +++ b/cmd/view-map/main.go @@ -139,10 +139,10 @@ func (s *state) present(pWin *pixelgl.Window) { center := pWin.Bounds().Center() cam := pixel.IM - // cam = cam.ScaledXY(center, pixel.Vec{1.0, -1.0}) // invert the Y axis - cam = cam.Scaled(pixel.ZV, s.zoom) // apply current zoom factor - cam = cam.Moved(center.Sub(s.camPos)) // Make it central - // cam = cam.Rotated(center.Sub(s.camPos), -0.785) // Apply isometric angle + cam = cam.ScaledXY(center, pixel.Vec{1.0, -1.0}) // invert the Y axis + cam = cam.Scaled(pixel.ZV, s.zoom) // apply current zoom factor + cam = cam.Moved(center.Sub(s.camPos)) // Make it central + cam = cam.Rotated(center.Sub(s.camPos), -0.785) // Apply isometric angle s.cam = cam pWin.SetMatrix(s.cam) @@ -164,14 +164,13 @@ func (s *state) present(pWin *pixelgl.Window) { log.Printf("WARN: Surface sprite has wrong width: %v", surfaceSprite.Width) } - yPos := (y - int(gameMap.MinLength)) * cellHeight - xPos := (x - int(gameMap.MinWidth)) * cellWidth + yPos := float64((y - int(gameMap.MinLength)) * cellHeight / 2) + xPos := float64((x - int(gameMap.MinWidth)) * cellWidth) - // Tiles should be flush to each other. Offset odd-numbered tiles up - // and right to get the effect - if y%2 == 1 { - yPos -= cellHeight * 2 - xPos += (cellWidth / 2) + // Tiles should be flush to each other. Offset even-numbered tiles + // across to get this effect + if y%2 == 0 { + xPos += float64(cellWidth) / 2.0 } pic := surfaceSprite.Pic @@ -179,7 +178,7 @@ func (s *state) present(pWin *pixelgl.Window) { log.Printf( "cell(%v,%v,%v): %s %d: pix(%v,%v - %v,%v)", x, y, z, surfaceObj.Name, cell.Surface.Index(), - xPos, yPos, xPos+surfaceSprite.Width, yPos+surfaceSprite.Height, + xPos, yPos, xPos+float64(surfaceSprite.Width), yPos+float64(surfaceSprite.Height), ) spr.Draw(pWin, pixel.IM.Moved(pixel.V(float64(xPos), float64(yPos)))) }