From c7a2fa80e71bc36369583edd3fa09fb2bbdd2a6e Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Wed, 20 May 2020 01:43:40 +0100 Subject: [PATCH] Internalise the map rect --- internal/assetstore/map.go | 11 +++-------- internal/maps/maps.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/internal/assetstore/map.go b/internal/assetstore/map.go index 2450d08..5a3f053 100644 --- a/internal/assetstore/map.go +++ b/internal/assetstore/map.go @@ -47,12 +47,7 @@ func (a *AssetStore) Map(name string) (*Map, error) { } m := &Map{ - Rect: image.Rect( - int(raw.MinWidth), - int(raw.MinLength), - int(raw.MaxWidth), - int(raw.MaxLength), - ), + Rect: raw.Rect(), assets: a, raw: raw, set: set, @@ -65,8 +60,8 @@ func (a *AssetStore) Map(name string) (*Map, error) { func (m *Map) LoadSprites() error { // Eager load the sprites we use - for x := m.Rect.Min.X; x <= m.Rect.Max.X; x++ { - for y := m.Rect.Min.Y; y <= m.Rect.Max.Y; y++ { + for x := m.Rect.Min.X; x < m.Rect.Max.X; x++ { + for y := m.Rect.Min.Y; y < m.Rect.Max.Y; y++ { for z := 0; z < maps.MaxHeight; z++ { if _, err := m.SpritesForCell(x, y, z); err != nil { return err diff --git a/internal/maps/maps.go b/internal/maps/maps.go index 68821ff..c72a81f 100644 --- a/internal/maps/maps.go +++ b/internal/maps/maps.go @@ -5,6 +5,7 @@ import ( "compress/gzip" "encoding/binary" "fmt" + "image" "io" "io/ioutil" "log" @@ -173,6 +174,15 @@ type GameMap struct { Text string } +func (m *GameMap) Rect() image.Rectangle { + return image.Rect( + int(m.Header.MinWidth), + int(m.Header.MinLength), + int(m.Header.MaxWidth), + int(m.Header.MaxLength), + ) +} + // A game map contains a .txt and a .map. If they're in the same directory, // just pass the directory + basename to load both func LoadGameMap(prefix string) (*GameMap, error) {