make billboard more complicated
This commit is contained in:
parent
146e713fd7
commit
0981350993
2 changed files with 48 additions and 8 deletions
|
@ -2,7 +2,6 @@ package engine
|
|||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"image"
|
||||
|
||||
"drjosh.dev/gurgle/geom"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
|
@ -10,6 +9,7 @@ import (
|
|||
|
||||
// Ensure Billboard satisfies interfaces.
|
||||
var _ interface {
|
||||
BoundingBoxer
|
||||
Identifier
|
||||
Drawer
|
||||
Scanner
|
||||
|
@ -24,9 +24,19 @@ func init() {
|
|||
type Billboard struct {
|
||||
ID
|
||||
Hides
|
||||
Pos image.Point
|
||||
Pos geom.Int3
|
||||
Src ImageRef
|
||||
ZPosition
|
||||
|
||||
game *Game
|
||||
}
|
||||
|
||||
// BoundingBox returns a 0-depth box incorporating the image size.
|
||||
func (b *Billboard) BoundingBox() geom.Box {
|
||||
sx, sy := b.Src.Image().Size()
|
||||
return geom.Box{
|
||||
Min: b.Pos,
|
||||
Max: b.Pos.Add(geom.Pt3(sx, sy, 0)),
|
||||
}
|
||||
}
|
||||
|
||||
// Draw draws the image.
|
||||
|
@ -34,10 +44,41 @@ func (b *Billboard) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
|||
screen.DrawImage(b.Src.Image(), opts)
|
||||
}
|
||||
|
||||
// DrawAfter reports if b.Pos.Z >= x.Max.Z.
|
||||
func (b *Billboard) DrawAfter(x Drawer) bool {
|
||||
switch x := x.(type) {
|
||||
case BoundingBoxer:
|
||||
return b.Pos.Z >= x.BoundingBox().Max.Z
|
||||
case ZPositioner:
|
||||
return b.Pos.Z > x.ZPos()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// DrawBefore reports if b.Pos.Z < x.Min.Z.
|
||||
func (b *Billboard) DrawBefore(x Drawer) bool {
|
||||
switch x := x.(type) {
|
||||
case BoundingBoxer:
|
||||
return b.Pos.Z < x.BoundingBox().Min.Z
|
||||
case ZPositioner:
|
||||
return b.Pos.Z < x.ZPos()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Prepare saves the reference to Game.
|
||||
func (b *Billboard) Prepare(g *Game) error {
|
||||
b.game = g
|
||||
return nil
|
||||
}
|
||||
|
||||
// Scan returns a slice containing Src.
|
||||
func (b *Billboard) Scan() []interface{} { return []interface{}{&b.Src} }
|
||||
|
||||
// Transform returns a translation by the projected position.
|
||||
func (b *Billboard) Transform() (opts ebiten.DrawImageOptions) {
|
||||
opts.GeoM.Translate(geom.CFloat(b.Pos))
|
||||
opts.GeoM.Translate(geom.CFloat(
|
||||
b.game.Projection.Project(b.Pos),
|
||||
))
|
||||
return opts
|
||||
}
|
||||
|
|
|
@ -22,10 +22,9 @@ func Level1() *engine.Scene {
|
|||
&engine.Parallax{
|
||||
CameraID: "game_camera",
|
||||
Child: &engine.Billboard{
|
||||
ID: "bg_image",
|
||||
ZPosition: -900,
|
||||
Pos: image.Pt(-160, -120),
|
||||
Src: engine.ImageRef{Path: "assets/space.png"},
|
||||
ID: "bg_image",
|
||||
Pos: geom.Pt3(-160, -120, -1),
|
||||
Src: engine.ImageRef{Path: "assets/space.png"},
|
||||
},
|
||||
Factor: 0.5,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue