change of bounds computation

This commit is contained in:
Josh Deprez 2021-09-09 17:16:00 +10:00
parent f0288cd169
commit 724b5af8a3
5 changed files with 28 additions and 18 deletions

View file

@ -19,16 +19,21 @@ func init() {
// Actor handles basic movement.
type Actor struct {
CollisionDomain string // id of component to look for colliders inside of
Pos, Size geom.Int3 // in voxels; multiply by game.VoxelScale for regular Euclidean space
Pos geom.Int3 // in voxels; multiply by game.VoxelScale for regular Euclidean space
Bounds geom.Box // in voxels; relative to Pos
rem geom.Float3
game *Game
}
func (a *Actor) BoundingBox() geom.Box {
return a.Bounds.Add(a.Pos)
}
// CollidesAt runs a collision test of the actor, supposing the actor is at a
// given position (not necessarily a.Pos).
func (a *Actor) CollidesAt(p geom.Int3) bool {
bounds := geom.Box{Min: p, Max: p.Add(a.Size)}
bounds := a.Bounds.Add(p)
for c := range a.game.Query(a.CollisionDomain, ColliderType) {
if c.(Collider).CollidesWith(bounds) {
return true

View file

@ -37,7 +37,6 @@ type PrismMap struct {
Hidden
Ersatz bool
Map map[geom.Int3]*Prism // pos -> prism
DrawOrderBias image.Point // dot with pos.XY() = bias value
DrawOffset image.Point // offset applies to whole map
PosToWorld geom.IntMatrix3x4 // p.pos -> world voxelspace
PrismSize geom.Int3 // in world voxelspace units
@ -152,7 +151,7 @@ func (p *Prism) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
func (p *Prism) DrawOrder() (int, int) {
return p.m.PosToWorld.Apply(p.pos).Z,
geom.Dot(p.pos.XY(), p.m.DrawOrderBias)
geom.Dot(p.pos.XY(), image.Point(p.m.game.Projection).Mul(-1))
}
func (p *Prism) Transform() (opts ebiten.DrawImageOptions) {

View file

@ -72,9 +72,7 @@ func (aw *Awakeman) Update() error {
if ebiten.IsKeyPressed(ebiten.KeyShift) {
z = 2.0
}
pos := aw.Sprite.Actor.Pos
size := aw.Sprite.Actor.Size
aw.camera.PointAt(pos.Add(size.Div(2)), z)
aw.camera.PointAt(aw.Sprite.Actor.BoundingBox().Centre(), z)
return nil
}

View file

@ -31,7 +31,7 @@ func Level1() *engine.Scene {
},
&engine.PrismMap{
ID: "hexagons",
DrawOrderBias: image.Pt(0, -1), // draw higher Y after lower Y
//DrawOrderBias: image.Pt(0, -1), // draw higher Y after lower Y
PosToWorld: geom.IntMatrix3x4{
// For each tile in the X direction, go right by 24 and
// forward by 8, etc
@ -264,9 +264,12 @@ func Level1() *engine.Scene {
Actor: engine.Actor{
CollisionDomain: "level_1",
Pos: geom.Pt3(100, -64, 100),
Size: geom.Pt3(8, 16, 2),
Bounds: geom.Box{
Min: geom.Pt3(-4, -16, -1),
Max: geom.Pt3(4, 0, 1),
},
DrawOffset: image.Pt(-1, 0),
},
DrawOffset: image.Pt(-5, -16),
Sheet: engine.Sheet{
AnimDefs: map[string]*engine.AnimDef{
"idle_left": {Steps: []engine.AnimStep{

View file

@ -36,6 +36,11 @@ func (b Box) Size() Int3 {
return b.Max.Sub(b.Min)
}
// Centre returns the centre point of the box.
func (b Box) Centre() Int3 {
return b.Min.Add(b.Max).Div(2)
}
// Add offsets the box by vector p.
func (b Box) Add(p Int3) Box {
return Box{