World.script
require("main.hex")
go.property("TILESIZE", 35)
function init(self)
-- Add initialization code here
-- Remove this function if not needed
self.width = 30
self.height = 15
self.tiles = {}
for q = 1, self.width do
self.tiles[q] = {}
for r = 1, self.height do
local h = Hex(q, r)
local pix = hexToPixel(h, go.get("#", "TILESIZE"))
local tile_pos = vmath.vector3(pix.x, pix.y, -q*.001-r*.001)
--local newtile = collectionfactory.create("#tiles_factory", tile_pos, nil, {}, 1)
local newtile = factory.create("#tiles_factory1", tile_pos, nil, {}, 1)
self.tiles[q][r] = newtile
pprint(newtile)
pprint(msg.url(newtile))
pprint(go.get(msg.url(newtile), "tiletype"))
end
end
print("World built")
end
tile.script (from tile.go, prototype of tiles factory)
go.property("tiletype", hash("grass"))
go.property("passable", true)
function init(self)
local rng = math.random()
if rng > .7 then
go.set("#", "tiletype", hash("water"))
end
if self.type == hash("water") then
msg.post("#sprite", "play_animation", {id = hash("tileWater_full")})
go.set("#", "passable", false)
else
msg.post("#sprite", "play_animation", {id = hash("tileGrass_full")})
end
end