|
|
|
@@ -22,6 +22,17 @@ type IsoPt struct {
|
|
|
|
|
func (s *Scenario) Update(screenX, screenY int) error {
|
|
|
|
|
s.tick += 1
|
|
|
|
|
|
|
|
|
|
x, y := ebiten.CursorPosition()
|
|
|
|
|
screenPos := CartPt{
|
|
|
|
|
X: float64(s.Viewpoint.X + x),
|
|
|
|
|
Y: float64(s.Viewpoint.Y + y),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.selectedCell = screenPos.ToISO()
|
|
|
|
|
|
|
|
|
|
// TODO: zoom support will need a camera
|
|
|
|
|
// FIXME: adjust for Z level
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -33,13 +44,15 @@ func (s *Scenario) Draw(screen *ebiten.Image) error {
|
|
|
|
|
|
|
|
|
|
sw, sh := screen.Size()
|
|
|
|
|
|
|
|
|
|
topLeft := CartPt{X: float64(s.Viewpoint.X), Y: float64(s.Viewpoint.Y)}.ToISO()
|
|
|
|
|
topLeft.X -= 5 // Ensure we paint to every visible section of the screeen.
|
|
|
|
|
topLeft.X -= 5 // FIXME: haxxx
|
|
|
|
|
topLeft := CartPt{
|
|
|
|
|
X: float64(s.Viewpoint.X - 2*cellWidth), // Ensure all visible cells are rendered
|
|
|
|
|
Y: float64(s.Viewpoint.Y - 2*cellHeight),
|
|
|
|
|
}.ToISO()
|
|
|
|
|
|
|
|
|
|
bottomRight := CartPt{X: float64(s.Viewpoint.X + sw), Y: float64(s.Viewpoint.Y + sh)}.ToISO()
|
|
|
|
|
bottomRight.X += 5
|
|
|
|
|
bottomRight.Y += 5
|
|
|
|
|
bottomRight := CartPt{
|
|
|
|
|
X: float64(s.Viewpoint.X + sw + 2*cellHeight),
|
|
|
|
|
Y: float64(s.Viewpoint.Y + sh + 5*cellHeight), // Z dimension requires it
|
|
|
|
|
}.ToISO()
|
|
|
|
|
|
|
|
|
|
// X+Y is constant for all tiles in a column
|
|
|
|
|
// X-Y is constant for all tiles in a row
|
|
|
|
@@ -79,7 +92,7 @@ func (s *Scenario) Draw(screen *ebiten.Image) error {
|
|
|
|
|
counter := map[string]int{}
|
|
|
|
|
for _, pt := range toDraw {
|
|
|
|
|
for z := 0; z <= s.ZIdx; z++ {
|
|
|
|
|
if err := s.renderCell(pt, z, screen, counter); err != nil {
|
|
|
|
|
if err := s.renderCell(int(pt.X), int(pt.Y), z, screen, counter); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -87,26 +100,53 @@ func (s *Scenario) Draw(screen *ebiten.Image) error {
|
|
|
|
|
|
|
|
|
|
//log.Printf("%#+v", counter)
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Scenario) renderCell(pos IsoPt, z int, screen *ebiten.Image, counter map[string]int) error {
|
|
|
|
|
sprites, err := s.area.SpritesForCell(int(pos.X), int(pos.Y), z)
|
|
|
|
|
// Finally, draw cursor chrome
|
|
|
|
|
spr, err := s.specials.Sprite(0)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iso := ebiten.GeoM{}
|
|
|
|
|
iso.Translate(-float64(s.Viewpoint.X), -float64(s.Viewpoint.Y))
|
|
|
|
|
op := ebiten.DrawImageOptions{}
|
|
|
|
|
op.GeoM = s.geoForCoords(int(s.selectedCell.X), int(s.selectedCell.Y), 0)
|
|
|
|
|
op.GeoM.Translate(-cellWidthHalf, -cellHeightHalf)
|
|
|
|
|
|
|
|
|
|
pix := pos.ToCart()
|
|
|
|
|
iso.Translate(pix.X, pix.Y)
|
|
|
|
|
if err := screen.DrawImage(spr.Image, &op); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sx, sy := op.GeoM.Apply(0, 0)
|
|
|
|
|
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("(%.0f,%.0f)", s.selectedCell.X, s.selectedCell.Y), int(sx), int(sy))
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Scenario) geoForCoords(x, y, z int) ebiten.GeoM {
|
|
|
|
|
geo := ebiten.GeoM{}
|
|
|
|
|
geo.Translate(-float64(s.Viewpoint.X), -float64(s.Viewpoint.Y))
|
|
|
|
|
|
|
|
|
|
pix := IsoPt{X: float64(x), Y: float64(y)}.ToCart()
|
|
|
|
|
geo.Translate(pix.X, pix.Y)
|
|
|
|
|
|
|
|
|
|
// Taking the Z index away *seems* to draw the object in the correct place.
|
|
|
|
|
// FIXME: There are some artifacts, investigate more
|
|
|
|
|
iso.Translate(0.0, -float64(z*48.0)) // offset for Z index
|
|
|
|
|
geo.Translate(0.0, -float64(z*48.0)) // offset for Z index
|
|
|
|
|
|
|
|
|
|
return geo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Scenario) renderCell(x, y, z int, screen *ebiten.Image, counter map[string]int) error {
|
|
|
|
|
sprites, err := s.area.SpritesForCell(x, y, z)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: iso.Scale(e.state.zoom, e.state.zoom) // apply current zoom factor
|
|
|
|
|
iso := s.geoForCoords(x, y, z)
|
|
|
|
|
|
|
|
|
|
// FIXME: this fixed offset is found in jungtil.obj. Drawing with it
|
|
|
|
|
// means we put everywhere where the iso->pix conversion expects, but
|
|
|
|
|
// it's a bit nasty. Is there a better way?
|
|
|
|
|
iso.Translate(-209, -332)
|
|
|
|
|
|
|
|
|
|
for _, spr := range sprites {
|
|
|
|
|
// if _, ok := counter[spr.ID]; !ok {
|
|
|
|
@@ -115,20 +155,11 @@ func (s *Scenario) renderCell(pos IsoPt, z int, screen *ebiten.Image, counter ma
|
|
|
|
|
// counter[spr.ID] = counter[spr.ID] + 1
|
|
|
|
|
op := ebiten.DrawImageOptions{GeoM: iso}
|
|
|
|
|
|
|
|
|
|
// FIXME: this fixed offset is found in jungtil.obj. Drawing with it
|
|
|
|
|
// means we put everywhere where the iso->pix conversion expects, but
|
|
|
|
|
// it's a bit nasty. Is there a better way?
|
|
|
|
|
op.GeoM.Translate(float64(spr.Rect.Min.X-209), float64(spr.Rect.Min.Y-322))
|
|
|
|
|
op.GeoM.Translate(float64(spr.Rect.Min.X), float64(spr.Rect.Min.Y))
|
|
|
|
|
|
|
|
|
|
if err := screen.DrawImage(spr.Image, &op); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if z == 0 {
|
|
|
|
|
x, y := op.GeoM.Apply(0, 0)
|
|
|
|
|
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("(%d,%d)", int(pos.X), int(pos.Y)), int(x), int(y))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|