last_light/game/world/map.go

80 lines
1.4 KiB
Go
Raw Normal View History

2024-05-06 18:59:14 +03:00
package world
import (
2024-05-06 21:19:08 +03:00
"mvvasilev/last_light/engine"
)
type Map interface {
2024-05-06 21:19:08 +03:00
Size() engine.Size
2024-05-12 23:22:39 +03:00
SetTileAt(x, y int, t Tile) Tile
TileAt(x, y int) Tile
2024-05-06 18:59:14 +03:00
Tick(dt int64)
}
type WithPlayerSpawnPoint interface {
2024-05-06 21:19:08 +03:00
PlayerSpawnPoint() engine.Position
2024-05-06 18:59:14 +03:00
}
type WithRooms interface {
2024-05-06 21:19:08 +03:00
Rooms() []engine.BoundingBox
2024-05-12 23:22:39 +03:00
}
type WithNextLevelStaircasePosition interface {
NextLevelStaircasePosition() engine.Position
}
type WithPreviousLevelStaircasePosition interface {
PreviousLevelStaircasePosition() engine.Position
}
2024-05-03 13:46:32 +03:00
type BasicMap struct {
tiles [][]Tile
}
func CreateBasicMap(tiles [][]Tile) *BasicMap {
bm := new(BasicMap)
bm.tiles = tiles
return bm
}
func (bm *BasicMap) Tick() {
}
2024-05-06 21:19:08 +03:00
func (bm *BasicMap) Size() engine.Size {
return engine.SizeOf(len(bm.tiles[0]), len(bm.tiles))
2024-05-03 13:46:32 +03:00
}
2024-05-12 23:22:39 +03:00
func (bm *BasicMap) SetTileAt(x int, y int, t Tile) Tile {
2024-05-03 13:46:32 +03:00
if len(bm.tiles) <= y || len(bm.tiles[0]) <= x {
2024-05-12 23:22:39 +03:00
return CreateStaticTile(x, y, TileTypeVoid())
2024-05-03 13:46:32 +03:00
}
if x < 0 || y < 0 {
2024-05-12 23:22:39 +03:00
return CreateStaticTile(x, y, TileTypeVoid())
2024-05-03 13:46:32 +03:00
}
bm.tiles[y][x] = t
2024-05-12 23:22:39 +03:00
return bm.tiles[y][x]
2024-05-03 13:46:32 +03:00
}
func (bm *BasicMap) TileAt(x int, y int) Tile {
if x < 0 || y < 0 {
return CreateStaticTile(x, y, TileTypeVoid())
}
if x >= bm.Size().Width() || y >= bm.Size().Height() {
return CreateStaticTile(x, y, TileTypeVoid())
}
tile := bm.tiles[y][x]
if tile == nil {
return CreateStaticTile(x, y, TileTypeVoid())
}
return tile
}