Guest User

Untitled

a guest
Jun 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. function Monster:fov()
  2.     local x, y
  3.     self.visible_tiles = {}
  4.    
  5.     for i = 1, self.current_dungeon.size.w do
  6.         self.visible_tiles[i] = {}
  7.         for j = 1, self.current_dungeon.size.h do
  8.             self.visible_tiles[i][j] = 0
  9.         end
  10.     end
  11.    
  12.     for i = 0, 360 do
  13.         x = math.cos(i * 0.01745)
  14.         y = math.sin(i * 0.01745)
  15.         self:do_fov(x, y)
  16.     end
  17. end
  18.  
  19. function Monster:do_fov(x, y)
  20.     local ox, oy
  21.     ox = self.pos.x + 0.5
  22.     oy = self.pos.y + 0.5
  23.    
  24.     for i = 0, self.view_radius do
  25.         self.visible_tiles[math.ceil(ox)][math.ceil(oy)] = self.view_radius - (i * 1.7)
  26.        
  27.         if self.visible_tiles[math.ceil(ox)][math.ceil(oy)] <= 0 then
  28.             self.visible_tiles[math.ceil(ox)][math.ceil(oy)] = 0
  29.         end
  30.    
  31.         if self.current_dungeon.tiles[math.ceil(ox)][math.ceil(oy)].solid then
  32.             return
  33.         end
  34.        
  35.         ox = ox + x
  36.         oy = oy + y
  37.     end
  38. end
Add Comment
Please, Sign In to add comment