So I'm making an isometric RTS and so far, I've got the terrain set up only.
I'm using spriteBatch for the tiles and I update the spriteBatch only when I update the terrain (The white and blue are placed via mouse buttons) so the terrain is editable. I'm pretty happy with it actually. The white border is the chunk. Currently this chunk is surrounded by 8 more in every isometric direction. I would later expands this so the map is something like 256x256 chunks but only draw 9 at a time (or more if the user has a bigger resolution). So there's 4096 tiles in one chunk and total of 36864 drawn on screen. Now, I want to make 2 more tables.
So terrain information is stored in terrain_chunk (a 2D array or table). Now I would make object_chunk and entity_chunk.
Object_chunk will hold the buildings and environment (trees, bushes etc) but it isn't as simple as terrain chunk.
I'd need to hold several things, location in the grid (localX, localY), the image of the object and the depth of it.
Then, in the love.draw (I guess?) I would sort the table by depth and draw them in that order.
Would all of this fit in one table? Or would I have several?
It all sounds good, but in practice I have no idea where to start from.
I have found a way to sort the table by value or keys on stackoverflow:
Code: Select all
function spairs(t, order)
-- collect the keys
local keys = {}
for k in pairs(t) do keys[#keys+1] = k end
-- if order function given, sort by it by passing the table and keys a, b,
-- otherwise just sort the keys
if order then
table.sort(keys, function(a,b) return order(t, a, b) end)
else
table.sort(keys)
end
-- return the iterator function
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
Code: Select all
HighScore = { Robin = 8, Jon = 10, Max = 11 }
-- basic usage, just sort by the keys
for k,v in spairs(HighScore) do
print(k,v)
end
--> Jon 10
--> Max 11
--> Robin 8
-- this uses an custom sorting function ordering by score descending
for k,v in spairs(HighScore, function(t,a,b) return t[b] < t[a] end) do
print(k,v)
end
--> Max 11
--> Jon 10
--> Robin 8
And I'm wondering if I could change the entries of the table to the image name. Something like this:
Code: Select all
image_name1 = love.graphics.newImage( filename, flags )
image_name2 = love.graphics.newImage( filename1, flags )
ObjectData = {image_name1 = 1, image_name2 = 3, image_name = depth}
Any ideas how would I approach this?
EDIT: I think I can store all the info I need in a 3D table, but should I? Or should I just store it in several tables?