Posted 04 February 2015 - 03:16 PM
Hi guys,
I have a question:
I am making a game and I am a little stuck. I have a map renderer program, as well as a random map generator, Everytime you move the map will redraw the map and your position. The thing is if a map doesn't exist for the sector you are in then it will generate one (to make the world endless); which means everytime I move on a generated world, it will re-generate the map and then draw it, meaning that the map will always change everytime you press a key. Please help :(/>
Here is the main game function:
Here is the game's map renderer:
and here is the game's map generator (I have deleted the content in the itemset1 as this is just to add the content in to the map and it is huge like 70 lines, so I have taken it out due to space):
Thanks in advance
I have a question:
I am making a game and I am a little stuck. I have a map renderer program, as well as a random map generator, Everytime you move the map will redraw the map and your position. The thing is if a map doesn't exist for the sector you are in then it will generate one (to make the world endless); which means everytime I move on a generated world, it will re-generate the map and then draw it, meaning that the map will always change everytime you press a key. Please help :(/>
Here is the main game function:
function game.start()
if not player.pos.current then
player.pos.current = "space1x1"
end
game.drawstats()
game.drawmap(player.pos.current)
game.drawplayer()
while true do
local args = { os.pullEvent() }
game.input(args[1], args[2], args[3], args[4], args[5])
game.drawstats()
game.drawmap(player.pos.current)
game.drawplayer()
end
end
Here is the game's map renderer:
function game.drawmap(name)
col.set("white", "black")
name = name
if fs.exists("/data/maps/"..name..".lua") == false then
map = game.worldgen(name)
else
local map1 = fs.open("/data/maps/"..name..".lua", "r")
map = textutils.unserialize(map1.readAll())
end
intx = 2
inty = 2
for k1, v1 in ipairs(map) do
for k2, v2 in ipairs(map[k1]) do
term.setCursorPos(k2, k1)
write(v2)
end
end
end
and here is the game's map generator (I have deleted the content in the itemset1 as this is just to add the content in to the map and it is huge like 70 lines, so I have taken it out due to space):
function game.worldgen(name)
itemset1 = {}
key = 1
world = {{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},}
for i = 1, 19 do
for j = 1, 35 do
local ran = math.floor(math.random(1000))
table.insert(world[key], itemset1[ran])
end
key = key + 1
end
return world
end
Thanks in advance