prisms
This commit is contained in:
parent
d5a141f4b8
commit
03e5e7ca49
3 changed files with 54 additions and 11 deletions
|
@ -1,10 +0,0 @@
|
|||
package engine
|
||||
|
||||
type HexPrismMap struct {
|
||||
Map map[Point3]*HexPrism
|
||||
}
|
||||
|
||||
type HexPrism struct {
|
||||
pos Point3
|
||||
hpm *HexPrismMap
|
||||
}
|
53
engine/prisms.go
Normal file
53
engine/prisms.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"image"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type PrismMap struct {
|
||||
Map map[Point3]*Prism
|
||||
DrawOrderBias image.Point // dot with (X,Y) = bias
|
||||
DrawOffset image.Point // offset to apply to whole map
|
||||
DrawZStride image.Point // (X,Y) draw translation for each unit in Z
|
||||
PrismSize Point3
|
||||
Sheet Sheet
|
||||
}
|
||||
|
||||
func (m *PrismMap) Prepare(*Game) error {
|
||||
for v, p := range m.Map {
|
||||
p.pos = v
|
||||
p.pm = m
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *PrismMap) Transform(pt Transform) (tf Transform) {
|
||||
tf.Opts.GeoM.Translate(cfloat(m.DrawOffset))
|
||||
return tf.Concat(pt)
|
||||
}
|
||||
|
||||
type Prism struct {
|
||||
Cell int
|
||||
|
||||
pos Point3
|
||||
pm *PrismMap
|
||||
}
|
||||
|
||||
func (p *Prism) Draw(screen *ebiten.Image, tf *Transform) {
|
||||
screen.DrawImage(p.pm.Sheet.SubImage(p.Cell), &tf.Opts)
|
||||
}
|
||||
|
||||
func (p *Prism) DrawOrder() (int, int) {
|
||||
return p.pos.Z * p.pm.PrismSize.Z,
|
||||
dot(p.pos.XY(), p.pm.DrawOrderBias)
|
||||
}
|
||||
|
||||
func (p *Prism) Transform(pt Transform) (tf Transform) {
|
||||
v := p.pos.CMul(p.pm.PrismSize)
|
||||
tf.Opts.GeoM.Translate(cfloat(
|
||||
v.XY().Add(p.pm.DrawZStride.Mul(v.Z)),
|
||||
))
|
||||
return tf.Concat(pt)
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package engine
|
||||
|
||||
const (
|
||||
var (
|
||||
// Oblique projections
|
||||
CabinetProjection = ParallelProjection{0.5, 0.5}
|
||||
CavalierProjection = ParallelProjection{1, 1}
|
||||
|
|
Loading…
Reference in a new issue