From ab3f053ef9dd2412100f7902c117967e8906a5f9 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Sat, 24 Mar 2018 00:15:59 +0000 Subject: [PATCH] Draw isometically using magic formulae, correcting the view --- cmd/view-map/main.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/view-map/main.go b/cmd/view-map/main.go index 3cc8f39..5a1ee2b 100644 --- a/cmd/view-map/main.go +++ b/cmd/view-map/main.go @@ -135,8 +135,8 @@ func (e *env) getSprite(palette []string, ref maps.ObjRef) (*conv.Sprite, *conv. } var ( - cellWidth = 72.0 // I think, anyway - cellLength = 72.0 + cellWidth = 64.0 // I think, anyway + cellLength = 64.0 ) // TODO: build all the sprites in the set into a single spritesheet so we can @@ -158,8 +158,9 @@ func (s *state) present(pWin *pixelgl.Window) { // TODO: bounds clipping z := int(s.zIdx) - for x := int(gameMap.MinWidth); x < int(gameMap.MaxWidth); x++ { - for y := int(gameMap.MinLength); y < int(gameMap.MaxLength); y++ { + for y := int(gameMap.MaxLength - 1); y >= int(gameMap.MinLength); y-- { + for x := int(gameMap.MaxWidth - 1); x >= int(gameMap.MinWidth); x-- { + cell := gameMap.Cells.At(x, y, z) surfaceSprite, _ := s.env.getSprite(s.env.set.SurfacePalette, cell.Surface) @@ -175,14 +176,14 @@ func (s *state) present(pWin *pixelgl.Window) { // ones \o/ // FIXME: these are off by a bit orig := pixel.V(xPos, yPos) - rotated := orig.Rotated(s.rot) + iso := pixel.V(orig.X-orig.Y, (orig.X+orig.Y)/2.0) if surfaceSprite != nil { - surfaceSprite.Spr.Draw(pWin, pixel.IM.Moved(rotated)) + surfaceSprite.Spr.Draw(pWin, pixel.IM.Moved(iso)) } if centerSprite != nil { - centerSprite.Spr.Draw(pWin, pixel.IM.Moved(rotated)) + centerSprite.Spr.Draw(pWin, pixel.IM.Moved(iso)) } } }