Get the rotation *slightly* closer and show some center objects

This commit is contained in:
2018-03-23 23:54:20 +00:00
parent c69beafa76
commit f6e695e387

View File

@@ -95,7 +95,7 @@ func (e *env) run() {
// camPos: pixel.V(0, float64(-pWin.Bounds().Size().Y)),
// camPos: pixel.V(float64(3700), float64(0)),
zoom: 1.0,
rot: 0.45,
rot: 0.785,
}
pWin.SetSmooth(true)
@@ -113,7 +113,13 @@ func (e *env) run() {
}
func (e *env) getSprite(palette []string, ref maps.ObjRef) (*conv.Sprite, *conv.Object) {
if ref.Index() >= len(palette) {
log.Printf("Palette too small: %v requested", ref.Index())
return nil, nil
}
name := palette[ref.Index()]
obj := e.objects[name]
if obj == nil {
log.Printf("Failed to find surface sprite %#v -> %q", ref, name)
@@ -129,8 +135,8 @@ func (e *env) getSprite(palette []string, ref maps.ObjRef) (*conv.Sprite, *conv.
}
var (
cellWidth = 128 // I think, anyway
cellHeight = 63
cellWidth = 72.0 // I think, anyway
cellLength = 72.0
)
// TODO: build all the sprites in the set into a single spritesheet so we can
@@ -146,7 +152,7 @@ func (s *state) present(pWin *pixelgl.Window) {
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.Rotated(center.Sub(s.camPos), s.rot) // Apply isometric angle
s.cam = cam
pWin.SetMatrix(cam)
@@ -156,39 +162,28 @@ func (s *state) present(pWin *pixelgl.Window) {
for y := int(gameMap.MinLength); y < int(gameMap.MaxLength); y++ {
cell := gameMap.Cells.At(x, y, z)
surfaceSprite, obj := s.env.getSprite(s.env.set.SurfacePalette, cell.Surface)
surfaceSprite, _ := s.env.getSprite(s.env.set.SurfacePalette, cell.Surface)
centerSprite, _ := s.env.getSprite(s.env.set.CenterPalette, cell.Center)
fX := float64(x)
fY := float64(y)
fWidth := float64(cellWidth)
fLength := float64(cellHeight)
// numCellsToOffset := math.Abs(float64(gameMap.Width() / 2) - fY)
// xOffset := numCellsToOffset * (fWidth/2)
//yOffset := 0.0 //numCellsToOffset * (fLength/2)
xPos := (fX - fY) * fWidth / 2 // - xOffset
yPos := fY * fLength // - yOffset
xPos := fX * cellWidth
yPos := fY * cellLength
// The rotation translates the rectangular coordinates to diamond
// ones \o/
// FIXME: these are off by a bit
orig := pixel.V(xPos, yPos)
rotated := orig
rotated = rotated.Rotated(s.rot)
// rotated = rotated.Rotated(0.464) // 26.565'
// rotated = orig.Rotated(0.35)
// rotated = rotated.Rotated(0.524) // 30'
// rotated = rotated.Rotated(0.785) // 45'
// rotated = rotated.Rotated(1.571) // 90'
rotated := orig.Rotated(s.rot)
log.Printf(
"cell(%v,%v): %s %d: %#v -> %#v",
x, y, obj.Name, cell.Surface.Index(),
orig, rotated,
)
if surfaceSprite != nil {
surfaceSprite.Spr.Draw(pWin, pixel.IM.Moved(rotated))
}
surfaceSprite.Spr.Draw(pWin, pixel.IM.Moved(rotated))
if centerSprite != nil {
centerSprite.Spr.Draw(pWin, pixel.IM.Moved(rotated))
}
}
}
}
@@ -231,23 +226,6 @@ func (s *state) handleKeys(pWin *pixelgl.Window) {
s.rot += 0.001
}
/* TODO: restore this
// Show details of clicked-on cell in termal
if pWin.JustPressed(pixelgl.MouseButtonLeft) {
vec := s.cam.Unproject(pWin.MousePosition())
x, y := vecToCell(vec)
log.Printf("%#v -> %d,%d", vec, x, y)
cell := state.env.gameMap.Cells.At(x, y, state.zIdx)
log.Printf(
"x=%d y=%d z=%d SurfaceTile=%d (%s) SurfaceFrame=%d SquadRelated=%d",
x, y, state.zIdx,
cell.Surface.Index(), state.env.set.SurfacePalette[int(cell.Surface.Index())], cell.Surface.Frame(),
cell.SquadRelated,
)
log.Printf("CellIdx%d=%d. Full cell data: %#v", state.cellIdx, cell.At(state.cellIdx), cell)
}
*/
// Zoom in and out with the mouse wheel
s.zoom *= math.Pow(1.2, pWin.MouseScroll().Y)
}