light renaming
This commit is contained in:
parent
66ddcdabf7
commit
9785b556e5
8 changed files with 22 additions and 22 deletions
|
@ -37,6 +37,6 @@ func (b *Billboard) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
func (b *Billboard) Scan() []interface{} { return []interface{}{&b.Src} }
|
func (b *Billboard) Scan() []interface{} { return []interface{}{&b.Src} }
|
||||||
|
|
||||||
func (b *Billboard) Transform() (opts ebiten.DrawImageOptions) {
|
func (b *Billboard) Transform() (opts ebiten.DrawImageOptions) {
|
||||||
opts.GeoM.Translate(float2(b.Pos))
|
opts.GeoM.Translate(pfloat(b.Pos))
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ func (c *Camera) PointAt(centre image.Point, zoom float64) {
|
||||||
|
|
||||||
// If the configured centre puts the camera out of bounds, move it.
|
// If the configured centre puts the camera out of bounds, move it.
|
||||||
// Camera frame currently Rectangle{ centre ± (screen/(2*zoom)) }.
|
// Camera frame currently Rectangle{ centre ± (screen/(2*zoom)) }.
|
||||||
sw2, sh2 := float2(c.game.ScreenSize.Div(2))
|
sw2, sh2 := pfloat(c.game.ScreenSize.Div(2))
|
||||||
swz, shz := int(sw2/zoom), int(sh2/zoom)
|
swz, shz := int(sw2/zoom), int(sh2/zoom)
|
||||||
if centre.X-swz < br.Min.X {
|
if centre.X-swz < br.Min.X {
|
||||||
centre.X = br.Min.X + swz
|
centre.X = br.Min.X + swz
|
||||||
|
@ -87,9 +87,9 @@ func (c *Camera) Scan() []interface{} { return []interface{}{c.Child} }
|
||||||
|
|
||||||
// Transform returns the camera transform.
|
// Transform returns the camera transform.
|
||||||
func (c *Camera) Transform() (opts ebiten.DrawImageOptions) {
|
func (c *Camera) Transform() (opts ebiten.DrawImageOptions) {
|
||||||
opts.GeoM.Translate(float2(c.Centre.Mul(-1)))
|
opts.GeoM.Translate(pfloat(c.Centre.Mul(-1)))
|
||||||
opts.GeoM.Scale(c.Zoom, c.Zoom)
|
opts.GeoM.Scale(c.Zoom, c.Zoom)
|
||||||
opts.GeoM.Rotate(c.Rotation)
|
opts.GeoM.Rotate(c.Rotation)
|
||||||
opts.GeoM.Translate(float2(c.game.ScreenSize.Div(2)))
|
opts.GeoM.Translate(pfloat(c.game.ScreenSize.Div(2)))
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,20 +44,20 @@ type ZOrder float64
|
||||||
// DrawOrder returns z as a float64.
|
// DrawOrder returns z as a float64.
|
||||||
func (z ZOrder) DrawOrder() float64 { return float64(z) }
|
func (z ZOrder) DrawOrder() float64 { return float64(z) }
|
||||||
|
|
||||||
// ---------- Some math helpers ----------
|
// ---------- Some math helpers for image.Point ----------
|
||||||
|
|
||||||
func mul2(p, q image.Point) image.Point {
|
func pmul(p, q image.Point) image.Point {
|
||||||
p.X *= q.X
|
p.X *= q.X
|
||||||
p.Y *= q.Y
|
p.Y *= q.Y
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func div2(p, q image.Point) image.Point {
|
func pdiv(p, q image.Point) image.Point {
|
||||||
p.X /= q.X
|
p.X /= q.X
|
||||||
p.Y /= q.Y
|
p.Y /= q.Y
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func float2(p image.Point) (float64, float64) {
|
func pfloat(p image.Point) (float64, float64) {
|
||||||
return float64(p.X), float64(p.Y)
|
return float64(p.X), float64(p.Y)
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (p *Parallax) Scan() []interface{} { return []interface{}{p.Child} }
|
||||||
|
|
||||||
// Transform returns a GeoM translation of Factor * camera.Centre.
|
// Transform returns a GeoM translation of Factor * camera.Centre.
|
||||||
func (p *Parallax) Transform() (opts ebiten.DrawImageOptions) {
|
func (p *Parallax) Transform() (opts ebiten.DrawImageOptions) {
|
||||||
x, y := float2(p.camera.Centre)
|
x, y := pfloat(p.camera.Centre)
|
||||||
opts.GeoM.Translate(x*p.Factor, y*p.Factor)
|
opts.GeoM.Translate(x*p.Factor, y*p.Factor)
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (s *Sheet) Scan() []interface{} { return []interface{}{&s.Src} }
|
||||||
// SubImage returns an *ebiten.Image corresponding to the cell at the given
|
// SubImage returns an *ebiten.Image corresponding to the cell at the given
|
||||||
// index.
|
// index.
|
||||||
func (s *Sheet) SubImage(i int) *ebiten.Image {
|
func (s *Sheet) SubImage(i int) *ebiten.Image {
|
||||||
p := mul2(image.Pt(i%s.w, i/s.w), s.CellSize)
|
p := pmul(image.Pt(i%s.w, i/s.w), s.CellSize)
|
||||||
r := image.Rectangle{p, p.Add(s.CellSize)}
|
r := image.Rectangle{p, p.Add(s.CellSize)}
|
||||||
return s.Src.Image().SubImage(r).(*ebiten.Image)
|
return s.Src.Image().SubImage(r).(*ebiten.Image)
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ func (s *Sprite) SetAnim(a *Anim) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sprite) Transform() (opts ebiten.DrawImageOptions) {
|
func (s *Sprite) Transform() (opts ebiten.DrawImageOptions) {
|
||||||
opts.GeoM.Translate(float2(s.Actor.Pos.Add(s.FrameOffset)))
|
opts.GeoM.Translate(pfloat(s.Actor.Pos.Add(s.FrameOffset)))
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,8 @@ func (t *Tilemap) CollidesWith(r image.Rectangle) bool {
|
||||||
|
|
||||||
// Probe the map at all tilespace coordinates overlapping the rect.
|
// Probe the map at all tilespace coordinates overlapping the rect.
|
||||||
r = r.Sub(t.Offset)
|
r = r.Sub(t.Offset)
|
||||||
min := div2(r.Min, t.Sheet.CellSize)
|
min := pdiv(r.Min, t.Sheet.CellSize)
|
||||||
max := div2(r.Max.Sub(image.Pt(1, 1)), t.Sheet.CellSize) // NB: fencepost
|
max := pdiv(r.Max.Sub(image.Pt(1, 1)), t.Sheet.CellSize) // NB: fencepost
|
||||||
|
|
||||||
for j := min.Y; j <= max.Y; j++ {
|
for j := min.Y; j <= max.Y; j++ {
|
||||||
for i := min.X; i <= max.X; i++ {
|
for i := min.X; i <= max.X; i++ {
|
||||||
|
@ -73,7 +73,7 @@ func (t *Tilemap) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var geom ebiten.GeoM
|
var geom ebiten.GeoM
|
||||||
geom.Translate(float2(mul2(p, t.Sheet.CellSize)))
|
geom.Translate(pfloat(pmul(p, t.Sheet.CellSize)))
|
||||||
geom.Concat(og)
|
geom.Concat(og)
|
||||||
opts.GeoM = geom
|
opts.GeoM = geom
|
||||||
|
|
||||||
|
@ -93,24 +93,24 @@ func (t *Tilemap) Scan() []interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tilemap) Transform() (opts ebiten.DrawImageOptions) {
|
func (t *Tilemap) Transform() (opts ebiten.DrawImageOptions) {
|
||||||
opts.GeoM.Translate(float2(t.Offset))
|
opts.GeoM.Translate(pfloat(t.Offset))
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
// TileAt returns the tile present at the given world coordinate.
|
// TileAt returns the tile present at the given world coordinate.
|
||||||
func (t *Tilemap) TileAt(wc image.Point) Tile {
|
func (t *Tilemap) TileAt(wc image.Point) Tile {
|
||||||
return t.Map[div2(wc.Sub(t.Offset), t.Sheet.CellSize)]
|
return t.Map[pdiv(wc.Sub(t.Offset), t.Sheet.CellSize)]
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTileAt sets the tile at the given world coordinate.
|
// SetTileAt sets the tile at the given world coordinate.
|
||||||
func (t *Tilemap) SetTileAt(wc image.Point, tile Tile) {
|
func (t *Tilemap) SetTileAt(wc image.Point, tile Tile) {
|
||||||
t.Map[div2(wc.Sub(t.Offset), t.Sheet.CellSize)] = tile
|
t.Map[pdiv(wc.Sub(t.Offset), t.Sheet.CellSize)] = tile
|
||||||
}
|
}
|
||||||
|
|
||||||
// TileBounds returns a rectangle describing the tile boundary for the tile
|
// TileBounds returns a rectangle describing the tile boundary for the tile
|
||||||
// at the given world coordinate.
|
// at the given world coordinate.
|
||||||
func (t *Tilemap) TileBounds(wc image.Point) image.Rectangle {
|
func (t *Tilemap) TileBounds(wc image.Point) image.Rectangle {
|
||||||
p := mul2(div2(wc.Sub(t.Offset), t.Sheet.CellSize), t.Sheet.CellSize).Add(t.Offset)
|
p := pmul(pdiv(wc.Sub(t.Offset), t.Sheet.CellSize), t.Sheet.CellSize).Add(t.Offset)
|
||||||
return image.Rectangle{p, p.Add(t.Sheet.CellSize)}
|
return image.Rectangle{p, p.Add(t.Sheet.CellSize)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,8 @@ func (w *Wall) CollidesWith(r image.Rectangle) bool {
|
||||||
|
|
||||||
// Probe the map at all tilespace coordinates overlapping the rect.
|
// Probe the map at all tilespace coordinates overlapping the rect.
|
||||||
r = r.Sub(w.Offset)
|
r = r.Sub(w.Offset)
|
||||||
min := div2(r.Min, w.UnitSize)
|
min := pdiv(r.Min, w.UnitSize)
|
||||||
max := div2(r.Max.Sub(image.Pt(1, 1)), w.UnitSize) // NB: fencepost
|
max := pdiv(r.Max.Sub(image.Pt(1, 1)), w.UnitSize) // NB: fencepost
|
||||||
|
|
||||||
for j := min.Y; j <= max.Y; j++ {
|
for j := min.Y; j <= max.Y; j++ {
|
||||||
for i := min.X; i <= max.X; i++ {
|
for i := min.X; i <= max.X; i++ {
|
||||||
|
@ -80,7 +80,7 @@ func (w *Wall) Prepare(*Game) error {
|
||||||
|
|
||||||
// Transform returns a GeoM translation by Offset.
|
// Transform returns a GeoM translation by Offset.
|
||||||
func (w *Wall) Transform() (opts ebiten.DrawImageOptions) {
|
func (w *Wall) Transform() (opts ebiten.DrawImageOptions) {
|
||||||
opts.GeoM.Translate(float2(w.Offset))
|
opts.GeoM.Translate(pfloat(w.Offset))
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +106,6 @@ func (u *WallUnit) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
func (u *WallUnit) Scan() []interface{} { return []interface{}{u.Tile} }
|
func (u *WallUnit) Scan() []interface{} { return []interface{}{u.Tile} }
|
||||||
|
|
||||||
func (u *WallUnit) Transform() (opts ebiten.DrawImageOptions) {
|
func (u *WallUnit) Transform() (opts ebiten.DrawImageOptions) {
|
||||||
opts.GeoM.Translate(float2(mul2(u.Pos, u.wall.UnitSize).Add(u.wall.UnitOffset)))
|
opts.GeoM.Translate(pfloat(pmul(u.Pos, u.wall.UnitSize).Add(u.wall.UnitOffset)))
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue