summaryrefslogtreecommitdiff
path: root/common/chunk.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-01-27 13:43:49 +0000
committerubq323 <ubq323@ubq323.website>2023-01-27 13:46:41 +0000
commitd0916d568a00f5171b96fbc3bfc19ff263affc27 (patch)
treeef007be582d2b872ff2ac407def9d0ad64e3bc86 /common/chunk.lua
parent0eab09311f6634aefe0e79ecafd975ab68b2812c (diff)
coords, hexagons, drawing, chunks
Diffstat (limited to 'common/chunk.lua')
-rw-r--r--common/chunk.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/common/chunk.lua b/common/chunk.lua
new file mode 100644
index 0000000..38cdaf0
--- /dev/null
+++ b/common/chunk.lua
@@ -0,0 +1,30 @@
+local CHUNK_SIZE = 128
+
+-- for now tiles shall be booleans
+
+local function index(offq,offr)
+ -- indexes start at 0
+ -- and go up to (CHUNK_SIZE^2)-1
+ assert(0<=offq and 0<=offr and offq<CHUNK_SIZE and offr<CHUNK_SIZE, "chunk hex offset out of bounds")
+ return CHUNK_SIZE*offq + offr
+end
+
+local Chunk = {}
+Chunk.__index = Chunk
+function Chunk.make()
+ -- todo actual worldgen
+ local tiles = {}
+ for i=0,CHUNK_SIZE-1 do
+ for j=0,CHUNK_SIZE-1 do
+ tiles[index(i,j)] = (math.random()<0.5)
+ end
+ end
+
+ return setmetatable({tiles=tiles},Chunk)
+end
+
+return {
+ Chunk=Chunk,
+ SIZE=CHUNK_SIZE,
+ index=index
+}