Draw isometically using magic formulae, correcting the view

This commit is contained in:
2018-03-24 00:15:59 +00:00
parent f6e695e387
commit ab3f053ef9

View File

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