ichigo/engine/tiles.go

31 lines
570 B
Go
Raw Normal View History

2021-07-23 17:05:05 +10:00
package engine
2021-07-23 17:17:56 +10:00
import (
"image"
"github.com/hajimehoshi/ebiten/v2"
)
2021-07-23 17:05:05 +10:00
type Tilemap struct {
Map [][]int
Src *ebiten.Image
TileSize int
2021-07-23 17:17:56 +10:00
GeoM ebiten.GeoM
2021-07-23 17:05:05 +10:00
ZPos
}
func (t *Tilemap) Draw(screen *ebiten.Image) {
2021-07-23 17:17:56 +10:00
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)
2021-07-23 17:05:05 +10:00
2021-07-23 17:17:56 +10:00
sx := tile * t.TileSize
src := t.Src.SubImage(image.Rect(sx, 0, sx+t.TileSize, t.TileSize)).(*ebiten.Image)
screen.DrawImage(src, &op)
}
}
2021-07-23 17:05:05 +10:00
}