Advertisement
jdroid91

Untitled

Jan 20th, 2025
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. local dinoB_amount = 15
  2. local tiles
  3. local filled_tiles = {}
  4.  
  5. function init(self)
  6.     tiles = tilemap.get_tiles("main:/tilemap#level2maplevel", "floor")
  7.     math.randomseed(os.time())
  8.  
  9.     for i = 1, dinoB_amount do
  10.         local x_pos, y_pos, tile
  11.         -- loops till valid tile
  12.         repeat
  13.             x_pos = math.random(1,200)
  14.             y_pos = math.random(1,200)
  15.             tile = tiles[x_pos][y_pos]
  16.         until tile == 120 and is_tile_empty(x_pos, y_pos)
  17.  
  18.         mark_tile_filled(x_pos, y_pos) -- marks the tile as a full tile so that two wont spawn
  19.  
  20.         local tile_size = 16
  21.         local tilemap_origin = go.get_position("main:/level2maplevel")
  22.  
  23.         local dino_pos = vmath.vector3(
  24.         tilemap_origin.x + (y_pos - 0.5) * tile_size,
  25.         tilemap_origin.y + (x_pos - 0.5) * tile_size,
  26.         tilemap_origin.z
  27.     )
  28.  
  29.     factory.create("factory", dino_pos, nil, {}, 1.5 ) -- spawns the dino
  30.    
  31.     end
  32. end
  33.  
  34. function is_tile_empty(x,y)
  35.     return not (filled_tiles[x] and filled_tiles[x][y])
  36. end
  37.  
  38. function mark_tile_filled(x,y)
  39.     if not filled_tiles[x] then
  40.         filled_tiles[x] = {}
  41.     end
  42.     filled_tiles[x][y] = true
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement