From 19eb6361f52c9a2320e6fe10b4d71924f2ea810d Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Mon, 2 Aug 2021 16:32:27 +1000 Subject: [PATCH] support rectangular tile sources --- .DS_Store | Bin 6148 -> 6148 bytes assets/boxes.png | Bin 1186 -> 1470 bytes engine/tiles.go | 9 ++++++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.DS_Store b/.DS_Store index 103ec41e77681e130746129bb3b7038aef1858fd..4dab03e158312054410e3787b1afff4dc04adc04 100644 GIT binary patch delta 38 ucmZoMXfc@J&&a$nU^gQp^JE^Tube5x$vH{+`8kZ6KQjGg+04%ImmdK4+6{C7 delta 33 pcmZoMXfc@J&&aefU^nAr0}+xN6v>SsM0-S>G>IySX6k-QiikKbg&Z8j!Wmz z-oxbC|Kra-Ieq)j|NsAIuif5K*PfY`6&V&(=G3*u$mnKx^7ZOn{nNd=@(qCIkAl$< z7_=d9p{{}nm@gPgg8YIRfT?*T1Fq>`Y=B{r;OXKR;?cQv%5AP-)A0M)o{|@m=Ll?^#U3I8P{jUZ*4=+OS`3^dqEmL2dw~jgauyM@> z0fRGXxd8_^pOD{i;@Z;3T+ctqRWk4>E#K09D0e~Ln}?#o%Wf;n{kt=dnd@O=5ckF6 zin&)`b9|a+vEV3U#Eb*qRRzvE{t3MjnsDZJw~xTd*KLOO#is{eS3hY?SkU~E+u_-oWs%?9IYF7i)78&q Iol`;+0Pi#J)c^nh delta 416 zcmV;R0bl;U3!(`jiBL{Q4GJ0x0000DNk~Le0001>0000G2m=5B0H)i7YOyX31AhPk zbW%=J06^y0W&i*IP)S5VR7i=%mfMblFbqWN}X4dwCyrHqH-Xi9?E!)5HXu5}yOsiQWfH;v{(wnz#Y6zX$6cYD=o`GoTMD0J^04 zlJFYPGN3U#phaW43F@vTKvDv1x|pBoRbtyU4|R(~z<>u3;0&Et0b|R44|R~jgZxYQ z3u8u?xEV9PF4^m@6@YDt8Omz^M@{ln3D!*lqKmbE3vhhQ908Vka&FRJ0z4ViKI^SP zUA7+Np;&zHO`^xlq5tH&*ovvmzVjye-;V|D+Y%4T-xQo^Rr&>8v#h56&oCAM0000< KMNUMnLSTY9QnPXZ diff --git a/engine/tiles.go b/engine/tiles.go index 571c005..d60c1a0 100644 --- a/engine/tiles.go +++ b/engine/tiles.go @@ -19,7 +19,7 @@ type Tilemap struct { Hidden bool ID Map [][]Tile - Src ImageRef // must be a horizontal tile set + Src ImageRef TileSize int Transform GeoMDef ZPos @@ -30,6 +30,8 @@ func (t *Tilemap) Draw(screen *ebiten.Image, geom ebiten.GeoM) { if t.Hidden { return } + src := t.Src.Image() + w, _ := src.Size() geom.Concat(*t.Transform.GeoM()) for j, row := range t.Map { for i, tile := range row { @@ -40,8 +42,9 @@ func (t *Tilemap) Draw(screen *ebiten.Image, geom ebiten.GeoM) { op.GeoM.Translate(float64(i*t.TileSize), float64(j*t.TileSize)) op.GeoM.Concat(geom) - sx := tile.TileIndex() * t.TileSize - src := t.Src.Image().SubImage(image.Rect(sx, 0, sx+t.TileSize, t.TileSize)).(*ebiten.Image) + s := tile.TileIndex() * t.TileSize + sx, sy := s%w, (s/w)*t.TileSize + src := src.SubImage(image.Rect(sx, sy, sx+t.TileSize, sy+t.TileSize)).(*ebiten.Image) screen.DrawImage(src, &op) } }