SHARE
TWEET

[RGSS] Seph's Tilemap (Un-SDK, Un-MACL, bugged)

LiTTleDRAgo Jul 29th, 2013 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Tilemap (Basic)
  3. #------------------------------------------------------------------------------
  4. # SephirothSpawn
  5. # Version 1.11
  6. # 2007-07-31
  7. # Un-SDK
  8. #------------------------------------------------------------------------------
  9. # * Credits :
  10. #
  11. #   Thanks to Trickster for conversion formula for Hexidecimal to rgb.
  12. #   Thanks to trebor777 for helping with the priority bug from the 0.9 version.
  13. #------------------------------------------------------------------------------
  14. # * Version History :
  15. #
  16. #   Version 0.9 -------------------------------------------------- (??????????)
  17. #   Version 1 ---------------------------------------------------- (2007-05-30)
  18. #       Version 1.1 ------------------------------------------------- (2007-07-20)
  19. #       Version 1.11 ------------------------------------------------ (2007-07-31)
  20. #------------------------------------------------------------------------------
  21. # * Optional :
  22. #
  23. #   Method & Class Library (2.1+)
  24. #------------------------------------------------------------------------------
  25. # * Description :
  26. #
  27. #   This script was designed to re-write the default RMXP Hidden Tileset class.
  28. #   The script has added many features and a new "Tilemap Settings" class,
  29. #   that can be unique if you create mini-maps using this system.
  30. #------------------------------------------------------------------------------
  31. # * Instructions :
  32. #
  33. #   Place The Script Below the SDK and Above Main.
  34. #------------------------------------------------------------------------------
  35. # * Syntax :
  36. #
  37. #   Get Autotile Tile Bitmap
  38. #       - RPG::Cache.autotile_tile(autotile_filename, tile_id[, hue[, frame_id]])
  39. #
  40. #       autotile_filename : Filename of autotile
  41. #       tile_id : ID of tile (Found from RPG::Map.data)
  42. #       hue (Optional) : Hue for tile
  43. #       frame_id (Optional) : Frame of tile (for animated autotiles)
  44. #
  45. # * Tilemap Syntax
  46. #
  47. #   Readable Attributes :
  48. #       - layers : Array of Sprites (or Planes)
  49. #
  50. #   Readable/Writable Attributes :
  51. #       - tileset (No long required) : Bitmap for Tileset
  52. #       - tileset_name : Name of Bitmap
  53. #       - autotiles (No long required) : Array of Autotile Bitmaps
  54. #       - autotiles_name : Array of Autotile Filenames
  55. #       - map_data : 3D Table of Tile ID Data
  56. #       - flash_data : 3D Table of Tile Flash Data
  57. #                       (Should match tilemap_settings.flash_data)
  58. #       - priorities : 3D Table of Tile Priorities
  59. #       - Visible : Tilemap Visible Flag
  60. #       - ox, oy : Tilemap layer offsets
  61. #       - tilemap_settings : Unique Special Settings Object (See Below)
  62. #       - refresh_autotiles : Refresh Autotiles on frame reset flag
  63. #
  64. # * Special Tilemap Settings
  65. #
  66. #   To make special settings easier to control for your game map and any other
  67. #   special tilemap sprites you wish to create, a special class was created
  68. #   to hold these settings. For your game tilemap, a Tilemap_Settings object
  69. #   was created in $game_map ($game_map.tilemap_settings). It is advised to
  70. #   modify $game_map.tilemap_settings.flash_data instead of tilemap.flash_data.
  71. #
  72. #   Readable/Writeable Attributes :
  73. #       - map : RPG::Map (Not required, but for additions)
  74. #       - is_a_plane : Boolean whether layers are Sprites or Planes
  75. #       - tone : Tone for all layers
  76. #       - hue : Hue for all layers
  77. #       - zoom_x, zoom_y : Zoom factor for all layers
  78. #       - tilesize : Tilesize displayed on map
  79. #       - flash_data : 3D Table of flash_data
  80. #==============================================================================
  81.  
  82. #------------------------------------------------------------------------------
  83. # SDK Enabled Check
  84. #------------------------------------------------------------------------------
  85. if true
  86.  
  87. #==============================================================================
  88. # ** Tilemap_Options
  89. #==============================================================================
  90.  
  91. module Tilemap_Options
  92.   #--------------------------------------------------------------------------
  93.   # * Tilemap Options
  94.   #
  95.   #
  96.   #   Print Error Reports when not enough information set to tilemap
  97.   #     - Print_Error_Logs              = true or false
  98.   #
  99.   #   Number of autotiles to refresh at edge of viewport
  100.   #     - Viewport_Padding              = n
  101.   #
  102.   #   When maps are switch, automatically set
  103.   #   $game_map.tileset_settings.flash_data (Recommended : False unless using
  104.   #   flash_data)
  105.   #     - Autoset_Flash_data            = true or false
  106.   #
  107.   #   Duration Between Flash Data Flashes
  108.   #     - Flash_Duration                = n
  109.   #
  110.   #   Color of bitmap (Recommended to use low opacity value)
  111.   #     - Flash_Bitmap_C                = Color.new(255, 255, 255, 50)
  112.   #
  113.   #   Update Flashtiles Default Setting
  114.   #   Explanation : In the Flash Data Addition, because of lag, you may wish
  115.   #   to toggle whether flash tiles flash or not. This is the default state.
  116.   #     - Default_Update_Flashtiles = false
  117.   #--------------------------------------------------------------------------
  118.   Print_Error_Logs              = true
  119.   Autoset_Flash_data            = true
  120.   Viewport_Padding              = 2
  121.   Flash_Duration                = 40
  122.   Flash_Bitmap_C                = Color.new(255, 255, 255, 50)
  123.   Default_Update_Flashtiles = false
  124. end
  125. #==============================================================================
  126. # ** RGSS.RPG::Cache
  127. #------------------------------------------------------------------------------
  128. # These set of methods add to the RPG::Cache.
  129. #==============================================================================
  130.  
  131. #==============================================================================
  132. # ** RPG::Cache
  133. #==============================================================================
  134. module RPG::Cache
  135.   if !method_defined?(:autotile_tile)
  136.     #--------------------------------------------------------------------------
  137.     # * Auto-Tiles
  138.     #--------------------------------------------------------------------------
  139.     Autotiles = [
  140.       [[27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],
  141.        [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12]],
  142.       [[27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],
  143.        [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12]],
  144.       [[25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],
  145.        [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12]],
  146.       [[29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
  147.        [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46]],
  148.       [[25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
  149.        [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48]],
  150.       [[37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
  151.        [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8]]
  152.     ]
  153.     Animated_Autotiles_Frames = 16
  154.     #--------------------------------------------------------------------------
  155.     # * Autotile Cache
  156.     #
  157.     #   @autotile_cache = {
  158.     #     filename => { [autotile_id, frame_id, hue] => bitmap, ... },
  159.     #     ...
  160.     #    }
  161.     #--------------------------------------------------------------------------
  162.     @autotile_cache = {}
  163.     #--------------------------------------------------------------------------
  164.     # * Autotile Tile
  165.     #--------------------------------------------------------------------------
  166.     def self.autotile_tile(filename, tile_id, hue = 0, frame_id = nil)
  167.       # Gets Autotile Bitmap
  168.       autotile = self.autotile(filename)
  169.       # Configures Frame ID if not specified
  170.       if frame_id.nil?
  171.         # Animated Tiles
  172.         frames = autotile.width / 96
  173.         # Configures Animation Offset
  174.         fc = Graphics.frame_count / Animated_Autotiles_Frames
  175.         frame_id = (fc) % [frames,1].max * 96
  176.       end
  177.       # Creates list if already not created
  178.       @autotile_cache[filename] = {} unless @autotile_cache.has_key?(filename)
  179.       # Gets Key
  180.       key = [tile_id, frame_id, hue]
  181.       # If Key Not Found
  182.       unless @autotile_cache[filename].has_key?(key)
  183.         # Reconfigure Tile ID
  184.         tile_id %= 48
  185.         # Creates Bitmap
  186.         bitmap = Bitmap.new(32, 32)
  187.         # Collects Auto-Tile Tile Layout
  188.         tiles = Autotiles[tile_id / 8][tile_id % 8]
  189.         # Draws Auto-Tile Rects
  190.         for i in 0...4
  191.           tile_position = tiles[i] - 1
  192.           src_rect = Rect.new(tile_position % 6 * 16 + frame_id,
  193.             tile_position / 6 * 16, 16, 16)
  194.           bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)
  195.         end
  196.         # Saves Autotile to Cache
  197.         @autotile_cache[filename][key] = bitmap
  198.         # Change Hue
  199.         @autotile_cache[filename][key].hue_change(hue)
  200.       end
  201.       # Return Autotile
  202.       return @autotile_cache[filename][key]
  203.     end
  204.   end
  205. end
  206. #==============================================================================
  207. # ** Tilemap_Settings
  208. #==============================================================================
  209.  
  210. class Tilemap_Settings
  211.   #--------------------------------------------------------------------------
  212.   # * Public Instance Variables
  213.   #--------------------------------------------------------------------------
  214.   attr_accessor :map
  215.   attr_accessor :is_a_plane
  216.   attr_accessor :tone
  217.   attr_accessor :hue
  218.   attr_accessor :zoom_x
  219.   attr_accessor :zoom_y
  220.   attr_accessor :tile_size
  221.   attr_accessor :flash_data
  222.   #--------------------------------------------------------------------------
  223.   # * Object Initialization
  224.   #--------------------------------------------------------------------------
  225.   def initialize(map = nil)
  226.         # Set Instance Variables
  227.         @map, @is_a_plane, @tone, @hue, @zoom_x, @zoom_y, @tile_size,
  228.         @flash_data = map, false, nil, 0, 1.0, 1.0, 32, nil
  229.   end
  230. end
  231.  
  232. #==============================================================================
  233. # ** Game_Map
  234. #==============================================================================
  235.  
  236. class Game_Map
  237.   #--------------------------------------------------------------------------
  238.   # * Public Instance Variables
  239.   #--------------------------------------------------------------------------
  240.   attr_accessor :tilemap_settings
  241.   #--------------------------------------------------------------------------
  242.   # * Alias Listings
  243.   #--------------------------------------------------------------------------
  244.   alias_method :seph_tilemap_gmap_init, :initialize
  245.   alias_method :seph_tilemap_gmap_stld, :setup
  246.   #--------------------------------------------------------------------------
  247.   # * Object Initialization
  248.   #--------------------------------------------------------------------------
  249.   def initialize
  250.     # Original Initialization
  251.     seph_tilemap_gmap_init
  252.     # Create Tilemap Settings
  253.     @tilemap_settings = Tilemap_Settings.new
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # * Load Map Data
  257.   #--------------------------------------------------------------------------
  258.   def setup(*args)
  259.     # Original Load Map Data
  260.     seph_tilemap_gmap_stld(*args)
  261.     # Reset Tilemap Flash Data
  262.     if Tilemap_Options::Autoset_Flash_data
  263.       @tilemap_settings.flash_data = Table.new(@map.width, @map.height)
  264.     end
  265.     @tilemap_settings.map = @map
  266.   end
  267. end
  268.  
  269. #==============================================================================
  270. # ** Spriteset_Map
  271. #==============================================================================
  272.  
  273. class Spriteset_Map
  274.   #--------------------------------------------------------------------------
  275.   # * Alias Listings
  276.   #--------------------------------------------------------------------------
  277.   alias_method :seph_tilemap_ssmap_inittm, :initialize#create_tilemap
  278.   #--------------------------------------------------------------------------
  279.   # * Tilemap Initialization
  280.   #--------------------------------------------------------------------------
  281.   def initialize(*args)#create_tilemap
  282.     # Original Tilemap Initialization
  283.     seph_tilemap_ssmap_inittm(*args)
  284.     # Set Tilemap Settings
  285.     @tilemap.tileset_name = $game_map.tileset_name
  286.     for i in 0..6
  287.       @tilemap.autotiles_name[i] = $game_map.autotile_names[i]
  288.     end
  289.     @tilemap.tilemap_settings = $game_map.tilemap_settings
  290.     # Setup Flash Data
  291.     @tilemap.flash_data = $game_map.tilemap_settings.flash_data
  292.     # Run Tilemap Setup
  293.     @tilemap.setup
  294.     update
  295.   end
  296. end
  297.  
  298. #==============================================================================
  299. # ** Tilemap
  300. #==============================================================================
  301.  
  302. class Tilemap
  303.   #--------------------------------------------------------------------------
  304.   # * Public Instance Variables
  305.   #--------------------------------------------------------------------------
  306.   attr_reader   :layers
  307.   attr_accessor :tileset
  308.   attr_accessor :tileset_name
  309.   attr_accessor :autotiles
  310.   attr_accessor :autotiles_name
  311.   attr_reader   :map_data
  312.   attr_accessor :flash_data
  313.   attr_accessor :priorities
  314.   attr_accessor :visible
  315.   attr_accessor :ox
  316.   attr_accessor :oy
  317.   attr_accessor :tilemap_settings
  318.   attr_accessor :refresh_autotiles
  319.   #--------------------------------------------------------------------------
  320.   # * Object Initialization
  321.   #--------------------------------------------------------------------------
  322.   def initialize(viewport)
  323.     # Saves Viewport
  324.     @viewport = viewport
  325.     # Creates Blank Instance Variables
  326.     @layers             = []    # Refers to Array of Sprites or Planes
  327.     @tileset            = nil   # Refers to Tileset Bitmap
  328.     @tileset_name       = ''    # Refers to Tileset Filename
  329.     @autotiles          = []    # Refers to Array of Autotile Bitmaps
  330.     @autotiles_name     = []    # Refers to Array of Autotile Filenames
  331.     @map_data           = nil   # Refers to 3D Array Of Tile Settings
  332.     @flash_data         = nil   # Refers to 3D Array of Tile Flashdata
  333.     @priorities         = nil   # Refers to Tileset Priorities
  334.     @visible            = true  # Refers to Tilest Visibleness
  335.     @ox                 = 0     # Bitmap Offsets       
  336.     @oy                 = 0     # Bitmap Offsets
  337.     @tilemap_settings  = nil   # Special Tilemap Settings
  338.     @dispose            = false # Disposed Flag
  339.     @refresh_autotiles = true  # Refresh Autotile Flag
  340.   end
  341.   #--------------------------------------------------------------------------
  342.   # * Setup
  343.   #--------------------------------------------------------------------------
  344.   def setup
  345.     # Print Error if Tilemap Settings not Found
  346.     if Tilemap_Options::Print_Error_Logs
  347.       if @tilemap_settings.nil?
  348.         p 'Tilemap Settings have not been set. System will not crash.'
  349.       end
  350.       if @map_data.nil?
  351.         p 'Map Data has not been set. System will crash.'
  352.       end
  353.     end
  354.     # Creates Layers
  355.     @layers = []
  356.     for l in 0...3
  357.       layer = @tilemap_settings.nil? || !@tilemap_settings.is_a_plane ?
  358.         Sprite.new(@viewport) : Plane.new(@viewport)
  359.       layer.bitmap = Bitmap.new(@map_data.xsize * 32, @map_data.ysize * 32)
  360.       layer.z = l * 150
  361.       layer.zoom_x = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_x
  362.       layer.zoom_y = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_y
  363.       unless @tilemap_settings.nil? || @tilemap_settings.tone.nil?
  364.         layer.tone = @tilemap_settings.tone
  365.       end
  366.       @layers << layer
  367.     end
  368.     # Update Flags
  369.     @refresh_data = nil
  370.     @zoom_x   = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_x
  371.     @zoom_y   = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_y
  372.     @tone       = @tilemap_settings.nil? ? nil : @tilemap_settings.tone
  373.     @hue        = @tilemap_settings.nil? ? 0   : @tilemap_settings.hue
  374.     @tilesize = @tilemap_settings.nil? ? 32  : @tilemap_settings.tile_size
  375.   end
  376.   #--------------------------------------------------------------------------
  377.   # * Map Data=
  378.   #--------------------------------------------------------------------------
  379.   def map_data=(map_data)
  380.     # Save Map Data
  381.     @map_data = map_data
  382.     # Refresh if able
  383.     begin
  384.       refresh
  385.     rescue
  386.     end
  387.   end
  388.   #--------------------------------------------------------------------------
  389.   # * Dispose
  390.   #--------------------------------------------------------------------------
  391.   def dispose
  392.     # Dispose Layers (Sprites)
  393.     @layers.each { |layer| layer.dispose }
  394.     # Set Disposed Flag to True
  395.     @disposed = true
  396.   end
  397.   #--------------------------------------------------------------------------
  398.   # * Disposed?
  399.   #--------------------------------------------------------------------------
  400.   def disposed?
  401.     return @disposed
  402.   end
  403.   #--------------------------------------------------------------------------
  404.   # * Viewport
  405.   #--------------------------------------------------------------------------
  406.   def viewport
  407.     return @viewport
  408.   end
  409.   #--------------------------------------------------------------------------
  410.   # * Frame Update
  411.   #--------------------------------------------------------------------------
  412.   def update
  413.     #return if @tilemap_settings.nil?
  414.     # Set Refreshed Flag to On
  415.     needs_refresh = true
  416.     # If Map Data, Tilesize or HueChanges
  417.     if @map_data != @refresh_data || (!@tilemap_settings.nil? &&
  418.       ((@tilemap_settings != false && @hue != @tilemap_settings.hue) ||
  419.       (@tilemap_settings != false && @tilesize != @tilemap_settings.tile_size)))
  420.       # Refresh Bitmaps
  421.       refresh
  422.       # Turns Refresh Flag to OFF
  423.       needs_refresh = false
  424.     end
  425.     # Zoom X, Zoom Y, and Tone Changes
  426.     unless @tilemap_settings.nil?
  427.       if @zoom_x != @tilemap_settings.zoom_x
  428.         @zoom_x = @tilemap_settings.zoom_x
  429.         @layers.each {|layer| layer.zoom_x = @zoom_x}
  430.       end
  431.       if @zoom_y != @tilemap_settings.zoom_y
  432.         @zoom_y = @tilemap_settings.zoom_y
  433.         @layers.each {|layer| layer.zoom_y = @zoom_y}
  434.       end
  435.       if @tone != @tilemap_settings.tone
  436.         @tone = @tilemap_settings.tone.nil? ?
  437.           Tone.new(0, 0, 0, 0) : @tilemap_settings.tone
  438.         @layers.each {|layer| layer.tone = @tone}
  439.       end
  440.     end
  441.     # Update layer Position offsets
  442.     for layer in @layers
  443.       layer.ox = @ox
  444.       layer.oy = @oy
  445.     end
  446.     # If Refresh Autotiles, Needs Refreshed & Autotile Reset Frame
  447.     if @refresh_autotiles && needs_refresh &&
  448.       Graphics.frame_count % RPG::Cache::Animated_Autotiles_Frames == 0
  449.       # Refresh Autotiles
  450.       refresh_autotiles
  451.     end
  452.   end
  453.   #--------------------------------------------------------------------------
  454.   # * Refresh
  455.   #--------------------------------------------------------------------------
  456.   def refresh
  457.     # Saves Map Data & Tilesize
  458.     @refresh_data = @map_data
  459.     @hue        = @tilemap_settings.nil? ? 0  : @tilemap_settings.hue
  460.     @tilesize = @tilemap_settings.nil? ? 32 : @tilemap_settings.tile_size
  461.     # Passes Through Layers
  462.     for z in 0...@map_data.zsize
  463.       # Passes Through X Coordinates
  464.       for x in 0...@map_data.xsize
  465.         # Passes Through Z Coordinates
  466.         for y in 0...@map_data.ysize
  467.           # Collects Tile ID
  468.           id = @map_data[x, y, z]
  469.           # Skip if 0 tile
  470.           next if id == 0
  471.           # Passes Through All Priorities
  472.           for p in 0..5
  473.             # Skip If Priority Doesn't Match
  474.             next unless p == @priorities[id]
  475.             # Cap Priority to Layer 3
  476.             p = 2 if p > 2
  477.             # Draw Tile
  478.             id < 384 ? draw_autotile(x, y, p, id) : draw_tile(x, y, p, id)
  479.           end
  480.         end
  481.       end
  482.     end
  483.   end  
  484.   #--------------------------------------------------------------------------
  485.   # * Refresh Auto-Tiles
  486.   #--------------------------------------------------------------------------
  487.   def refresh_autotiles
  488.     # Auto-Tile Locations
  489.     autotile_locations = Table.new(@map_data.xsize, @map_data.ysize,
  490.       @map_data.zsize)
  491.     # Get X Tiles
  492.     x1 = [(@ox.round / @tilesize) - Tilemap_Options::Viewport_Padding, 0].max
  493.     x2 = [(@viewport.rect.width / @tilesize) +
  494.           Tilemap_Options::Viewport_Padding, @map_data.xsize].min
  495.     # Get Y Tiles
  496.     y1 = [(@oy.round / @tilesize) - Tilemap_Options::Viewport_Padding, 0].max
  497.     y2 = [(@viewport.rect.height / @tilesize) +
  498.           Tilemap_Options::Viewport_Padding, @map_data.ysize].min
  499.     # Passes Through Layers
  500.     for z in 0...@map_data.zsize
  501.       # Passes Through X Coordinates
  502.       for x in x1...x2
  503.         # Passes Through Y Coordinates
  504.         for y in y1...y2
  505.           # Collects Tile ID
  506.           id = @map_data[x, y, z]
  507.           # Skip if 0 tile
  508.           next if id == 0
  509.           # Skip If Non-Animated Tile
  510.           next unless @autotiles[id / 48 - 1].width / 96 > 1 if id < 384
  511.           # Get Priority
  512.           p = @priorities[id]
  513.           # Cap Priority to Layer 3
  514.           p = 2 if p > 2
  515.           # If Autotile
  516.           if id < 384
  517.             # Draw Auto-Tile
  518.             draw_autotile(x, y, p, id)
  519.             # Draw Higher Tiles
  520.             for l in 0...@map_data.zsize
  521.               id_l = @map_data[x, y, l]
  522.               draw_tile(x, y, p, id_l)
  523.             end
  524.             # Save Autotile Location
  525.             autotile_locations[x, y, z] = 1
  526.           # If Normal Tile
  527.           else
  528.             # If Autotile Drawn
  529.             if autotile_locations[x, y, z] == 1
  530.               # Redraw Normal Tile
  531.               draw_tile(x, y, p, id)
  532.               # Draw Higher Tiles
  533.               for l in 0...@map_data.zsize
  534.                 id_l = @map_data[x, y, l]
  535.                 draw_tile(x, y, p, id_l)
  536.               end
  537.             end
  538.           end
  539.         end
  540.       end
  541.     end
  542.   end  
  543.   #--------------------------------------------------------------------------
  544.   # * Draw Tile
  545.   #--------------------------------------------------------------------------
  546.   def draw_tile(x, y, z, id)
  547.     # Gets Tile Bitmap
  548.     bitmap = RPG::Cache.tile(@tileset_name, id, @hue)
  549.     # Calculates Tile Coordinates
  550.     x *= @tilesize
  551.     y *= @tilesize
  552.     # Draw Tile
  553.     if @tilesize == 32
  554.       @layers[z].bitmap.blt(x, y, bitmap, Rect.new(0, 0, 32, 32))
  555.     else
  556.       rect = Rect.new(x, y, @tilesize, @tilesize)
  557.       @layers[z].bitmap.stretch_blt(rect, bitmap, Rect.new(0, 0, 32, 32))
  558.     end
  559.   end
  560.   #--------------------------------------------------------------------------
  561.   # * Draw Auto-Tile
  562.   #--------------------------------------------------------------------------
  563.   def draw_autotile(x, y, z, tile_id)
  564.     # Gets Autotile Filename
  565.     filename = @autotiles_name[tile_id / 48 - 1]
  566.     # Reconfigure Tile ID
  567.     tile_id %= 48
  568.     # Gets Generated Autotile Bitmap Section
  569.     bitmap = RPG::Cache.autotile_tile(filename, tile_id, @hue)
  570.     # Calculates Tile Coordinates
  571.     x *= @tilesize
  572.     y *= @tilesize
  573.     # If Normal Tile
  574.     if @tilesize == 32
  575.       @layers[z].bitmap.blt(x, y, bitmap, Rect.new(0, 0, 32, 32))
  576.     # If Altered Dimensions
  577.     else
  578.       dest_rect = Rect.new(x, y, @tilesize, @tilesize)
  579.       @layers[z].bitmap.stretch_blt(dest_rect, bitmap, Rect.new(0, 0, 32, 32))
  580.     end
  581.   end
  582.   #--------------------------------------------------------------------------
  583.   # * Collect Bitmap
  584.   #--------------------------------------------------------------------------
  585.   def bitmap
  586.     # Creates New Blank Bitmap
  587.     bitmap = Bitmap.new(@layers[0].bitmap.width, @layers[0].bitmap.height)
  588.     # Passes Through All Layers
  589.     for layer in @layers
  590.       bitmap.blt(0, 0, layer.bitmap,
  591.         Rect.new(0, 0, bitmap.width, bitmap.height))
  592.     end
  593.     # Return Bitmap
  594.     return bitmap
  595.   end
  596. end
  597.  
  598. #==============================================================================
  599. # ** Tilemap (Flash Data)
  600. #------------------------------------------------------------------------------
  601. # SephirothSpawn
  602. # Version 1.01
  603. # 2007-07-30
  604. # SDK : Version 2.2+, Parts I & II
  605. #------------------------------------------------------------------------------
  606. # * Version History :
  607. #
  608. #   Version 1 ---------------------------------------------------- (2007-05-30)
  609. #       Version 1.01 ------------------------------------------------ (2007-07-30)
  610. #       - Update : Fixed Small Bug
  611. #------------------------------------------------------------------------------
  612. # * Requirements :
  613. #
  614. #   Tilemap (Basic) 1.0+
  615. #------------------------------------------------------------------------------
  616. # * Description :
  617. #
  618. #   This script adds flash data to the Tilemap class. Because flash data isn't
  619. #   used a lot in 99% of the scripts, this was seperated from the Tilemap
  620. #   Basic.
  621. #------------------------------------------------------------------------------
  622. # * Instructions :
  623. #
  624. #   Place The Script Below the SDK and Above Main.
  625. #==============================================================================
  626.  
  627. #==============================================================================
  628. # ** Tilemap
  629. #==============================================================================
  630.  
  631. class Tilemap
  632.   #--------------------------------------------------------------------------
  633.   # * Autotile Padding
  634.   #--------------------------------------------------------------------------
  635.   Autotile_Padding = 2
  636.   #--------------------------------------------------------------------------
  637.   # * Public Instance Variables
  638.   #--------------------------------------------------------------------------
  639.   attr_reader :update_flashtiles
  640.   #--------------------------------------------------------------------------
  641.   # * Alias Listings
  642.   #--------------------------------------------------------------------------
  643.   alias_method :seph_tilemapflashdata_tilemap_setup,   :setup
  644.   alias_method :seph_tilemapflashdata_tilemap_dispose, :dispose
  645.   alias_method :seph_tilemapflashdata_tilemap_update,  :update
  646.   #--------------------------------------------------------------------------
  647.   # * Update Flashtiles
  648.   #--------------------------------------------------------------------------
  649.   def update_flashtiles=(bool)
  650.     # Set Instance
  651.     @update_flashtiles = bool
  652.     # If True and Nil Flash Tiles
  653.     if bool && @flash_sprites.nil?
  654.       # Setup Flash Sprites
  655.       setup_flash_sprites
  656.     end
  657.     # If False and Flash Tiles Exist
  658.     if bool == false && @flash_sprites != nil
  659.       # Turn Tiles Invisible
  660.       @flash_sprites.each { |sprite| sprite.visible = false }
  661.     end
  662.   end
  663.   #--------------------------------------------------------------------------
  664.   # * Setup
  665.   #--------------------------------------------------------------------------
  666.   def setup
  667.     # Original Setup
  668.     seph_tilemapflashdata_tilemap_setup
  669.     # Turn Update Flashtiles Off
  670.     self.update_flashtiles = Tilemap_Options::Default_Update_Flashtiles
  671.   end
  672.   #--------------------------------------------------------------------------
  673.   # * Setup Flash Sprites
  674.   #--------------------------------------------------------------------------
  675.   def setup_flash_sprites
  676.     # Creates Flash Data Sprites
  677.     @flash_sprites = []
  678.     @flashing_sprites = []
  679.     @flash_sprite_size = @tilesize
  680.     for x in 0...@map_data.xsize
  681.       for y in 0...@map_data.ysize
  682.         sprite = Sprite.new(@viewport)
  683.         sprite.x, sprite.y, sprite.z = x * @tilesize, y * @tilesize, 151
  684.         sprite.bitmap = Bitmap.new(@tilesize, @tilesize)
  685.         @flash_sprites << sprite
  686.       end
  687.     end
  688.   end
  689.   #--------------------------------------------------------------------------
  690.   # * Dispose
  691.   #--------------------------------------------------------------------------
  692.   def dispose
  693.     # Original Dispose
  694.     seph_tilemapflashdata_tilemap_dispose
  695.     # Dispose Layers (Sprites)
  696.     unless @flash_sprites.nil?
  697.       @flash_sprites.each { |sprite| sprite.dispose }
  698.     end
  699.   end
  700.   #--------------------------------------------------------------------------
  701.   # * Frame Update
  702.   #--------------------------------------------------------------------------
  703.   def update
  704.     # Original Update
  705.     seph_tilemapflashdata_tilemap_update
  706.     # If Update Flashtiles and Sizes don't Match
  707.     if @update_flashtiles && @flash_sprite_size != @tilesize
  708.       # Setup Flash Sprites
  709.       setup_flash_sprites
  710.     end
  711.     # If Update Flashtiles and Flash Data isn't Nil
  712.     if @update_flashtiles && @flash_data != nil
  713.       # Get X Tiles
  714.       x1 = [@ox / @tilesize - Autotile_Padding, 0].max
  715.       x2 = [@viewport.rect.width / @tilesize + Autotile_Padding,
  716.                 @map_data.xsize].min
  717.       # Get Y Tiles
  718.       y1 = [@oy / @tilesize - Autotile_Padding, 0].max
  719.       y2 = [@viewport.rect.height / @tilesize + Autotile_Padding,
  720.                 @map_data.ysize].min
  721.       # Update Flash Data Sprites
  722.       for sprite in @flash_sprites
  723.         sprite.ox, sprite.oy = @ox, @oy
  724.         sprite.update
  725.         # Gets RGB Value
  726.         x, y = sprite.x / @tilesize, sprite.y / @tilesize
  727.         # Skip If Not On Screen (or without padding)
  728.         next unless x.between?(x1, x2) && y.between?(y1, y2)
  729.         rgb = @flash_data.nil? ? nil : @flash_data[x, y]
  730.         if rgb.nil? || rgb == 0
  731.           # If Sprite Flashing
  732.           if @flashing_sprites.include?([x, y])
  733.             sprite.bitmap.clear
  734.             @flashing_sprites.delete([x, y])
  735.           end
  736.         else
  737.           # If Sprite Not Already Flashing
  738.           unless @flashing_sprites.include?([x, y])
  739.             @flashing_sprites << [x, y]
  740.             sprite.bitmap.fill_rect(0, 0, 32, 32,
  741.               Tilemap_Options::Flash_Bitmap_C)
  742.           end
  743.           if Graphics.frame_count % Tilemap_Options::Flash_Duration == 0
  744.             r, g, b = rgb / 0x010000, rgb / 0x100 % 0x100, rgb % 0x100
  745.             sprite.flash((c = Color.new(r, g, b)),
  746.             Tilemap_Options::Flash_Duration)
  747.           end
  748.         end
  749.       end
  750.     end
  751.   end
  752. end
  753.  
  754. #------------------------------------------------------------------------------
  755. # End SDK Enabled Check
  756. #------------------------------------------------------------------------------
  757. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top