polectron

SetMapTile

May 19th, 2020 (edited)
1,668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.37 KB | None | 0 0
  1. class MapTemplate
  2.   attr_accessor :id
  3.   attr_accessor :width
  4.   attr_accessor :height
  5.   attr_accessor :map
  6.  
  7.   def initialize(id, width, height)
  8.     @id = id
  9.     @width = width
  10.     @height = height
  11.     readTemplate()
  12.   end
  13.  
  14.   def readTemplate()
  15.     @map = load_data(sprintf("Data/Map%03d.rxdata",@id))
  16.   end
  17. end
  18.  
  19. #Fusiona los arrays de dos mapas
  20. def mergeMapArrays(a, b, x, y)
  21.   tp = b.map
  22.   x_limit = b.width
  23.   y_limit = b.height
  24.  
  25.   for j in y..y_limit+y
  26.     for k in x..x_limit+x
  27.       for l in 0..2
  28.         begin
  29.           if tp.data[k-x,j-y,l] != 0  && tp.data[k-x,j-y,l] != nil
  30.             a.data[k,j,l] = tp.data[k-x,j-y,l]
  31.           end
  32.         rescue => exception
  33.           #p exception
  34.         end
  35.       end
  36.     end
  37.   end
  38.  
  39.   #return a
  40.  
  41. end
  42.  
  43. #Coloca permanentemente una plantilla en un mapa con origen en las coordenadas x,y
  44. def placeOnMap(template, x, y, mapid)
  45.   map_info = load_data(sprintf("Data/Map%03d.rxdata",mapid))
  46.   mergeMapArrays(map_info, template, x, y)
  47.   save_data(map_info, sprintf("Data/Map%03d.rxdata", mapid))
  48. end
  49.  
  50. #Cambiar temporalmente el tile situado en las coordenadas x,y,z en el mapa actual
  51. def setMapTile(id, x,y,z)
  52.   $game_map.map.data[x,y,z] = id
  53.   $game_map.refresh
  54. end
  55.  
  56. #Ejemplo de como colocar una plantilla en un mapa
  57. def placeTest()
  58.   t = MapTemplate.new(4, 8, 4)
  59.   placeOnMap(t, 3, 4, 2)
  60. end
Add Comment
Please, Sign In to add comment