forked from erle/xmaps
Encode map in treasure map style
This commit is contained in:
parent
f47d59fc4a
commit
70e3c534e4
71
init.lua
71
init.lua
|
@ -77,18 +77,10 @@ maps.create_map = function(pos, player_name)
|
|||
|
||||
local pixels = {}
|
||||
local colormap = {
|
||||
{ 0, 0, 0 },
|
||||
{ 0, 0, 255 }, -- water
|
||||
{ 255, 127, 0 }, -- lava
|
||||
{ 127, 127, 127 }, -- cracky
|
||||
{ 175, 175, 175 }, -- crumbly
|
||||
{ 47, 47, 47 }, -- stone
|
||||
{ 127, 47, 47 }, -- soil
|
||||
{ 0, 255, 0 }, -- grass
|
||||
{ 255, 255, 0 }, -- sand
|
||||
{ 255, 255, 255 }, -- snow
|
||||
{ 0, 47, 0 }, -- leaves
|
||||
{ 255, 0, 0 }, -- fire
|
||||
{ 195, 175, 140 }, -- background
|
||||
{ 60, 35, 16 }, -- dark line
|
||||
{ 135, 90, 40 }, -- liquid dark
|
||||
{ 210, 170, 130 }, -- liquid light
|
||||
}
|
||||
for x = 1,size,1 do
|
||||
for z = 1,size,1 do
|
||||
|
@ -98,25 +90,44 @@ maps.create_map = function(pos, player_name)
|
|||
end
|
||||
end
|
||||
|
||||
local color_map = function(color, query)
|
||||
local positions = minetest.find_nodes_in_area_under_air(minp, maxp, query)
|
||||
for _, p in ipairs(positions) do
|
||||
local z = p.z - minp.z + 1
|
||||
local x = p.x - minp.x + 1
|
||||
pixels[z][x] = { color }
|
||||
local positions = minetest.find_nodes_in_area_under_air(
|
||||
minp,
|
||||
maxp,
|
||||
"group:liquid"
|
||||
)
|
||||
for _, p in ipairs(positions) do
|
||||
local z = p.z - minp.z + 1
|
||||
local x = p.x - minp.x + 1
|
||||
pixels[z][x] = { 2 }
|
||||
end
|
||||
|
||||
-- draw coastline
|
||||
for x = 1,size,1 do
|
||||
for z = 1,size,1 do
|
||||
if (
|
||||
pixels[z][x][1] == 2 or
|
||||
pixels[z][x][1] == 3
|
||||
) then
|
||||
pixels[z][x] = { 2 + z % 2 } -- stripes
|
||||
if z > 1 and pixels[z-1][x][1] < 2 then
|
||||
pixels[z-1][x] = { 1 }
|
||||
pixels[z][x] = { 2 }
|
||||
end
|
||||
if z < size and pixels[z+1][x][1] < 2 then
|
||||
pixels[z+1][x] = { 1 }
|
||||
pixels[z][x] = { 2 }
|
||||
end
|
||||
if x > 1 and pixels[z][x-1][1] < 2 then
|
||||
pixels[z][x-1] = { 1 }
|
||||
pixels[z][x] = { 2 }
|
||||
end
|
||||
if x < size and pixels[z][x+1][1] < 2 then
|
||||
pixels[z][x+1] = { 1 }
|
||||
pixels[z][x] = { 2 }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
color_map( 1, "group:water")
|
||||
color_map( 2, "group:lava")
|
||||
color_map( 3, "group:cracky")
|
||||
color_map( 4, "group:crumbly")
|
||||
color_map( 5, "group:stone")
|
||||
color_map( 6, "group:soil")
|
||||
color_map( 7, "group:spreading_dirt_type")
|
||||
color_map( 8, "group:sand")
|
||||
color_map( 9, "group:snowy")
|
||||
color_map(10, "group:leaves")
|
||||
color_map(11, "group:fire")
|
||||
|
||||
local filepath = textures_dir .. filename
|
||||
tga_encoder.image(pixels):save(
|
||||
|
@ -160,7 +171,7 @@ minetest.register_on_joinplayer(
|
|||
scale = { x = 4, y = 4 }
|
||||
}
|
||||
local dot_def = table.copy(map_def)
|
||||
dot_def.text = "player.png^[resize:4x8"
|
||||
dot_def.text = "maps_x.tga" -- "player.png^[resize:4x8"
|
||||
maps.maps[player_name] = player:hud_add(map_def)
|
||||
maps.dots[player_name] = player:hud_add(dot_def)
|
||||
maps.minp[player_name] = { x=-32000, y=0, z=0 }
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue