summaryrefslogtreecommitdiff
path: root/common/chunk.lua
diff options
context:
space:
mode:
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
+}