Save chunks whem moving into new one
This commit is contained in:
parent
2f43a45886
commit
bfadc45f84
13
map.lua
13
map.lua
@ -35,6 +35,7 @@ water_height = 17
|
||||
function maplib.new_block(oldposx,oldposy)
|
||||
if player.playerx < 1 then
|
||||
if ore[loaded_chunks[-1][0][map_max][player.playery]["block"]]["collide"] == false then
|
||||
maplib.save_chunks()
|
||||
chunkx = chunkx - 1
|
||||
maplib.createmap() -- create a new block
|
||||
player.playerx = map_max -- put player on other side of screen
|
||||
@ -45,6 +46,7 @@ function maplib.new_block(oldposx,oldposy)
|
||||
end
|
||||
elseif player.playerx > map_max then
|
||||
if ore[loaded_chunks[1][0][1][player.playery]["block"]]["collide"] == false then
|
||||
maplib.save_chunks()
|
||||
chunkx = chunkx + 1
|
||||
maplib.createmap() -- create a new block
|
||||
player.playerx = 1 -- put player on other side of screen
|
||||
@ -56,6 +58,7 @@ function maplib.new_block(oldposx,oldposy)
|
||||
|
||||
elseif player.playery < 1 then
|
||||
if ore[loaded_chunks[0][1][player.playerx][map_max]["block"]]["collide"] == false then
|
||||
maplib.save_chunks()
|
||||
chunky = chunky + 1
|
||||
maplib.createmap() -- create a new block
|
||||
player.playery = map_max -- put player on other side of screen
|
||||
@ -66,6 +69,7 @@ function maplib.new_block(oldposx,oldposy)
|
||||
end
|
||||
elseif player.playery > map_max then
|
||||
if ore[loaded_chunks[0][-1][player.playerx][1]["block"]]["collide"] == false then
|
||||
maplib.save_chunks()
|
||||
chunky = chunky - 1
|
||||
maplib.createmap() -- create a new block
|
||||
player.playery = 1 -- put player on other side of screen
|
||||
@ -78,6 +82,15 @@ function maplib.new_block(oldposx,oldposy)
|
||||
|
||||
return true
|
||||
end
|
||||
--saves all memory data into file
|
||||
function maplib.save_chunks()
|
||||
for xx = -max_chunks,max_chunks do
|
||||
for yy = -max_chunks,max_chunks do
|
||||
love.filesystem.write( "/map/"..chunkx+xx.."_"..chunky+yy..".txt", TSerial.pack(loaded_chunks[xx][yy]))
|
||||
print("saving:"..chunkx+xx.."_"..chunky+yy)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--generates ore
|
||||
function maplib.generate_ore(tiles)
|
||||
|
2
ore.lua
2
ore.lua
@ -4,7 +4,7 @@ ore = {
|
||||
{name = "rock", image = "stone.png"}, --id 2
|
||||
{name = "dirt", image = "dirt.png"}, --id 3
|
||||
{name = "grass", image = "grass.png"}, --id 4
|
||||
{name = "water", image = "water.png", prop = "liquid", collide = false,float = true},
|
||||
{name = "water", image = "water.png", prop = "liquid", collide = false,water = true},
|
||||
|
||||
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ function mine(key)
|
||||
loaded_chunks[selected_chunkx][selected_chunky][mx][my]["block"] = player.selected
|
||||
player.mining = false
|
||||
love.filesystem.write( "/map/"..chunkx+selected_chunkx.."_"..chunky+selected_chunky..".txt", TSerial.pack(loaded_chunks[selected_chunkx][selected_chunky]))
|
||||
score = score + 1
|
||||
score = score + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user