Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dinoB_amount = 15
- local tiles
- local filled_tiles = {}
- function init(self)
- tiles = tilemap.get_tiles("main:/tilemap#level2maplevel", "floor")
- math.randomseed(os.time())
- for i = 1, dinoB_amount do
- local x_pos, y_pos, tile
- -- loops till valid tile
- repeat
- x_pos = math.random(1,200)
- y_pos = math.random(1,200)
- tile = tiles[x_pos][y_pos]
- until tile == 120 and is_tile_empty(x_pos, y_pos)
- mark_tile_filled(x_pos, y_pos) -- marks the tile as a full tile so that two wont spawn
- local tile_size = 16
- local tilemap_origin = go.get_position("main:/level2maplevel")
- local dino_pos = vmath.vector3(
- tilemap_origin.x + (y_pos - 0.5) * tile_size,
- tilemap_origin.y + (x_pos - 0.5) * tile_size,
- tilemap_origin.z
- )
- factory.create("factory", dino_pos, nil, {}, 1.5 ) -- spawns the dino
- end
- end
- function is_tile_empty(x,y)
- return not (filled_tiles[x] and filled_tiles[x][y])
- end
- function mark_tile_filled(x,y)
- if not filled_tiles[x] then
- filled_tiles[x] = {}
- end
- filled_tiles[x][y] = true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement