Load map from required LUA file.
Posted: Mon Jan 21, 2013 10:27 pm
So I've been following the grid-locked player tutorial, and it teaches how to create a map within main.lua, like so:
However, to keep it clean I would like to have the maps stored in other, required lua files. So for example I have:
Where "level_map" would be the table within the dungeon1.lua file. But when I pass that along to the draw stage:
I get that the value is nil, how would I go about doing this?
Thanks!
Avery
Code: Select all
function love.load()
-- Define the map used.
map = {
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
}
end
Code: Select all
require("maps/dungeon1");
function love.load()
map = level_map
end
Code: Select all
function love.draw()
-- Render the map.
for y=1, #map do
for x=1, #map[y] do
-- Check space and render suitable tile.
if map[y][x] == 1 then
love.graphics.draw(tile_brick, x * 32, y * 32)
end
if map[y][x] == 0 then
love.graphics.draw(tile_cobble, x * 32, y * 32)
end
end
end
end
Thanks!
Avery