Committing the island generator script, and a bugfix

region_api.cpp had a bug, where a glue function's name was used twice. It
was an easy catch, but there was an issue in the new script, where I was
counting from 0 instead of 1. As a result, I was chasing a segfault for 5
hours.
This commit is contained in:
Kayne Ruse
2014-06-23 10:29:39 +10:00
parent f5c58bf5ad
commit 95362286f8
5 changed files with 53 additions and 9 deletions
+41
View File
@@ -1 +1,42 @@
print("Lua script check (./rsc)")
--uber lazy declarations
function square(x) return x*x end
function distance(x, y, i, j) return math.sqrt(square(x - i) + square(y - j)) end
--tile macros, mapped to the tilesheet
local base = 14
local shift = 36
plains = base + shift * 0
grass = base + shift * 1
dirt = base + shift * 2
sand = base + shift * 3
water = base + shift * 4
--Overwrite the original OnCreate with my own version
Region.hcOnCreate = Region.OnCreate
Region.OnCreate = function(region)
local ret = Region.hcOnCreate(region) --best practices
for i = 1, Region.GetWidth() do
for j = 1, Region.GetHeight() do
if distance(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) > 10 then
Region.SetTile(region, i, j, 1, water)
else
Region.SetTile(region, i, j, 1, plains)
end
end
end
return ret
end
--Get some regions
newRoom = RoomMgr.CreateRoom("overworld")
pager = Room.GetPager(newRoom)
regionTable = {
RegionPager.GetRegion(pager, 0, 0),
RegionPager.GetRegion(pager, 0, -20),
RegionPager.GetRegion(pager, -20, 0),
RegionPager.GetRegion(pager, -20, -20)
}
print("Finished the lua script")