add some cubes and stuff
This commit is contained in:
parent
abdb975979
commit
0565ef0b7f
3 changed files with 34 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"image"
|
||||
"strconv"
|
||||
|
||||
|
@ -25,6 +26,12 @@ var (
|
|||
} = &IsoVoxelSide{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
gob.Register(&IsoVoxmap{})
|
||||
gob.Register(&IsoVoxel{})
|
||||
gob.Register(&IsoVoxelSide{})
|
||||
}
|
||||
|
||||
// Point3 is a an element of int^3.
|
||||
type Point3 struct {
|
||||
X, Y, Z int
|
||||
|
@ -152,7 +159,7 @@ type IsoVoxmap struct {
|
|||
DrawOrderBias image.Point // so boxes overdraw correctly
|
||||
OffsetBack image.Point // offsets the image drawn for the back
|
||||
OffsetFront image.Point // offsets the image drawn for the front
|
||||
Proj image.Point // IsoProjection parameter
|
||||
Projection image.Point // IsoProjection parameter
|
||||
Sheet Sheet
|
||||
VoxSize Point3 // size of each voxel
|
||||
}
|
||||
|
@ -201,10 +208,11 @@ func (v *IsoVoxel) Scan() []interface{} {
|
|||
return []interface{}{&v.back, &v.front}
|
||||
}
|
||||
|
||||
// Transform returns the transform for drawing this voxel.
|
||||
// Transform returns a translation of pos.CMul(VoxSize) iso-projected
|
||||
// (the top-left of the back of the voxel).
|
||||
func (v *IsoVoxel) Transform() (opts ebiten.DrawImageOptions) {
|
||||
p3 := v.pos.CMul(v.ivm.VoxSize)
|
||||
p2 := p3.IsoProject(v.ivm.Proj)
|
||||
p2 := p3.IsoProject(v.ivm.Projection)
|
||||
opts.GeoM.Translate(cfloat(p2))
|
||||
return opts
|
||||
}
|
||||
|
|
Binary file not shown.
25
main.go
25
main.go
|
@ -119,9 +119,30 @@ func writeLevel1() {
|
|||
},
|
||||
Factor: 0.5,
|
||||
},
|
||||
&engine.IsoVoxmap{
|
||||
ID: "voxmap",
|
||||
DrawOrderBias: image.Pt(1, -1), // draw left before right, bottom before top
|
||||
OffsetBack: image.Pt(-8, 0),
|
||||
OffsetFront: image.Pt(-8, 0),
|
||||
Projection: image.Pt(-2, 2), // each step in Z becomes -1/2 step in X plus 1/2 step in Y.
|
||||
VoxSize: engine.Pt3(16, 16, 16),
|
||||
Sheet: engine.Sheet{
|
||||
CellSize: image.Pt(24, 24),
|
||||
Src: engine.ImageRef{Path: "assets/box16.png"},
|
||||
},
|
||||
Map: map[engine.Point3]*engine.IsoVoxel{
|
||||
engine.Pt3(0, 2, 0): {CellBack: 0, CellFront: 1},
|
||||
engine.Pt3(1, 2, 0): {CellBack: 0, CellFront: 1},
|
||||
engine.Pt3(2, 2, 0): {CellBack: 0, CellFront: 1},
|
||||
|
||||
engine.Pt3(5, 0, 0): {CellBack: 0, CellFront: 1},
|
||||
engine.Pt3(5, 1, 0): {CellBack: 0, CellFront: 1},
|
||||
engine.Pt3(5, 2, 0): {CellBack: 0, CellFront: 1},
|
||||
},
|
||||
},
|
||||
&engine.Tilemap{
|
||||
ID: "terrain",
|
||||
ZOrder: 2,
|
||||
ZOrder: 8,
|
||||
Map: tiles,
|
||||
Sheet: engine.Sheet{
|
||||
AnimDefs: map[string]*engine.AnimDef{
|
||||
|
@ -203,7 +224,7 @@ func writeLevel1() {
|
|||
CellSize: image.Pt(10, 16),
|
||||
Src: engine.ImageRef{Path: "assets/aw.png"},
|
||||
},
|
||||
ZOrder: 3,
|
||||
ZOrder: 9,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue