summaryrefslogtreecommitdiff
path: root/common/chunk.lua
blob: 38cdaf042d31273294e55ddba932cca58ef45a2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
}