Selected cursor chrome
This commit is contained in:
@@ -92,7 +92,7 @@ func (s *Scenario) Draw(screen *ebiten.Image) error {
|
|||||||
counter := map[string]int{}
|
counter := map[string]int{}
|
||||||
for _, pt := range toDraw {
|
for _, pt := range toDraw {
|
||||||
for z := 0; z <= s.ZIdx; z++ {
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,26 +100,53 @@ func (s *Scenario) Draw(screen *ebiten.Image) error {
|
|||||||
|
|
||||||
//log.Printf("%#+v", counter)
|
//log.Printf("%#+v", counter)
|
||||||
|
|
||||||
return nil
|
// Finally, draw cursor chrome
|
||||||
}
|
spr, err := s.specials.Sprite(0)
|
||||||
|
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
iso := ebiten.GeoM{}
|
op := ebiten.DrawImageOptions{}
|
||||||
iso.Translate(-float64(s.Viewpoint.X), -float64(s.Viewpoint.Y))
|
op.GeoM = s.geoForCoords(int(s.selectedCell.X), int(s.selectedCell.Y), 0)
|
||||||
|
op.GeoM.Translate(-cellWidthHalf, -cellHeightHalf)
|
||||||
|
|
||||||
pix := pos.ToCart()
|
if err := screen.DrawImage(spr.Image, &op); err != nil {
|
||||||
iso.Translate(pix.X, pix.Y)
|
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.
|
// Taking the Z index away *seems* to draw the object in the correct place.
|
||||||
// FIXME: There are some artifacts, investigate more
|
// 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
|
// 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 {
|
for _, spr := range sprites {
|
||||||
// if _, ok := counter[spr.ID]; !ok {
|
// if _, ok := counter[spr.ID]; !ok {
|
||||||
@@ -128,20 +155,11 @@ func (s *Scenario) renderCell(pos IsoPt, z int, screen *ebiten.Image, counter ma
|
|||||||
// counter[spr.ID] = counter[spr.ID] + 1
|
// counter[spr.ID] = counter[spr.ID] + 1
|
||||||
op := ebiten.DrawImageOptions{GeoM: iso}
|
op := ebiten.DrawImageOptions{GeoM: iso}
|
||||||
|
|
||||||
// FIXME: this fixed offset is found in jungtil.obj. Drawing with it
|
op.GeoM.Translate(float64(spr.Rect.Min.X), float64(spr.Rect.Min.Y))
|
||||||
// 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))
|
|
||||||
|
|
||||||
if err := screen.DrawImage(spr.Image, &op); err != nil {
|
if err := screen.DrawImage(spr.Image, &op); err != nil {
|
||||||
return err
|
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
|
return nil
|
||||||
|
@@ -9,7 +9,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Scenario struct {
|
type Scenario struct {
|
||||||
area *assetstore.Map
|
area *assetstore.Map
|
||||||
|
specials *assetstore.Object
|
||||||
|
|
||||||
tick int
|
tick int
|
||||||
turn int
|
turn int
|
||||||
@@ -28,6 +29,11 @@ func NewScenario(assets *assetstore.AssetStore, name string) (*Scenario, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
specials, err := assets.Object("specials") // FIXME: should this be hardcoded?
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Eager load sprites. TODO: do we really want to do this?
|
// Eager load sprites. TODO: do we really want to do this?
|
||||||
if err := area.LoadSprites(); err != nil {
|
if err := area.LoadSprites(); err != nil {
|
||||||
return nil, fmt.Errorf("Eager-loading sprites failed: %v", err)
|
return nil, fmt.Errorf("Eager-loading sprites failed: %v", err)
|
||||||
@@ -35,6 +41,7 @@ func NewScenario(assets *assetstore.AssetStore, name string) (*Scenario, error)
|
|||||||
|
|
||||||
out := &Scenario{
|
out := &Scenario{
|
||||||
area: area,
|
area: area,
|
||||||
|
specials: specials,
|
||||||
Viewpoint: image.Pt(0, 3000), // FIXME: haxxx
|
Viewpoint: image.Pt(0, 3000), // FIXME: haxxx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user