summaryrefslogtreecommitdiff
path: root/tilemap.go
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2024-04-22 17:54:21 +0100
committerdavidovski <david@davidovski.xyz>2024-04-22 17:54:21 +0100
commite4c0edeacb2c5829f864e116b68f6cad175141b3 (patch)
tree88ebcb9dd06affb1e525f807e3a40b864dd0865b /tilemap.go
parentd57ab031de3987ead9c06c48c8a5ad18a9de860c (diff)
paper-style art
Diffstat (limited to 'tilemap.go')
-rw-r--r--tilemap.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/tilemap.go b/tilemap.go
index 23120fb..2c758d0 100644
--- a/tilemap.go
+++ b/tilemap.go
@@ -10,7 +10,7 @@ import (
type Tilemap struct {
tilesImage *ebiten.Image
- surface *ebiten.Image
+ surfaces []*ebiten.Image
mapWidth int
tileSize int
layers [][]int
@@ -27,25 +27,31 @@ func (* Tilemap) Update() error {
return nil
}
-func (tm * Tilemap) Draw(screen *ebiten.Image) {
+func (tm * Tilemap) Draw(screen *ebiten.Image, x, y float32) {
+ for _, surf := range tm.surfaces {
+ ShadowDraw(screen, surf, x, y, 1.0)
+ }
}
func (tm *Tilemap) UpdateSurface() {
w := tm.tilesImage.Bounds().Dx()
tileXCount := w / tileSize
+ tm.surfaces = make([]*ebiten.Image, len(tm.layers))
+
// Draw each tile with each DrawImage call.
// As the source images of all DrawImage calls are always same,
// this rendering is done very efficiently.
// For more detail, see https://pkg.go.dev/github.com/hajimehoshi/ebiten/v2#Image.DrawImage
- for _, l := range tm.layers {
+ for idx, l := range tm.layers {
+ tm.surfaces[idx] = ebiten.NewImage(tm.mapWidth*tm.tileSize, len(l)/tm.mapWidth*tm.tileSize)
for i, t := range l {
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64((i%tm.mapWidth)*tm.tileSize), float64((i/tm.mapWidth)*tm.tileSize))
sx := (t % tileXCount) * tileSize
sy := (t / tileXCount) * tileSize
- tm.surface.DrawImage(tm.tilesImage.SubImage(image.Rect(sx, sy, sx+tileSize, sy+tileSize)).(*ebiten.Image), op)
+ tm.surfaces[idx].DrawImage(tm.tilesImage.SubImage(image.Rect(sx, sy, sx+tileSize, sy+tileSize)).(*ebiten.Image), op)
}
}
@@ -60,8 +66,6 @@ func NewTilemap(layers [][]int, mapWidth int) Tilemap {
tilemap.layers = layers
- tilemap.surface = ebiten.NewImage(mapWidth*tilemap.tileSize, len(layers[0])/mapWidth*tilemap.tileSize)
-
var err error
tilemap.tilesImage = tilesImage