This commit is contained in:
Josh Deprez 2021-07-23 17:17:56 +10:00 committed by Josh Deprez
parent aa6cbbf295
commit a2fb805f41

View file

@ -1,16 +1,30 @@
package engine
import "github.com/hajimehoshi/ebiten/v2"
import (
"image"
"github.com/hajimehoshi/ebiten/v2"
)
type Tilemap struct {
Map [][]int
Src *ebiten.Image
TileSize int
GeoM *ebiten.GeoM
GeoM ebiten.GeoM
ZPos
}
func (t *Tilemap) Draw(screen *ebiten.Image) {
for j, row := range t.Map {
for i, tile := range row {
var op ebiten.DrawImageOptions
op.GeoM.Translate(float64(i*t.TileSize), float64(j*t.TileSize))
op.GeoM.Concat(t.GeoM)
sx := tile * t.TileSize
src := t.Src.SubImage(image.Rect(sx, 0, sx+t.TileSize, t.TileSize)).(*ebiten.Image)
screen.DrawImage(src, &op)
}
}
}