you made my day with your tutorial (https://github.com/kikito/love-tile-tutorial) about tiles maps with löve
i strongly appreciate the way you load map stored in a string so i dived a little into the code and i have now a minimal tech demo to share. it support tabbing the strings so it's a little cleaner but all credits goes to you
try the .love at the bottom ; press tab to convert cells
here is the code :
Code: Select all
function love.load()
gr = love.graphics
gr.setFont(gr.newFont(32))
local map_string = [[
#####
##.b.######
#....+e...#
#o...#....#
#....#...##
#.@..###y#
#....# ###
######
]]
map = map_load(map_string)
end
function love.draw()
map_print(map)
end
function map_load(map_string)
-- init local map and row/column counters
local map, gx, gy = {}, 1, 1
-- for each line readed
for this_line in map_string:gmatch("[^\t\n]+") do
-- restart the column counter
gx = 1
-- fill map with empty rows
map[gy] = {}
-- for each char
for this_char in this_line:gmatch(".") do
-- store it in map
map[gy][gx] = this_char
-- go to next table column
gx = gx + 1
end
-- go to next table row
gy = gy + 1
end
return map
end
function map_print(map)
-- for each row
for gy in ipairs(map) do
-- for each column
for gx, v in ipairs(map[gy]) do
-- if tab is pressed, convert
if love.keyboard.isDown("tab") then
v =
v == "." and 0 or
v == "#" and 1 or
v == "+" and -7 or
v == "@" and 42 or
v == "o" and 4 or
v == "b" and 5 or
v == "e" and 6 or
v == "y" and 7 or v
end
-- print map
gr.print(v, gx * 0x40, gy * 0x40)
end
end
end
my isömaps are so clean now !
see that !
Code: Select all
return { [[
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
]], [[
..................
..................
..................
..................
..................
..................
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
..................
..................
..................
..................
..................
]], [[
..................
..................
..................
..................
..................
..................
~~~~$$~~~~~~~$$~~~
~~~~$$~~~~~~~$$~~~
~~~~$$~~~~~~~$$~~~
~~~~$$~~~~~~~$$~~~
..................
..................
..................
..................
..................
]], [[
###############_##
______________#_#.
__________________
__$________$______
__________________
__________________
__________________
__________________
__________________
__________________
__________________
__________________
__$________$______
__________________
__________________
]], [[
###############_##
______________#_#_
__________________
__$________$______
__________________
__________________
__________________
__________________
__________________
__________________
__________________
__________________
__$________$______
__________________
__________________
]], [[
##################
______________###_
__________________
__$________$______
__________________
__________________
__________________
__________________
__________________
__________________
__________________
__________________
__$________$______
__________________
__________________
]], [[
##################
__________________
__%________%______
_%$%______%$%_____
__%________%______
__________________
__________________
__________________
__________________
__________________
__________________
__%________%______
_%$%______%$%_____
__%________%______
__________________
]], [[
##################
__________________
_%%%______%%%_____
_%$%______%$%_____
_%%%______%%%_____
__________________
__________________
__________________
__________________
__________________
__________________
_%%%______%%%_____
_%$%______%$%_____
_%%%______%%%_____
__________________
]], [[
__________________
__________________
__%________%______
_%%%______%%%_____
__%________%______
__________________
__________________
__________________
__________________
__________________
__________________
__%________%______
_%%%______%%%_____
__%________%______
__________________
]] }