walking around on hexagons

This commit is contained in:
Josh Deprez 2021-09-07 20:45:04 +10:00
parent 6c5f482e56
commit d73715f3e2
4 changed files with 227 additions and 18 deletions

View file

@ -52,6 +52,20 @@ func (b Box) Sub(p Int3) Box {
} }
} }
// Canon returns a copy of b that is well-formed.
func (b Box) Canon() Box {
if b.Max.X < b.Min.X {
b.Min.X, b.Max.X = b.Max.X, b.Min.X
}
if b.Max.Y < b.Min.Y {
b.Min.Y, b.Max.Y = b.Max.Y, b.Min.Y
}
if b.Max.Z < b.Min.Z {
b.Min.Z, b.Max.Z = b.Max.Z, b.Min.Z
}
return b
}
// Back returns an image.Rectangle representing the back of the box, using // Back returns an image.Rectangle representing the back of the box, using
// the given projection π. // the given projection π.
func (b Box) Back(π IntProjection) image.Rectangle { func (b Box) Back(π IntProjection) image.Rectangle {

View file

@ -60,9 +60,13 @@ func (m *PrismMap) CollidesWith(b Box) bool {
// (Spoilers: I did this already in Prepare) // (Spoilers: I did this already in Prepare)
b.Min = m.pwinverse.IntApply(b.Min) b.Min = m.pwinverse.IntApply(b.Min)
b.Max = m.pwinverse.IntApply(b.Max.Sub(Int3{1, 1, 1})) b.Max = m.pwinverse.IntApply(b.Max.Sub(Int3{1, 1, 1}))
for k := b.Min.Z; k < b.Max.Z; k++ { b = b.Canon() // inverse might flip the corners around...
for j := b.Min.Y; j < b.Max.Y; j++ {
for i := b.Min.X; i < b.Max.X; i++ { log.Printf("b.Max = %v", b.Max)
for k := b.Min.Z; k <= b.Max.Z; k++ {
for j := b.Min.Y; j <= b.Max.Y; j++ {
for i := b.Min.X; i <= b.Max.X; i++ {
// TODO: take into account the prism shape... // TODO: take into account the prism shape...
if _, found := m.Map[Int3{i, j, k}]; found { if _, found := m.Map[Int3{i, j, k}]; found {
return true return true
@ -80,7 +84,7 @@ func (m *PrismMap) Prepare(g *Game) error {
return fmt.Errorf("inverting PosToWorld: %w", err) return fmt.Errorf("inverting PosToWorld: %w", err)
} }
m.pwinverse = pwi m.pwinverse = pwi
log.Printf("inverted PosToWorld: %v", pwi) // log.Printf("inverted PosToWorld: %v", pwi)
for v, p := range m.Map { for v, p := range m.Map {
p.pos = v p.pos = v
p.m = m p.m = m

View file

@ -48,6 +48,7 @@ func (aw *Awakeman) Update() error {
// TODO: better cheat for noclip // TODO: better cheat for noclip
if inpututil.IsKeyJustPressed(ebiten.KeyN) { if inpututil.IsKeyJustPressed(ebiten.KeyN) {
aw.noclip = !aw.noclip aw.noclip = !aw.noclip
aw.vx, aw.vy, aw.vz = 0, 0, 0
if aw.toast != nil { if aw.toast != nil {
if aw.noclip { if aw.noclip {
aw.toast.Toast("noclip enabled") aw.toast.Toast("noclip enabled")

214
main.go
View file

@ -150,20 +150,210 @@ func level1() *engine.Scene {
Src: engine.ImageRef{Path: "assets/hexprism32.png"}, Src: engine.ImageRef{Path: "assets/hexprism32.png"},
}, },
Map: map[engine.Int3]*engine.Prism{ Map: map[engine.Int3]*engine.Prism{
engine.Pt3(11, 0, -6): {},
engine.Pt3(12, 0, -6): {},
engine.Pt3(9, 0, -5): {},
engine.Pt3(10, 0, -5): {},
engine.Pt3(11, 0, -5): {},
engine.Pt3(12, 0, -5): {},
engine.Pt3(7, 0, -4): {},
engine.Pt3(8, 0, -4): {},
engine.Pt3(9, 0, -4): {},
engine.Pt3(10, 0, -4): {},
engine.Pt3(11, 0, -4): {},
engine.Pt3(12, 0, -4): {},
engine.Pt3(5, 0, -3): {},
engine.Pt3(6, 0, -3): {},
engine.Pt3(7, 0, -3): {},
engine.Pt3(8, 0, -3): {},
engine.Pt3(9, 0, -3): {},
engine.Pt3(10, 0, -3): {},
engine.Pt3(11, 0, -3): {},
engine.Pt3(12, 0, -3): {},
engine.Pt3(3, 0, -2): {},
engine.Pt3(4, 0, -2): {},
engine.Pt3(5, 0, -2): {},
engine.Pt3(6, 0, -2): {},
engine.Pt3(7, 0, -2): {},
engine.Pt3(8, 0, -2): {},
engine.Pt3(9, 0, -2): {},
engine.Pt3(10, 0, -2): {},
engine.Pt3(11, 0, -2): {},
engine.Pt3(12, 0, -2): {},
engine.Pt3(1, 0, -1): {},
engine.Pt3(2, 0, -1): {},
engine.Pt3(3, 0, -1): {},
engine.Pt3(4, 0, -1): {},
engine.Pt3(5, 0, -1): {},
engine.Pt3(6, 0, -1): {},
engine.Pt3(7, 0, -1): {},
engine.Pt3(8, 0, -1): {},
engine.Pt3(9, 0, -1): {},
engine.Pt3(10, 0, -1): {},
engine.Pt3(11, 0, -1): {},
engine.Pt3(12, 0, -1): {},
engine.Pt3(0, 0, 0): {}, engine.Pt3(0, 0, 0): {},
engine.Pt3(1, 0, 0): {}, engine.Pt3(1, 0, 0): {},
engine.Pt3(2, 0, 0): {}, engine.Pt3(2, 0, 0): {},
engine.Pt3(3, 0, 0): {},
engine.Pt3(4, -2, 0): {},
engine.Pt3(4, -1, 0): {},
engine.Pt3(4, 0, 0): {}, engine.Pt3(4, 0, 0): {},
engine.Pt3(5, 0, 0): {},
engine.Pt3(6, 0, -2): {},
engine.Pt3(6, 0, -1): {},
engine.Pt3(6, 0, 0): {}, engine.Pt3(6, 0, 0): {},
engine.Pt3(7, 0, 0): {},
engine.Pt3(8, 0, 0): {},
engine.Pt3(9, 0, 0): {},
engine.Pt3(10, 0, 0): {},
engine.Pt3(11, 0, 0): {},
engine.Pt3(12, 0, 0): {},
engine.Pt3(0, 0, 1): {},
engine.Pt3(1, 0, 1): {},
engine.Pt3(2, 0, 1): {},
engine.Pt3(3, 0, 1): {},
engine.Pt3(4, 0, 1): {},
engine.Pt3(5, 0, 1): {},
engine.Pt3(6, 0, 1): {},
engine.Pt3(7, 0, 1): {},
engine.Pt3(8, 0, 1): {},
engine.Pt3(9, 0, 1): {},
engine.Pt3(10, 0, 1): {},
engine.Pt3(11, 0, 1): {},
engine.Pt3(12, 0, 1): {},
engine.Pt3(0, 0, 2): {},
engine.Pt3(1, 0, 2): {},
engine.Pt3(2, 0, 2): {},
engine.Pt3(3, 0, 2): {},
engine.Pt3(4, 0, 2): {},
engine.Pt3(5, 0, 2): {},
engine.Pt3(6, 0, 2): {},
engine.Pt3(7, 0, 2): {},
engine.Pt3(8, 0, 2): {},
engine.Pt3(9, 0, 2): {},
engine.Pt3(10, 0, 2): {},
engine.Pt3(11, 0, 2): {},
engine.Pt3(12, 0, 2): {},
engine.Pt3(0, 0, 3): {},
engine.Pt3(1, 0, 3): {},
engine.Pt3(2, 0, 3): {},
engine.Pt3(3, 0, 3): {},
engine.Pt3(4, 0, 3): {},
engine.Pt3(5, 0, 3): {},
engine.Pt3(6, 0, 3): {},
engine.Pt3(7, 0, 3): {},
engine.Pt3(8, 0, 3): {},
engine.Pt3(9, 0, 3): {},
engine.Pt3(10, 0, 3): {},
engine.Pt3(11, 0, 3): {},
engine.Pt3(12, 0, 3): {},
engine.Pt3(0, 0, 4): {},
engine.Pt3(1, 0, 4): {},
engine.Pt3(2, 0, 4): {},
engine.Pt3(3, 0, 4): {},
engine.Pt3(4, 0, 4): {},
engine.Pt3(5, 0, 4): {},
engine.Pt3(6, 0, 4): {},
engine.Pt3(7, 0, 4): {},
engine.Pt3(8, 0, 4): {},
engine.Pt3(9, 0, 4): {},
engine.Pt3(10, 0, 4): {},
engine.Pt3(11, 0, 4): {},
engine.Pt3(12, 0, 4): {},
engine.Pt3(0, 0, 5): {},
engine.Pt3(1, 0, 5): {},
engine.Pt3(2, 0, 5): {},
engine.Pt3(3, 0, 5): {},
engine.Pt3(4, 0, 5): {},
engine.Pt3(5, 0, 5): {},
engine.Pt3(6, 0, 5): {},
engine.Pt3(7, 0, 5): {},
engine.Pt3(8, 0, 5): {},
engine.Pt3(9, 0, 5): {},
engine.Pt3(10, 0, 5): {},
engine.Pt3(11, 0, 5): {},
engine.Pt3(12, 0, 5): {},
engine.Pt3(0, 0, 6): {},
engine.Pt3(1, 0, 6): {},
engine.Pt3(2, 0, 6): {},
engine.Pt3(3, 0, 6): {},
engine.Pt3(4, 0, 6): {},
engine.Pt3(5, 0, 6): {},
engine.Pt3(6, 0, 6): {},
engine.Pt3(7, 0, 6): {},
engine.Pt3(8, 0, 6): {},
engine.Pt3(9, 0, 6): {},
engine.Pt3(10, 0, 6): {},
engine.Pt3(11, 0, 6): {},
engine.Pt3(12, 0, 6): {},
engine.Pt3(0, 0, 7): {},
engine.Pt3(1, 0, 7): {},
engine.Pt3(2, 0, 7): {},
engine.Pt3(3, 0, 7): {},
engine.Pt3(4, 0, 7): {},
engine.Pt3(5, 0, 7): {},
engine.Pt3(6, 0, 7): {},
engine.Pt3(7, 0, 7): {},
engine.Pt3(8, 0, 7): {},
engine.Pt3(9, 0, 7): {},
engine.Pt3(10, 0, 7): {},
engine.Pt3(11, 0, 7): {},
engine.Pt3(12, 0, 7): {},
engine.Pt3(0, 0, 8): {},
engine.Pt3(1, 0, 8): {},
engine.Pt3(2, 0, 8): {},
engine.Pt3(3, 0, 8): {},
engine.Pt3(4, 0, 8): {},
engine.Pt3(5, 0, 8): {},
engine.Pt3(6, 0, 8): {},
engine.Pt3(7, 0, 8): {},
engine.Pt3(8, 0, 8): {},
engine.Pt3(9, 0, 8): {},
engine.Pt3(10, 0, 8): {},
engine.Pt3(0, 0, 9): {},
engine.Pt3(1, 0, 9): {},
engine.Pt3(2, 0, 9): {},
engine.Pt3(3, 0, 9): {},
engine.Pt3(4, 0, 9): {},
engine.Pt3(5, 0, 9): {},
engine.Pt3(6, 0, 9): {},
engine.Pt3(7, 0, 9): {},
engine.Pt3(8, 0, 9): {},
engine.Pt3(0, 0, 10): {},
engine.Pt3(1, 0, 10): {},
engine.Pt3(2, 0, 10): {},
engine.Pt3(3, 0, 10): {},
engine.Pt3(4, 0, 10): {},
engine.Pt3(5, 0, 10): {},
engine.Pt3(6, 0, 10): {},
engine.Pt3(0, 0, 11): {},
engine.Pt3(1, 0, 11): {},
engine.Pt3(2, 0, 11): {},
engine.Pt3(3, 0, 11): {},
engine.Pt3(4, 0, 11): {},
engine.Pt3(0, 0, 12): {},
engine.Pt3(1, 0, 12): {},
engine.Pt3(2, 0, 12): {},
engine.Pt3(0, 0, 13): {},
}, },
}, },
&engine.Tilemap{ /*&engine.Tilemap{
ID: "terrain", ID: "terrain",
ZOrder: -1, ZOrder: -1,
Map: tiles, Map: tiles,
@ -187,8 +377,8 @@ func level1() *engine.Scene {
CellSize: image.Pt(16, 16), CellSize: image.Pt(16, 16),
Src: engine.ImageRef{Path: "assets/boxes.png"}, Src: engine.ImageRef{Path: "assets/boxes.png"},
}, },
}, },*/
&engine.SolidRect{ /*&engine.SolidRect{
ID: "ceiling", ID: "ceiling",
Box: engine.Box{Min: engine.Pt3(0, -1, 0), Max: engine.Pt3(320, 0, 100)}, Box: engine.Box{Min: engine.Pt3(0, -1, 0), Max: engine.Pt3(320, 0, 100)},
}, },
@ -199,15 +389,15 @@ func level1() *engine.Scene {
&engine.SolidRect{ &engine.SolidRect{
ID: "right_wall", ID: "right_wall",
Box: engine.Box{Min: engine.Pt3(320, 0, 0), Max: engine.Pt3(321, 240, 100)}, Box: engine.Box{Min: engine.Pt3(320, 0, 0), Max: engine.Pt3(321, 240, 100)},
}, },*/
&game.Awakeman{ &game.Awakeman{
CameraID: "game_camera", CameraID: "game_camera",
ToastID: "toast", ToastID: "toast",
Sprite: engine.Sprite{ Sprite: engine.Sprite{
Actor: engine.Actor{ Actor: engine.Actor{
CollisionDomain: "level_1", CollisionDomain: "level_1",
Pos: engine.Pt3(100, 100, 0), Pos: engine.Pt3(100, 0, 100),
Size: engine.Pt3(8, 16, 8), Size: engine.Pt3(8, 16, 1),
}, },
DrawOffset: image.Pt(-1, 0), DrawOffset: image.Pt(-1, 0),
Sheet: engine.Sheet{ Sheet: engine.Sheet{