From cfc6c381aef5571891b82b5a289604c9e84adb96 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 21 Jul 2015 14:29:46 +1000 Subject: [PATCH] Cleaned up the generator; playing around --- rsc/roguegenerator.lua | 61 +++++++++++++++++++++++++++--------------- src/example_scene.cpp | 5 ++++ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/rsc/roguegenerator.lua b/rsc/roguegenerator.lua index 2526289..e9e36b5 100644 --- a/rsc/roguegenerator.lua +++ b/rsc/roguegenerator.lua @@ -13,16 +13,10 @@ This specification isn't ironclad. print("Beginning generator...") -math.randomseed(os.time()) - -roomcount = math.random(5, 10) -roomlist = {} -tunnellist = {} - -function newroom() +function newroom(northBound, eastBound, southBound, westBound) --place the room within proximity of the center, so that they're not too far apart. - local x = math.random(-30, 30) - local y = math.random(-30, 30) + local x = math.random(westBound, eastBound) + local y = math.random(northBound, southBound) local w = math.random(2, 5) local h = math.random(2, 5) @@ -68,22 +62,47 @@ function newpath(x1, y1, x2, y2) return path end +function buildpaths(roomlist) + local roomcount = #roomlist + local pathlist = {} + --tunnel the shortest paths + for i = 1, roomcount-1 do + table.insert(pathlist, newpath( + roomlist[i].seedX, + roomlist[i].seedY, + roomlist[i+1].seedX, + roomlist[i+1].seedY)) + end + + --return the new paths + return pathlist +end + print("populating lists") +math.randomseed(os.time()) + +roomlist = {} +pathlist = {} + --populate the roomlist +roomcount = math.random(10, 15) for i = 1, roomcount do - table.insert(roomlist, newroom()) + table.insert(roomlist, newroom(-30, 0, 30, -60)) --60x60 end ---tunnel the shortest paths -for i = 1, roomcount-1 do - table.insert(tunnellist, newpath( - roomlist[i].seedX, - roomlist[i].seedY, - roomlist[i+1].seedX, - roomlist[i+1].seedY)) +roomcount = math.random(10, 15) +for i = 1, roomcount do + table.insert(roomlist, newroom(-30, 50, 30, -10)) --60x60 end +roomcount = math.random(20, 30) +for i = 1, roomcount do + table.insert(roomlist, newroom(-60, 120, 60, 70)) --50x120 +end + +pathlist = buildpaths(roomlist) + --pass the data onto the pager pager = ... --called as a chunk @@ -93,19 +112,17 @@ for k, iter in next, roomlist do for i = iter.east, iter.west do for j = iter.north, iter.south do --set - local ret = region_pager.SetTile(pager, i, j, 0, 14) --- print("ret: ", ret) + region_pager.SetTile(pager, i, j, 0, 14) end end end --create the paths iter = nil -for k, path in next, tunnellist do --multiple paths in the tunnellsit +for k, path in next, pathlist do --multiple paths in the lsit for k, iter in next, path do --for each tile in the path, set - local ret = region_pager.SetTile(pager, iter.x, iter.y, 1, 50) --DEBUG: set to layer 1 --- print("ret: ", ret) + region_pager.SetTile(pager, iter.x, iter.y, 0, 14) end end diff --git a/src/example_scene.cpp b/src/example_scene.cpp index 3b45064..e6f600c 100644 --- a/src/example_scene.cpp +++ b/src/example_scene.cpp @@ -41,6 +41,11 @@ ExampleScene::ExampleScene(lua_State* L) { //run the function lua_pcall(lua, 1, LUA_MULTRET, 0); + + //DEBUG: cam jump + camera.x = -3000; + camera.y = -1500; + camera.scale = 0.25; } ExampleScene::~ExampleScene() {