ichigo/engine/prisms.go

87 lines
1.6 KiB
Go
Raw Normal View History

2021-09-05 20:54:43 +10:00
package engine
import (
2021-09-05 20:58:55 +10:00
"encoding/gob"
2021-09-05 20:54:43 +10:00
"image"
"github.com/hajimehoshi/ebiten/v2"
)
2021-09-05 20:58:55 +10:00
var (
_ interface {
2021-09-06 10:45:51 +10:00
Identifier
Collider
Disabler
Hider
2021-09-05 20:58:55 +10:00
Prepper
Transformer
} = &PrismMap{}
_ interface {
Drawer
Transformer
} = &Prism{}
)
func init() {
gob.Register(&PrismMap{})
gob.Register(&Prism{})
}
2021-09-05 20:54:43 +10:00
type PrismMap struct {
2021-09-06 10:45:51 +10:00
ID
Disabled
Hidden
2021-09-06 17:50:17 +10:00
Map map[Point3]*Prism // pos -> prism
DrawOrderBias image.Point // dot with pos.XY() = bias value
DrawOffset image.Point // offset applies to whole map
PosToDraw IntMatrix2x3 // p.pos -> drawspace (before offset and camera and ...)
PosToWorld IntMatrix3x4 // p.pos -> worldspace
PrismSize Point3 // in worldspace
2021-09-05 20:54:43 +10:00
Sheet Sheet
}
2021-09-06 10:45:51 +10:00
func (m *PrismMap) CollidesWith(b Box) bool {
2021-09-06 17:50:17 +10:00
// Back corner of a prism p is:
// m.PrismPos.Apply(p.pos)
2021-09-06 10:45:51 +10:00
return false
}
2021-09-05 20:54:43 +10:00
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
}
2021-09-05 20:58:55 +10:00
func (p *Prism) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
screen.DrawImage(p.pm.Sheet.SubImage(p.Cell), opts)
2021-09-05 20:54:43 +10:00
}
func (p *Prism) DrawOrder() (int, int) {
2021-09-06 17:50:17 +10:00
return p.pm.PosToWorld.Apply(p.pos).Z,
2021-09-05 20:54:43 +10:00
dot(p.pos.XY(), p.pm.DrawOrderBias)
}
func (p *Prism) Transform(pt Transform) (tf Transform) {
tf.Opts.GeoM.Translate(cfloat(
2021-09-06 17:50:17 +10:00
p.pm.PosToDraw.Apply(p.pos),
2021-09-05 20:54:43 +10:00
))
return tf.Concat(pt)
}