diff options
Diffstat (limited to 'chunk.rhm')
-rw-r--r-- | chunk.rhm | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/chunk.rhm b/chunk.rhm new file mode 100644 index 0000000..3ded42d --- /dev/null +++ b/chunk.rhm @@ -0,0 +1,58 @@ +#lang rhombus/static + +export: + Direction + TileType + Tile + Chunk + flip_block + +enum Direction: + north + north_east + east + south_east + south + south_west + west + north_west + +enum TileType: + empty + wall_north + +fun flip_block(block :: maybe(Direction)) :: maybe(Direction): + match block + | Direction.north: Direction.south + | Direction.north_east: Direction.south_west + | Direction.east: Direction.west + | Direction.south_east: Direction.north_west + | Direction.south: Direction.north + | Direction.south_west: Direction.north_east + | Direction.west: Direction.east + | Direction.north_west: Direction.south_east + | ~else: #false + +class Tile(type :: TileType): + method get_block() :: maybe(Direction): + match type + | TileType.empty: #false + | TileType.wall_north: Direction.north + +class Chunk(width :: Int, + height :: Int, + offset_x :: Int, + offset_y :: Int, + tiles :: Array.now_of(Tile), + neighbours :: MutableMap.now_of(Direction, Chunk)): + constructor(width :: Int, height :: Int, offset_x :: Int, offset_y :: Int): + super(width, height, offset_x, offset_y, Array.make(width * height, Tile(TileType.empty)), MutableMap()) + + method add_neighbour(chunk :: Chunk, direction :: Direction): + neighbours[direction] := chunk + + method get_tile(x :: Int, y :: Int) :: Tile: + tiles[y * width + x] + + method set_tile(x :: Int, y :: Int, tile :: Tile): + tiles[y * width + x] := tile |