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()
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))))
}