Vlue

Multiple Map Layers

Sep 18th, 2013
1,975
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Multiple Map Layers v1.1
  2. #----------#
  3. #Features: Let's you layer one or two maps on top of another! Even if they have
  4. #           like different tilesets! Which is the point.
  5. #
  6. #Usage:   Just put <LAYER# #> in the note box of the base map, where the first
  7. #          # is the layer #, and the second # is the map to squish on.
  8. #
  9. #         New Features:
  10. #          show_layer(id)   - will show that layer
  11. #          hide_layer(id)   - will hide that layer
  12. #
  13. #          Placing <L#> (where # is the number of the layer) in the name of event
  14. #          will tie that event to that layer, which means it will only be active
  15. #          and visible when that layer is.
  16. #
  17. #         As a general rule, all layered maps should be the same size as the base map, or things will happen.
  18. #
  19. #Examples:
  20. #     <LAYER5 54>
  21. #     <LAYER78 2>
  22. #
  23. #----------#
  24. #-- Script by: V.M of D.T
  25. #
  26. #- Questions or comments can be:
  27. #    given by email: sumptuaryspade@live.ca
  28. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  29. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  30. #
  31. #--- Free to use in any project, commercial or non-commercial, with credit given
  32. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  33.  
  34. class Game_Map
  35.   attr_accessor   :maps
  36.   alias mm_setup setup
  37.   def setup(map_id)
  38.     @maps = {}
  39.     mm_setup(map_id)
  40.     note = @map.note.clone
  41.     while note.include?("<LAYER")
  42.       /<LAYER(?<id>\d{1,3}) (?<cond>\d{1,3})>/ =~ note
  43.       @maps[$1.to_i] = load_data(sprintf("Data/Map%03d.rvdata2", $2.to_i))
  44.       @maps[$1.to_i].active = true
  45.       note[note.index("<LAYER")] = "&"
  46.     end
  47.   end
  48.   def layer(id)
  49.     return false if @maps[id].nil?
  50.     return @maps[id]
  51.   end
  52.   def check_passage(x, y, bit)
  53.     passable = false
  54.     all_tiles(x, y, 0).each do |tile_id|
  55.       flag = tileset.flags[tile_id]
  56.       next if flag & 0x10 != 0            # [☆]: No effect on passage
  57.       break passable = true if flag & bit == 0     # [○] : Passable
  58.       return false if flag & bit == bit   # [×] : Impassable
  59.     end
  60.     @maps.each do |id,map|
  61.       next unless map.active
  62.       all_tiles(x, y, id).each do |tile_id|
  63.         flag = $data_tilesets[layer(id).tileset_id].flags[tile_id]
  64.         next if flag & 0x10 != 0            # [☆]: No effect on passage
  65.         break passable = true if flag & bit == 0     # [○] : Passable
  66.         return false if flag & bit == bit   # [×] : Impassable
  67.       end
  68.     end
  69.     return true if passable
  70.     return false                          # Impassable
  71.   end
  72.   def all_tiles(x,y,id = 0)
  73.     tile_events_xy(x, y).collect {|ev| ev.tile_id } + layered_tiles(x, y, id)
  74.   end
  75.   def layered_tiles(x,y, id = 0)
  76.     [2, 1, 0].collect {|z| tile_id(x, y, z, id) }
  77.   end
  78.   def tile_id(x,y,z, id = 0)
  79.     return @map.data[x,y,z] || 0 if id == 0
  80.     @maps[id].data[x,y,z] || 0
  81.   end
  82.   def hide_layer(id)
  83.     @maps[id].active = false if @maps[id]
  84.     refresh
  85.   end
  86.   def show_layer(id)
  87.     @maps[id].active = true if @maps[id]
  88.     refresh
  89.   end
  90. end
  91.  
  92. class Game_Player
  93.   def perform_transfer
  94.     if transfer?
  95.       set_direction(@new_direction)
  96.       if @new_map_id != $game_map.map_id
  97.         $game_map.setup(@new_map_id)
  98.         SceneManager.scene.spriteset.load_tileset
  99.         $game_map.autoplay
  100.       end
  101.       moveto(@new_x, @new_y)
  102.       clear_transfer_info
  103.     end
  104.   end
  105. end
  106.  
  107. class Game_Event
  108.   alias mml_conditions_met? conditions_met?
  109.   def conditions_met?(page)
  110.     return false if layer && $game_map.maps[layer] && !$game_map.maps[layer].active
  111.     mml_conditions_met?(page)
  112.   end
  113.   def layer
  114.     @event.name =~ /<L(\d+)>/ ? $1.to_i : false
  115.   end
  116. end
  117.  
  118. class RPG::Map
  119.   attr_accessor :active
  120. end
  121.  
  122. class Scene_Map
  123.   attr_accessor  :spriteset
  124. end
  125.  
  126. class Spriteset_Map
  127.   alias mm_load_tileset load_tileset
  128.   alias mm_update_tilemap update_tilemap
  129.   alias mm_dispose_tilemap dispose_tilemap
  130.   def create_ex_tilemaps
  131.     $game_map.maps.each do |id,map|
  132.       @ex_tilemaps[id] = Tilemap.new(@viewport1)
  133.       @ex_tilemaps[id].map_data = $game_map.layer(id).data
  134.     end
  135.   end
  136.   def dispose_ex_tilemaps
  137.     if @ex_tilemaps
  138.       @ex_tilemaps.each do |id,tilemap|
  139.         tilemap.dispose
  140.       end
  141.     end
  142.     @ex_tilemaps = {}
  143.   end
  144.   def load_tileset
  145.     mm_load_tileset
  146.     dispose_ex_tilemaps
  147.     create_ex_tilemaps
  148.     @ex_tilesets = {}
  149.     @ex_tilemaps.each do |id,tilemap|
  150.       @ex_tilesets[id] = $data_tilesets[$game_map.layer(id).tileset_id]
  151.       @ex_tilesets[id].tileset_names.each_with_index do |name, i|
  152.         tilemap.bitmaps[i] = Cache.tileset(name)
  153.       end
  154.       tilemap.flags = @ex_tilesets[id].flags
  155.     end
  156.   end
  157.   def dispose_tilemap
  158.     mm_dispose_tilemap
  159.     dispose_ex_tilemaps
  160.   end
  161.   def update_tilemap
  162.     mm_update_tilemap
  163.     @ex_tilemaps.each do |id,tilemap|
  164.       tilemap.visible = $game_map.maps[id].active
  165.       tilemap.map_data = $game_map.layer(id).data
  166.       tilemap.ox = $game_map.display_x * 32
  167.       tilemap.oy = $game_map.display_y * 32
  168.       tilemap.update
  169.     end
  170.   end
  171. end
  172.  
  173. class Game_Interpreter
  174.   def hide_layer(id)
  175.     $game_map.hide_layer(id)
  176.   end
  177.   def show_layer(id)
  178.     $game_map.show_layer(id)
  179.   end
  180. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×