change of bounds computation
This commit is contained in:
parent
f0288cd169
commit
724b5af8a3
5 changed files with 28 additions and 18 deletions
|
@ -19,16 +19,21 @@ func init() {
|
||||||
// Actor handles basic movement.
|
// Actor handles basic movement.
|
||||||
type Actor struct {
|
type Actor struct {
|
||||||
CollisionDomain string // id of component to look for colliders inside of
|
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
|
rem geom.Float3
|
||||||
game *Game
|
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
|
// CollidesAt runs a collision test of the actor, supposing the actor is at a
|
||||||
// given position (not necessarily a.Pos).
|
// given position (not necessarily a.Pos).
|
||||||
func (a *Actor) CollidesAt(p geom.Int3) bool {
|
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) {
|
for c := range a.game.Query(a.CollisionDomain, ColliderType) {
|
||||||
if c.(Collider).CollidesWith(bounds) {
|
if c.(Collider).CollidesWith(bounds) {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -35,14 +35,13 @@ type PrismMap struct {
|
||||||
ID
|
ID
|
||||||
Disabled
|
Disabled
|
||||||
Hidden
|
Hidden
|
||||||
Ersatz bool
|
Ersatz bool
|
||||||
Map map[geom.Int3]*Prism // pos -> prism
|
Map map[geom.Int3]*Prism // pos -> prism
|
||||||
DrawOrderBias image.Point // dot with pos.XY() = bias value
|
DrawOffset image.Point // offset applies to whole map
|
||||||
DrawOffset image.Point // offset applies to whole map
|
PosToWorld geom.IntMatrix3x4 // p.pos -> world voxelspace
|
||||||
PosToWorld geom.IntMatrix3x4 // p.pos -> world voxelspace
|
PrismSize geom.Int3 // in world voxelspace units
|
||||||
PrismSize geom.Int3 // in world voxelspace units
|
PrismTop []image.Point // polygon vertices anticlockwise, Y means Z
|
||||||
PrismTop []image.Point // polygon vertices anticlockwise, Y means Z
|
Sheet Sheet
|
||||||
Sheet Sheet
|
|
||||||
|
|
||||||
game *Game
|
game *Game
|
||||||
pwinverse geom.RatMatrix3
|
pwinverse geom.RatMatrix3
|
||||||
|
@ -152,7 +151,7 @@ func (p *Prism) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
|
|
||||||
func (p *Prism) DrawOrder() (int, int) {
|
func (p *Prism) DrawOrder() (int, int) {
|
||||||
return p.m.PosToWorld.Apply(p.pos).Z,
|
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) {
|
func (p *Prism) Transform() (opts ebiten.DrawImageOptions) {
|
||||||
|
|
|
@ -72,9 +72,7 @@ func (aw *Awakeman) Update() error {
|
||||||
if ebiten.IsKeyPressed(ebiten.KeyShift) {
|
if ebiten.IsKeyPressed(ebiten.KeyShift) {
|
||||||
z = 2.0
|
z = 2.0
|
||||||
}
|
}
|
||||||
pos := aw.Sprite.Actor.Pos
|
aw.camera.PointAt(aw.Sprite.Actor.BoundingBox().Centre(), z)
|
||||||
size := aw.Sprite.Actor.Size
|
|
||||||
aw.camera.PointAt(pos.Add(size.Div(2)), z)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ func Level1() *engine.Scene {
|
||||||
Factor: 0.5,
|
Factor: 0.5,
|
||||||
},
|
},
|
||||||
&engine.PrismMap{
|
&engine.PrismMap{
|
||||||
ID: "hexagons",
|
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{
|
PosToWorld: geom.IntMatrix3x4{
|
||||||
// For each tile in the X direction, go right by 24 and
|
// For each tile in the X direction, go right by 24 and
|
||||||
// forward by 8, etc
|
// forward by 8, etc
|
||||||
|
@ -264,9 +264,12 @@ func Level1() *engine.Scene {
|
||||||
Actor: engine.Actor{
|
Actor: engine.Actor{
|
||||||
CollisionDomain: "level_1",
|
CollisionDomain: "level_1",
|
||||||
Pos: geom.Pt3(100, -64, 100),
|
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{
|
Sheet: engine.Sheet{
|
||||||
AnimDefs: map[string]*engine.AnimDef{
|
AnimDefs: map[string]*engine.AnimDef{
|
||||||
"idle_left": {Steps: []engine.AnimStep{
|
"idle_left": {Steps: []engine.AnimStep{
|
||||||
|
|
|
@ -36,6 +36,11 @@ func (b Box) Size() Int3 {
|
||||||
return b.Max.Sub(b.Min)
|
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.
|
// Add offsets the box by vector p.
|
||||||
func (b Box) Add(p Int3) Box {
|
func (b Box) Add(p Int3) Box {
|
||||||
return Box{
|
return Box{
|
||||||
|
|
Loading…
Reference in a new issue