Fix Y-rendering and the camera view

This commit is contained in:
2018-03-22 12:41:32 +00:00
parent 2d423a4c4c
commit 431d2c7f78

View File

@@ -139,10 +139,10 @@ func (s *state) present(pWin *pixelgl.Window) {
center := pWin.Bounds().Center() center := pWin.Bounds().Center()
cam := pixel.IM cam := pixel.IM
// cam = cam.ScaledXY(center, pixel.Vec{1.0, -1.0}) // invert the Y axis 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.Scaled(pixel.ZV, s.zoom) // apply current zoom factor
cam = cam.Moved(center.Sub(s.camPos)) // Make it central cam = cam.Moved(center.Sub(s.camPos)) // Make it central
// cam = cam.Rotated(center.Sub(s.camPos), -0.785) // Apply isometric angle cam = cam.Rotated(center.Sub(s.camPos), -0.785) // Apply isometric angle
s.cam = cam s.cam = cam
pWin.SetMatrix(s.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) log.Printf("WARN: Surface sprite has wrong width: %v", surfaceSprite.Width)
} }
yPos := (y - int(gameMap.MinLength)) * cellHeight yPos := float64((y - int(gameMap.MinLength)) * cellHeight / 2)
xPos := (x - int(gameMap.MinWidth)) * cellWidth xPos := float64((x - int(gameMap.MinWidth)) * cellWidth)
// Tiles should be flush to each other. Offset odd-numbered tiles up // Tiles should be flush to each other. Offset even-numbered tiles
// and right to get the effect // across to get this effect
if y%2 == 1 { if y%2 == 0 {
yPos -= cellHeight * 2 xPos += float64(cellWidth) / 2.0
xPos += (cellWidth / 2)
} }
pic := surfaceSprite.Pic pic := surfaceSprite.Pic
@@ -179,7 +178,7 @@ func (s *state) present(pWin *pixelgl.Window) {
log.Printf( log.Printf(
"cell(%v,%v,%v): %s %d: pix(%v,%v - %v,%v)", "cell(%v,%v,%v): %s %d: pix(%v,%v - %v,%v)",
x, y, z, surfaceObj.Name, cell.Surface.Index(), 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)))) spr.Draw(pWin, pixel.IM.Moved(pixel.V(float64(xPos), float64(yPos))))
} }