diff options
Diffstat (limited to 'go/ui/map.go')
| -rw-r--r-- | go/ui/map.go | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/go/ui/map.go b/go/ui/map.go deleted file mode 100644 index 2e83ad2d..00000000 --- a/go/ui/map.go +++ /dev/null @@ -1,109 +0,0 @@ -package ui - -import ( - "log" - "math" - - "github.com/hajimehoshi/ebiten/v2" - "muhq.space/muhqs-game/go/assets" - "muhq.space/muhqs-game/go/game" -) - -const ( - TILE_WIDTH int = 50 - TILE_HEIGHT int = 50 -) - -type MapLayer struct { - m *game.Map - img *ebiten.Image -} - -func NewMapLayerFromMap(m *game.Map) *MapLayer { - mv := MapLayer{m, nil} - return &mv -} - -func rotateStreetImg(x, y int, radian float64, op *ebiten.DrawImageOptions) { - // Move the image's center to the screen's upper-left corner. - // This is a preparation for rotating. When geometry matrices are applied, - // the origin point is the upper-left corner. - op.GeoM.Translate(-float64(TILE_WIDTH)/2, -float64(TILE_HEIGHT)/2) - - // Rotate the image. As a result, the anchor point of this rotate is - // the center of the image. - op.GeoM.Rotate(radian) - - // Reset translation - op.GeoM.Translate(float64(TILE_WIDTH)/2, float64(TILE_HEIGHT)/2) -} - -func (m *MapLayer) rotateStreet(x, y int, op *ebiten.DrawImageOptions) { - connections, left, right, above, below := m.m.FindStreetConnections(x, y) - - if connections == 0 { - // This street is not connected to another street -> - // check any other non neutral tiles - connections, left, right, above, below = m.m.FindAnyConnections(x, y) - } - - // This street is not connected to anything. Seams odd! - if connections == 0 { - log.Printf("Street at (%d, %d) is not connected", x, y) - } else if (connections == 1 || - (connections == 2 && ((left && right) || (above && below)))) && - (above || below) { - rotateStreetImg(x, y, math.Pi/2, op) - } else if connections == 2 { - // normal orientation above and right - if right && below { - rotateStreetImg(x, y, 3*math.Pi/2, op) - } else if left && below { - rotateStreetImg(x, y, math.Pi, op) - } else if above && left { - rotateStreetImg(x, y, math.Pi/2, op) - } - } else if connections == 3 { - // normal orientation left above right - if above && right && below { - rotateStreetImg(x, y, 3*math.Pi/2, op) - } else if left && below && right { - rotateStreetImg(x, y, math.Pi, op) - } else if below && left && above { - rotateStreetImg(x, y, math.Pi/2, op) - } - } -} - -func (m *MapLayer) Draw(screen *ebiten.Image) { - if m.img == nil { - // TODO: support non symetric maps - maxWidth := len(m.m.Tiles[0]) * TILE_WIDTH - maxHeight := len(m.m.Tiles) * TILE_HEIGHT - m.img = ebiten.NewImage(maxWidth, maxHeight) - - x_px, y_px := 0.0, 0.0 - for y := 0; y < len(m.m.Tiles); y++ { - for x := 0; x < len(m.m.Tiles[y]); x++ { - tile := &m.m.Tiles[y][x] - tileImg := assets.GetTile(tile.Raw) - - op := &ebiten.DrawImageOptions{} - // Rotate Street - if tile.Type == game.TileTypes.Street { - m.rotateStreet(x, y, op) - } - - op.GeoM.Translate(x_px, y_px) - - m.img.DrawImage(tileImg, op) - - x_px += float64(TILE_WIDTH) - } - x_px = 0 - y_px += float64(TILE_HEIGHT) - } - } - - screen.DrawImage(m.img, &ebiten.DrawImageOptions{}) -} |
