Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Hidden Tilemap REWRITE + Zoom (noSDK) [SOLVED]

Good evening everyone, i'll go straight to the point:

I'm looking for a Rewrite of the Hidden Tilemap class, the one that has been made several times, by Poccil, by RTH, by SephirothSpawn...
the problem is that the only version of this script that has the ZOOM option is the SephirothSpawn one... and it depend on the SDK, i've managed in doing one without the SDK, but there's a problem with the Layer priorities...
is there a way to merge together the various version of this class making one that zoom and take care of the priorities?

SephirothSpawn's Tilemap (noSDK) + zoom defs from Trebor777 - Modified by me and Ally:
Code:
#==============================================================================

# ** Spriteset_Map

#------------------------------------------------------------------------------

# Scena modificata per eliminare l'SDK

# Autore: Ally

#         [url=http://www.rpgmkr.net]http://www.rpgmkr.net[/url]

#==============================================================================

 

class Spriteset_Map

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    # Make viewports

    @viewport1 = Viewport.new(0, 0, 640, 480)

    @viewport2 = Viewport.new(0, 0, 640, 480)

    @viewport3 = Viewport.new(0, 0, 640, 480)

    @viewport2.z = 200

    @viewport3.z = 5000

    # Make tilemap

    init_tilemap

    # Make panorama plane

    @panorama = Plane.new(@viewport1)

    @panorama.z = -1000

    # Make fog plane

    @fog = Plane.new(@viewport1)

    @fog.z = 3000

    # Make character sprites

    @character_sprites = []

    for i in $game_map.events.keys.sort

      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])

      @character_sprites.push(sprite)

    end

    @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))

    # Make weather

    @weather = RPG::Weather.new(@viewport1)

    # Make picture sprites

    @picture_sprites = []

    for i in 1..50

      @picture_sprites.push(Sprite_Picture.new(@viewport2,

        $game_screen.pictures[i]))

    end

    # Make timer sprite

    @timer_sprite = Sprite_Timer.new

    # Frame update

    update

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  def dispose

    # Dispose of tilemap

    @tilemap.tileset.dispose

    for i in 0..6

      @tilemap.autotiles[i].dispose

    end

    @tilemap.dispose

    # Dispose of panorama plane

    @panorama.dispose

    # Dispose of fog plane

    @fog.dispose

    # Dispose of character sprites

    for sprite in @character_sprites

      sprite.dispose

    end

    # Dispose of weather

    @weather.dispose

    # Dispose of picture sprites

    for sprite in @picture_sprites

      sprite.dispose

    end

    # Dispose of timer sprite

    @timer_sprite.dispose

    # Dispose of viewports

    @viewport1.dispose

    @viewport2.dispose

    @viewport3.dispose

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # If panorama is different from current one

    if @panorama_name != $game_map.panorama_name or

       @panorama_hue != $game_map.panorama_hue

      @panorama_name = $game_map.panorama_name

      @panorama_hue = $game_map.panorama_hue

      if @panorama.bitmap != nil

        @panorama.bitmap.dispose

        @panorama.bitmap = nil

      end

      if @panorama_name != ""

        @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)

      end

      Graphics.frame_reset

    end

    # If fog is different than current fog

    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue

      @fog_name = $game_map.fog_name

      @fog_hue = $game_map.fog_hue

      if @fog.bitmap != nil

        @fog.bitmap.dispose

        @fog.bitmap = nil

      end

      if @fog_name != ""

        @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)

      end

      Graphics.frame_reset

    end

    # Update tilemap

    @tilemap.ox = $game_map.display_x / 4

    @tilemap.oy = $game_map.display_y / 4

    @tilemap.update

    # Update panorama plane

    @panorama.ox = $game_map.display_x / 8

    @panorama.oy = $game_map.display_y / 8

    # Update fog plane

    @fog.zoom_x = $game_map.fog_zoom / 100.0

    @fog.zoom_y = $game_map.fog_zoom / 100.0

    @fog.opacity = $game_map.fog_opacity

    @fog.blend_type = $game_map.fog_blend_type

    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox

    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy

    @fog.tone = $game_map.fog_tone

    # Update character sprites

    for sprite in @character_sprites

      sprite.update

    end

    # Update weather graphic

    @weather.type = $game_screen.weather_type

    @weather.max = $game_screen.weather_max

    @weather.ox = $game_map.display_x / 4

    @weather.oy = $game_map.display_y / 4

    @weather.update

    # Update picture sprites

    for sprite in @picture_sprites

      sprite.update

    end

    # Update timer sprite

    @timer_sprite.update

    # Set screen color tone and shake position

    @viewport1.tone = $game_screen.tone

    @viewport1.ox = $game_screen.shake

    # Set screen flash color

    @viewport3.color = $game_screen.flash_color

    # Update viewports

    @viewport1.update

    @viewport3.update

  end

end

 

#===============================

# SECOND PART

#===============================

 

#==============================================================================

# ** Tilemap (Basic)

#------------------------------------------------------------------------------

# SephirothSpawn

# Version 1.0

# 2007-05-30

#------------------------------------------------------------------------------

# * Credits :

#

#   Thanks to Trickster for conversion formula for Hexidecimal to rgb.

#   Thanks to trebor777 for helping with the priority bug from the 0.9 version.

#   Thanks to Ally for :

#    - disable script of SDK

#    - Fix bug passabilità

#    - Fix bug al codice

#    - Modificato lo Spriteset_Map

#    http://www.rpgmkr.net

#------------------------------------------------------------------------------

# * Description :

#

#   This script was designed to re-write the default RMXP Hidden Tileset class.

#   The script has added many features and a new "Tilemap Settings" class,

#   that can be unique if you create mini-maps using this system.

#------------------------------------------------------------------------------

# * Instructions :

#

#   Place The Script Below the SDK and Above Main.

#------------------------------------------------------------------------------

# * Syntax :

#

#   Get Autotile Tile Bitmap

#    - RPG::Cache.autotile_tile(autotile_filename, tile_id[, hue[, frame_id]])

#

#      autotile_filename : Filename of autotile

#      tile_id : ID of tile (Found from RPG::Map.data)

#      hue (Optional) : Hue for tile

#      frame_id (Optional) : Frame of tile (for animated autotiles)

#

# * Tilemap Syntax

#

#   Readable Attributes :

#    - layers : Array of Sprites (or Planes)

#

#   Readable/Writable Attributes :

#    - tileset (No long required) : Bitmap for Tileset

#    - tileset_name : Name of Bitmap

#    - autotiles (No long required) : Array of Autotile Bitmaps

#    - autotiles_name : Array of Autotile Filenames

#    - map_data : 3D Table of Tile ID Data

#    - flash_data : 3D Table of Tile Flash Data

#                   (Should match tilemap_settings.flash_data)

#    - priorities : 3D Table of Tile Priorities

#    - Visible : Tilemap Visible Flag

#    - ox, oy : Tilemap layer offsets

#    - tilemap_settings : Unique Special Settings Object (See Below)

#    - refresh_autotiles : Refresh Autotiles on frame reset flag

#

# * Special Tilemap Settings

#

#   To make special settings easier to control for your game map and any other

#   special tilemap sprites you wish to create, a special class was created

#   to hold these settings. For your game tilemap, a Tilemap_Settings object

#   was created in $game_map ($game_map.tilemap_settings). It is advised to

#   modify $game_map.tilemap_settings.flash_data instead of tilemap.flash_data.

#

#   Readable/Writeable Attributes :

#    - map : RPG::Map (Not required, but for additions)

#    - is_a_plane : Boolean whether layers are Sprites or Planes

#    - tone : Tone for all layers

#    - hue : Hue for all layers

#    - zoom_x, zoom_y : Zoom factor for all layers

#    - tilesize : Tilesize displayed on map

#    - flash_data : 3D Table of flash_data

#==============================================================================

 

 

 

#==============================================================================

# ** Tilemap_Options

#==============================================================================

 

module Tilemap_Options

  #--------------------------------------------------------------------------

  # * Tilemap Options

  #

  #

  #   Print Error Reports when not enough information set to tilemap

  #    - Print_Error_Logs          = true or false

  #

  #   Number of autotiles to refresh at edge of viewport

  #   Number of Frames Before Redrawing Animated Autotiles

  #    - Animated_Autotiles_Frames = 16

  #

  #    - Viewport_Padding          = n

  #

  #   When maps are switch, automatically set

  #   $game_map.tileset_settings.flash_data (Recommended : False unless using

  #   flash_data)

  #    - Autoset_Flash_data        = true or false

  #

  #   Duration Between Flash Data Flashes

  #    - Flash_Duration            = n

  #

  #   Color of bitmap (Recommended to use low opacity value)

  #    - Flash_Bitmap_C            = Color.new(255, 255, 255, 50)

  #

  #   Update Flashtiles Default Setting

  #   Explanation : In the Flash Data Addition, because of lag, you may wish

  #   to toggle whether flash tiles flash or not. This is the default state.

  #    - Default_Update_Flashtiles = false

  #--------------------------------------------------------------------------

  Print_Error_Logs          = true

  Animated_Autotiles_Frames = 16

  Autoset_Flash_data        = true

  Viewport_Padding          = 2

  Flash_Duration            = 40

  Flash_Bitmap_C            = Color.new(255, 255, 255, 50)

  Default_Update_Flashtiles = false

end

 

 

 

#==============================================================================

# ** RPG::Cache

#==============================================================================

 

module RPG::Cache

  #--------------------------------------------------------------------------

  # * Auto-Tiles

  #

  #   Auto-Tile 48 : First Auto-Tile, Constructed of tiles 27, 28, 33, 34

  #--------------------------------------------------------------------------

  Autotiles = [

    [[27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],

     [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12]],

    [[27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],

     [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12]],

    [[25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],

     [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12]],

    [[29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],

     [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46]],

    [[25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],

     [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48]],

    [[37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],

     [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8]]

  ]

  #--------------------------------------------------------------------------

  # * Autotile Cache

  #

  #   @autotile_cache = {

  #     filename => { [autotile_id, frame_id, hue] => bitmap, ... },

  #     ...

  #    }

  #--------------------------------------------------------------------------

  @autotile_cache = {}

  #--------------------------------------------------------------------------

  # * Autotile Tile

  #--------------------------------------------------------------------------

  def self.autotile_tile(filename, tile_id, hue = 0, frame_id = nil)

    return if filename.nil?

    # Gets Autotile Bitmap

    autotile = self.autotile(filename)

    # Configures Frame ID if not specified

    if frame_id.nil?

      # Animated Tiles

      frames = autotile.width / 96

      # Configures Animation Offset

      fc = Graphics.frame_count / Tilemap_Options::Animated_Autotiles_Frames

      frame_id = (fc) % frames * 96

    end

    # Creates list if already not created

    @autotile_cache[filename] = {} unless @autotile_cache.has_key?(filename)

    # Gets Key

    key = [tile_id, frame_id, hue]

    # If Key Not Found

    unless @autotile_cache[filename].has_key?(key)

      # Reconfigure Tile ID

      tile_id %= 48

      # Creates Bitmap

      bitmap = Bitmap.new(32, 32)

      # Collects Auto-Tile Tile Layout

      tiles = Autotiles[tile_id / 8][tile_id % 8]

      # Draws Auto-Tile Rects

      for i in 0...4

        tile_position = tiles[i] - 1

        src_rect = Rect.new(tile_position % 6 * 16 + frame_id,

          tile_position / 6 * 16, 16, 16)

        bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)

      end

      # Saves Autotile to Cache

      @autotile_cache[filename][key] = bitmap

      # Change Hue

      @autotile_cache[filename][key].hue_change(hue)

    end

    # Return Autotile

    return @autotile_cache[filename][key]

  end

end

 

 

 

#==============================================================================

# ** Tilemap_Settings

#==============================================================================

 

class Tilemap_Settings

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_accessor :map

  attr_accessor :is_a_plane

  attr_accessor :tone

  attr_accessor :hue

  attr_accessor :zoom_x

  attr_accessor :zoom_y

  attr_accessor :tile_size

  attr_accessor :flash_data

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize(map = nil)

    # Set Instance Variables

    @map, @is_a_plane, @tone, @hue, @zoom_x, @zoom_y, @tile_size,

      @flash_data = map, false, nil, 0, 1.0, 1.0, 32, nil

  end

end

 

 

 

#==============================================================================

# ** Game_Map

#==============================================================================

 

class Game_Map

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_accessor :tilemap_settings

  #--------------------------------------------------------------------------

  # * Alias Listings

  #--------------------------------------------------------------------------

  alias_method :seph_tilemap_gmap_init, :initialize  unless $@

  alias_method :seph_tilemap_gmap_stld, :setup       unless $@

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    # Original Initialization

    seph_tilemap_gmap_init

    # Create Tilemap Settings

    @tilemap_settings = Tilemap_Settings.new

  end

  #--------------------------------------------------------------------------

  # * Load Map Data

  #--------------------------------------------------------------------------

  def setup(*args)

    # Original Load Map Data

    return_value = seph_tilemap_gmap_stld(*args)

    # Reset Tilemap Flash Data

    if Tilemap_Options::Autoset_Flash_data

      @tilemap_settings.flash_data = Table.new(@map.width, @map.height)

    end

    @tilemap_settings.map = @map

    # Return the original return value

    return return_value

  end

end

 

 

 

#==============================================================================

# ** Spriteset_Map

#==============================================================================

 

class Spriteset_Map

  #--------------------------------------------------------------------------

  # * Alias Listings

  #--------------------------------------------------------------------------

  #alias_method :seph_tilemap_ssmap_inittm, :init_tilemap

  #--------------------------------------------------------------------------

  # * Tilemap Initialization

  #--------------------------------------------------------------------------

  def init_tilemap

    # Original Tilemap Initialization

    # Make tilemap

    @tilemap = TilemapNEW.new(@viewport1)

    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)

    for i in 0..6

      autotile_name = $game_map.autotile_names[i]

      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)

    end

    @tilemap.map_data = $game_map.data.dup

    @tilemap.priorities = $game_map.priorities

    # Set Tilemap Settings

    @tilemap.tileset_name = $game_map.tileset_name

    for i in 0..6

      @tilemap.autotiles_name[i] = $game_map.autotile_names[i]

    end

    @tilemap.tilemap_settings = $game_map.tilemap_settings

    # Setup Flash Data

    @tilemap.flash_data = $game_map.tilemap_settings.flash_data

    # Run Tilemap Setup

    @tilemap.setup

  end

end

 

 

 

#==============================================================================

# ** Tilemap

#==============================================================================

 

class TilemapNEW

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_reader   :layers

  attr_accessor :tileset

  attr_accessor :tileset_name

  attr_accessor :autotiles

  attr_accessor :autotiles_name

  attr_accessor :map_data

  attr_accessor :flash_data

  attr_accessor :priorities

  attr_accessor :visible

  attr_accessor :ox

  attr_accessor :oy

  attr_accessor :tilemap_settings

  attr_accessor :refresh_autotiles

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize(viewport)

    # Saves Viewport

    @viewport = viewport

    # Creates Blank Instance Variables

    @layers            = []    # Refers to Array of Sprites or Planes

    @tileset           = nil   # Refers to Tileset Bitmap

    @tileset_name      = ''    # Refers to Tileset Filename

    @autotiles         = []    # Refers to Array of Autotile Bitmaps

    @autotiles_name    = []    # Refers to Array of Autotile Filenames

    @map_data          = nil   # Refers to 3D Array Of Tile Settings

    @flash_data        = nil   # Refers to 3D Array of Tile Flashdata

    @priorities        = nil   # Refers to Tileset Priorities

    @visible           = true  # Refers to Tilest Visibleness

    @ox                = 0     # Bitmap Offsets          

    @oy                = 0     # Bitmap Offsets

    @tilemap_settings  = nil   # Special Tilemap Settings

    @dispose           = false # Disposed Flag

    @refresh_autotiles = true  # Refresh Autotile Flag

  end

  #--------------------------------------------------------------------------

  # * Setup

  #--------------------------------------------------------------------------

  def setup

    # Print Error if Tilemap Settings not Found

    if Tilemap_Options::Print_Error_Logs

      if @tilemap_settings.nil?

        p 'Tilemap Settings have not been set. System will not crash.'

      end

      if @map_data.nil?

        p 'Map Data has not been set. System will crash.'

      end

    end

    # Creates Layers

    @layers = []

    for l in 0...3

      layer = @tilemap_settings.nil? || !@tilemap_settings.is_a_plane ?

        Sprite.new(@viewport) : Plane.new(@viewport)

      layer.bitmap = Bitmap.new(@map_data.xsize * 32, @map_data.ysize * 32)

      layer.z = l * 150

      layer.zoom_x = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_x

      layer.zoom_y = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_y

      unless @tilemap_settings.nil? || @tilemap_settings.tone.nil?

        layer.tone = @tilemap_settings.tone

      end

      @layers << layer

    end

    # Update Flags

    @refresh_data = nil

    @zoom_x   = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_x

    @zoom_y   = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_y

    @tone     = @tilemap_settings.nil? ? nil : @tilemap_settings.tone

    @hue      = @tilemap_settings.nil? ? 0   : @tilemap_settings.hue

    @tilesize = @tilemap_settings.nil? ? 32  : @tilemap_settings.tile_size

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  def dispose

    # Dispose Layers (Sprites)

    @layers.each { |layer| layer.dispose }

    # Set Disposed Flag to True

    @disposed = true

  end

  #--------------------------------------------------------------------------

  # * Disposed?

  #--------------------------------------------------------------------------

  def disposed?

    return @disposed

  end

  #--------------------------------------------------------------------------

  # * Viewport

  #--------------------------------------------------------------------------

  def viewport

    return @viewport

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # Set Refreshed Flag to On

    needs_refresh = true

    # If Map Data, Tilesize or HueChanges

    if @map_data != @refresh_data || (@tilemap_settings != false &&

       @hue != @tilemap_settings.hue) || (@tilemap_settings != false &&

       @tilesize != @tilemap_settings.tile_size)

      # Refresh Bitmaps

      refresh

      # Turns Refresh Flag to OFF

      needs_refresh = false

    end

    # Zoom X, Zoom Y, and Tone Changes

    unless @tilemap_settings.nil?

      if @zoom_x != @tilemap_settings.zoom_x

        @zoom_x = @tilemap_settings.zoom_x

        @layers.each {|layer| layer.zoom_x = @zoom_x}

      end

      if @zoom_y != @tilemap_settings.zoom_y

        @zoom_y = @tilemap_settings.zoom_y

        @layers.each {|layer| layer.zoom_y = @zoom_y}

      end

      if @tone != @tilemap_settings.tone

        @tone = @tilemap_settings.tone.nil? ?

          Tone.new(0, 0, 0, 0) : @tilemap_settings.tone

        @layers.each {|layer| layer.tone = @tone}

      end

    end

    # Update layer Position offsets

    for layer in @layers

      layer.ox = @ox

      layer.oy = @oy

    end

    # If Refresh Autotiles, Needs Refreshed & Autotile Reset Frame

    if @refresh_autotiles && needs_refresh &&

       Graphics.frame_count % Tilemap_Options::Animated_Autotiles_Frames == 0

      # Refresh Autotiles

      refresh_autotiles

    end

  end

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    # Saves Map Data & Tilesize

    @refresh_data = @map_data

    @hue      = @tilemap_settings.nil? ? 0  : @tilemap_settings.hue

    @tilesize = @tilemap_settings.nil? ? 32 : @tilemap_settings.tile_size

    # Passes Through Layers

    for z in 0...@map_data.zsize

      # Passes Through X Coordinates

      for x in 0...@map_data.xsize

        # Passes Through Z Coordinates

        for y in 0...@map_data.ysize

          # Collects Tile ID

          id = @map_data[x, y, z]

          # Skip if 0 tile

          next if id == 0

          # Passes Through All Priorities

          for p in 0..5

            # Skip If Priority Doesn't Match

            next unless p == @priorities[id]

            # Cap Priority to Layer 3

            p = 2 if p > 2

            # Draw Tile

            id < 384 ? draw_autotile(x, y, p, id) : draw_tile(x, y, p, id)

          end

        end

      end

    end

  end    

  #--------------------------------------------------------------------------

  # * Refresh Auto-Tiles

  #--------------------------------------------------------------------------

  def refresh_autotiles

    # Auto-Tile Locations

    autotile_locations = Table.new(@map_data.xsize, @map_data.ysize,

      @map_data.zsize)

    # Get X Tiles

    x1 = [@ox / @tilesize - Tilemap_Options::Viewport_Padding, 0].max.round

    x2 = [@viewport.rect.width / @tilesize +

          Tilemap_Options::Viewport_Padding, @map_data.xsize].min.round

    # Get Y Tiles

    y1 = [@oy / @tilesize - Tilemap_Options::Viewport_Padding, 0].max.round

    y2 = [@viewport.rect.height / @tilesize +

          Tilemap_Options::Viewport_Padding, @map_data.ysize].min.round

    # Passes Through Layers

    for z in 0...@map_data.zsize

      # Passes Through X Coordinates

      for x in x1...x2

        # Passes Through Y Coordinates

        for y in y1...y2

          # Collects Tile ID

          id = @map_data[x, y, z]

          # Skip if 0 tile

          next if id == 0

          # Skip If Non-Animated Tile

          next unless @autotiles[id / 48 - 1].width / 96 > 1 if id < 384

          # Passes Through All Priorities

          for p in 0..5

            # Skip If Priority Doesn't Match

            next unless p == @priorities[id]

            # Cap Priority to Layer 3

            p = 2 if p > 2

            # If Autotile

            if id < 384

              # Draw Auto-Tile

              draw_autotile(x, y, p, id)

              # Draw Higher Tiles

              for l in 0...@map_data.zsize

                id_l = @map_data[x, y, l]

                draw_tile(x, y, p, id_l)

              end

              # Save Autotile Location

              autotile_locations[x, y, z] = 1

            # If Normal Tile

            else

              # If Autotile Drawn

              if autotile_locations[x, y, z] == 1

                # Redraw Normal Tile

                draw_tile(x, y, p, id)

                # Draw Higher Tiles

                for l in 0...@map_data.zsize

                  id_l = @map_data[x, y, l]

                  draw_tile(x, y, p, id_l)

                end

              end

            end

          end

        end

      end

    end

  end      

  #--------------------------------------------------------------------------

  # * Draw Tile

  #--------------------------------------------------------------------------

  def draw_tile(x, y, z, id)

    # Gets Tile Bitmap

    bitmap = RPG::Cache.tile(@tileset_name, id, @hue)

    # Calculates Tile Coordinates

    x *= @tilesize

    y *= @tilesize

    # Draw Tile

    if @tilesize == 32

      @layers[z].bitmap.blt(x, y, bitmap, Rect.new(0, 0, 32, 32))

    else

      rect = Rect.new(x, y, @tilesize, @tilesize)

      @layers[z].bitmap.stretch_blt(rect, bitmap, Rect.new(0, 0, 32, 32))

    end

    @layers[z].z = z * 1000

  end

  #--------------------------------------------------------------------------

  # * Draw Auto-Tile

  #--------------------------------------------------------------------------

  def draw_autotile(x, y, z, tile_id)

    # Gets Autotile Filename

    filename = @autotiles_name[tile_id / 48 - 1]

    # Reconfigure Tile ID

    tile_id %= 48

    # Gets Generated Autotile Bitmap Section

    bitmap = RPG::Cache.autotile_tile(filename, tile_id, @hue)

    # Calculates Tile Coordinates

    x *= @tilesize

    y *= @tilesize

    # If Normal Tile

    if @tilesize == 32

      @layers[z].bitmap.blt(x, y, bitmap, Rect.new(0, 0, 32, 32))

    # If Altered Dimensions

    else

      dest_rect = Rect.new(x, y, @tilesize, @tilesize)

      @layers[z].bitmap.stretch_blt(dest_rect, bitmap, Rect.new(0, 0, 32, 32))

    end

  end

  #--------------------------------------------------------------------------

  # * Collect Bitmap

  #--------------------------------------------------------------------------

  def bitmap

    # Creates New Blank Bitmap

    bitmap = Bitmap.new(@layers[0].bitmap.width, @layers[0].bitmap.height)

    # Passes Through All Layers

    for layer in @layers

      bitmap.blt(0, 0, layer.bitmap,

        Rect.new(0, 0, bitmap.width, bitmap.height))

    end

    # Return Bitmap

    return bitmap

  end

end

 

 

#==============================================================================

# ** Game_Character

#==============================================================================

class Game_Character

  #--------------------------------------------------------------------------

  # * Get Screen X-Coordinates

  #--------------------------------------------------------------------------

  def screen_x

    # Get screen coordinates from real coordinates and map display position

    #return (@real_x) / 4 #+ 16

    return (@real_x - $game_map.display_x + 3*$game_map.tilemap_settings.zoom_x) / 4*$game_map.tilemap_settings.zoom_x + 16*$game_map.tilemap_settings.zoom_x

  end

  #--------------------------------------------------------------------------

  # * Get Screen Y-Coordinates

  #--------------------------------------------------------------------------

  def screen_y

    # Get screen coordinates from real coordinates and map display position

    y = (@real_y - $game_map.display_y + 3*$game_map.tilemap_settings.zoom_y) / 4*$game_map.tilemap_settings.zoom_y + 32*$game_map.tilemap_settings.zoom_y

    # Make y-coordinate smaller via jump count

    if @jump_count >= @jump_peak

      n = @jump_count - @jump_peak

    else

      n = @jump_peak - @jump_count

    end

    return y - (@jump_peak * @jump_peak - n * n) / 2

  end

  #--------------------------------------------------------------------------

  # * Get Screen Z-Coordinates

  #--------------------------------------------------------------------------

  def screen_z(height = 0)

    # If display flag on closest surface is ON

    if @always_on_top

      # 999, unconditional

      return 999

    end

    # Get screen coordinates from real coordinates and map display position

    z = (@real_y - $game_map.display_y + 3*$game_map.tilemap_settings.zoom_y) / 4*$game_map.tilemap_settings.zoom_y + 32*$game_map.tilemap_settings.zoom_y

    # If tile

    if @tile_id > 0

      # Add tile priority * 32

      return z + $game_map.priorities[@tile_id] * 32*$game_map.tilemap_settings.zoom_y

    # If character

    else

      # If height exceeds 32, then add 31

      return z + ((height > 32) ? 31 : 0)

    end

  end

end

 

 

 

#==============================================================================

# ** Game_Player

#==============================================================================

class Game_Player < Game_Character

  @center_x= CENTER_X   # Center screen x-coordinate * 4

  @center_y = CENTER_Y   # Center screen y-coordinate * 4

  #--------------------------------------------------------------------------

  # * Scroll Down

  #--------------------------------------------------------------------------

  def update_scroll_down(last_real_y)

    # If character moves down and is positioned lower than the center

    # of the screen

    if @real_y > last_real_y and @real_y - $game_map.display_y > @center_y

      # Scroll map down

      $game_map.scroll_down(@real_y - last_real_y)

    end

  end

  #--------------------------------------------------------------------------

  # * Scroll Left

  #--------------------------------------------------------------------------

  def update_scroll_left(last_real_x)

    # If character moves left and is positioned more let on-screen than

    # center

    if @real_x < last_real_x and @real_x - $game_map.display_x < @center_x

      # Scroll map left

      $game_map.scroll_left(last_real_x - @real_x)

    end

  end

  #--------------------------------------------------------------------------

  # * Scroll Right

  #--------------------------------------------------------------------------

  def update_scroll_right(last_real_x)

    # If character moves right and is positioned more right on-screen than

    # center

    if @real_x > last_real_x and @real_x - $game_map.display_x > @center_x

      # Scroll map right

      $game_map.scroll_right(@real_x - last_real_x)

    end

  end

  #--------------------------------------------------------------------------

  # * Scroll Up

  #--------------------------------------------------------------------------

  def update_scroll_up(last_real_y)

    # If character moves up and is positioned higher than the center

    # of the screen

    if @real_y < last_real_y and @real_y - $game_map.display_y < @center_y

      # Scroll map up

      $game_map.scroll_up(last_real_y - @real_y)

    end

  end

  #--------------------------------------------------------------------------

  # * Set Map Display Position to Center of Screen

  #--------------------------------------------------------------------------

  def center(x, y)

    @center_x= (320/$game_map.tilemap_settings.zoom_x - 16) * 4   # Center screen x-coordinate * 4

    @center_y = (240/$game_map.tilemap_settings.zoom_y - 16) * 4   # Center screen y-coordinate * 4

    max_x = ($game_map.width*$game_map.tilemap_settings.zoom_x - 20) * 128/$game_map.tilemap_settings.zoom_x

    max_y = ($game_map.height*$game_map.tilemap_settings.zoom_y - 15) * 128/$game_map.tilemap_settings.zoom_y

    $game_map.display_x = ([0, [x * 128 - @center_x, max_x].min].max)

    $game_map.display_y = ([0, [y * 128 - @center_y, max_y].min].max)

  end

end

 

#=================================

# THIRD PART

#=================================

 

=begin

==============================================================================

 ** Map_Zoom

------------------------------------------------------------------------------

 Trebor777

 Version 1.1

 14/06/2007

------------------------------------------------------------------------------

 * Description FR:

 

   Ce script permet d'effectuer des zoom in et zoom out sur un point précis de

   la map.

 

 * Description US:

 

   This script allow you to zoom in or out on a specific map location.

 

------------------------------------------------------------------------------

 * Instructions FR:

 

   Placer le Script sous le SDK et au dessus de Main.

   Utiliser 1 des 2 commandes dans un script ou un évènement "appeler un script":

    .  $game_map.start_zoom(x,y,coef,spd)

    .  $scene.zoom(x,y,coef,spd) #avec $scene une instance de Scene_Map

 

   x et y: Coordonnées(pas en pixel) du point à zoomer/dézoomer

   coef  : Valeur du zoom à atteindre de 0.1, à l'infini

   spd   : Vitesse du zoom, la variation est basée sur le calcul suivant:

           0.2*spd

 

 * Instructions US:

 

   Place The Script Below the SDK and Above Main.

   Use 1 of this 2 command in a script or with the event command "Call a script":

    .  $game_map.start_zoom(x,y,coef,spd)

    .  $scene.zoom(x,y,coef,spd) #with $scene a Scene_Map instance

 

   x & y: Target Location(not inpixel)to zoom in/out

   coef  : Zoom value to reach from 0.1, to infinite

   spd   : Zoom speed, the fluctuation is based on this formula: 0.2*spd

           

 Version 1.1

   Code adapted to the new tilemap class.

==============================================================================

=end

 

 

#==============================================================================

# ** Spriteset_Map

#==============================================================================

class Spriteset_Map

  alias_method :zoom_update, :update  unless $@

  def update

    # Run the original update

    zoom_update

    # Update character sprites

    for sprite in @character_sprites

      sprite.zoom_x=$game_map.tilemap_settings.zoom_x

      sprite.zoom_y=$game_map.tilemap_settings.zoom_y

      sprite.update

    end

  end

end

 

 

 

#==============================================================================

# ** Scene_Map

#==============================================================================

class Scene_Map

  def zoom(x,y,coef,spd)

    if !$game_map.zooming?

      $game_map.start_zoom(x,y,coef,spd)

    end

  end

  def zoom_d(x,y,coef)

    if !$game_map.zooming?

      $game_map.default_zoom(x,y,coef)

    end

  end

end

 

 

 

#==============================================================================

# ** Game_Map

#==============================================================================

class Game_Map

  #--------------------------------------------------------------------------

  alias zoom_setup_scroll setup  unless $@

  def setup(*args)

    setup_zoom

    return zoom_setup_scroll(*args)

  end

  #--------------------------------------------------------------------------

  def setup_zoom

    # Initialize scroll information

    @zoom_rest = 0

    @zoom_speed = 2

  end

  #--------------------------------------------------------------------------

  # * Start Zoom

  #     focus  : zoom value to reach

  #     speed  : zoom speed

  #--------------------------------------------------------------------------

  def start_zoom(x,y,focus, speed)

    if x > 0

      @x_zoom=x

    elsif x < 0

      @x_zoom=@events[-x].x

    else

      @x_zoom=$game_player.x

    end

    if y > 0

      @y_zoom=y

    elsif y < 0

      @y_zoom=@events[-y].y

    else

      @y_zoom=$game_player.y

    end

    @zoom_rest = (focus-@tilemap_settings.zoom_x).abs

    @zoom_speed = speed*((focus-@tilemap_settings.zoom_x)/@zoom_rest)

  end

  ###########################################################################

  def default_zoom(x,y,coef)

    if x > 0

      @x_zoom=x

    elsif x < 0

      @x_zoom=@events[-x].x

    else

      @x_zoom=$game_player.x

    end

    if y > 0

      @y_zoom=y

    elsif y < 0

      @y_zoom=@events[-y].y

    else

      @y_zoom=$game_player.y

    end

    $game_map.tilemap_settings.zoom_x = coef

    $game_map.tilemap_settings.zoom_y = coef

    $game_player.center(@x_zoom,@y_zoom)

    @zoom_rest = 0

  end

  #--------------------------------------------------------------------------

  # * Determine if Scrolling

  #--------------------------------------------------------------------------

  def zooming?

    return @zoom_rest > 0

  end

  #--------------------------------------------------------------------------

  alias zoom_update_scrolling update

  def update

    zoom_update_scrolling

    update_zooming

  end

  #--------------------------------------------------------------------------

  def update_zooming

    # If zooming

    @zoom_rest = 0 if @zoom_rest.nil?

    if @zoom_rest > 0

      # Change from zoom speed to focus in map coordinates

      focus = 0.2 * @zoom_speed

      # Execute zooming

      @tilemap_settings.zoom_x+=focus

      @tilemap_settings.zoom_y+=focus

      # Subtract focus zoomed

      @zoom_rest -= focus.abs

      $game_player.center(@x_zoom,@y_zoom)

    end

  end

  #--------------------------------------------------------------------------

  # * Scroll Down

  #     distance : scroll distance

  #--------------------------------------------------------------------------

  def scroll_down(distance)

    @display_y = [@display_y + distance, (self.height*@tilemap_settings.zoom_y - 15) * 128/tilemap_settings.zoom_y].min

  end

  #--------------------------------------------------------------------------

  # * Scroll Left

  #     distance : scroll distance

  #--------------------------------------------------------------------------

  def scroll_left(distance)

    @display_x = [@display_x - distance, 0].max

  end

  #--------------------------------------------------------------------------

  # * Scroll Right

  #     distance : scroll distance

  #--------------------------------------------------------------------------

  def scroll_right(distance)

    @display_x = [@display_x + distance, (self.width*@tilemap_settings.zoom_x - 20) * 128/tilemap_settings.zoom_x].min

  end

  #--------------------------------------------------------------------------

  # * Scroll Up

  #     distance : scroll distance

  #--------------------------------------------------------------------------

  def scroll_up(distance)

    @display_y = [@display_y - distance, 0].max

  end

end

Poccil's Tilemap class
Code:
class CustomTilemapAutotiles

  attr_accessor :changed

  def initialize

   @changed=true

   @tiles=[nil,nil,nil,nil,nil,nil,nil]

  end

  def []=(i,value)

   @tiles[i]=value

   @changed=true

  end

  def [](i)

   return @tiles[i]

  end

end

 

class TilemapNEW

  Animated_Autotiles_Frames = 15

  Autotiles = [

    [ [27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],

      [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12] ],

    [ [27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],

      [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12] ],

    [ [25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],

      [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],

    [ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],

      [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46] ],

    [ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],

      [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],

    [ [37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],

      [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8] ]

  ]

  FlashOpacity=[100,90,80,70,80,90]

  attr_reader :tileset

  attr_reader :autotiles

  attr_reader :map_data

  attr_accessor :flash_data

  attr_accessor :priorities

  attr_reader :visible

  attr_accessor :ox

  attr_accessor :oy

  attr_reader :viewport

  def initialize(viewport)

    @tileset    = nil  # Refers to Map Tileset Name

    @autotiles  = CustomTilemapAutotiles.new

    @map_data   = nil  # Refers to 3D Array Of Tile Settings

    @flash_data = nil  # Refers to 3D Array of Tile Flashdata

    @priorities = nil  # Refers to Tileset Priorities

    @visible    = true # Refers to Tileset Visibleness

    @ox         = 0    # Bitmap Offsets

    @oy         = 0    # bitmap Offsets

    @plane       = false

    @selfviewport=Viewport.new(0,0,640,480)

    @viewport=viewport ? viewport : @selfviewport

    @tiles=[]

    @autotileInfo=[]

    @regularTileInfo=[]

    @oldOx=0

    @oldOy=0

    @layer0=Sprite.new(viewport)

    @layer0.visible=true

    @nowshown=false

    @layer0.bitmap=Bitmap.new(@viewport.rect.width*2,@viewport.rect.height*2)

    @flash=nil

    @layer0.ox=0

    @layer0.oy=0

    @oxLayer0=0

    @oyLayer0=0

    @oxFlash=0

    @oyFlash=0

    @layer0.z=0

    @priotiles=[]

    @prioautotiles=[]

    @autosprites=[]

    @framecount=[]

    @tilesetChanged=true

    @flashChanged=false

    @firsttime=true

    @disposed=false

    @usedsprites=false

    @layer0clip=true

    @firsttimeflash=true

    @fullyrefreshed=false

    @fullyrefreshedautos=false

  end

  def disposed?

   return @disposed

  end

  def flash_data=(value)

   @flash_data=value

   @flashChanged=true  

  end

  def update

    if @autotiles.changed

      refresh_autotiles

      repaintAutotiles

    end

    if @flashChanged

      refresh_flash

    end

    if @tilesetChanged

      refresh_tileset

    end

    if @flash

     @flash.opacity=FlashOpacity[(Graphics.frame_count/2) % 6]

    end

    if !(@oldOx==@ox && @oldOy==@oy &&

           !@tilesetChanged &&

           !@autotiles.changed)

      refresh

    end

    if (Graphics.frame_count % Animated_Autotiles_Frames == 0) || @nowshown

      repaintAutotiles

      refresh(true)

    end

    @nowshown=false

    @autotiles.changed=false

    @tilesetChanged=false

  end

def priorities=(value)

  @priorities=value

  @tilesetChanged=true

end

def tileset=(value)

  @tileset=value

  @tilesetChanged=true

end

def shown?

   return false if !@visible

   ysize=@map_data.ysize

   xsize=@map_data.xsize

   xStart=(@ox/32)-1

   xEnd=((@ox+@viewport.rect.width)/32)+1

   yStart=(@oy/32)-1

   yEnd=((@oy+@viewport.rect.height)/32)+1

   xStart=0 if xStart<0

   xStart=xsize-1 if xStart>=xsize

   xEnd=0 if xEnd<0

   xEnd=xsize-1 if xEnd>=xsize

   yStart=0 if yStart<0

   yStart=ysize-1 if yStart>=ysize

   yEnd=0 if yEnd<0

   yEnd=ysize-1 if yEnd>=ysize

   return (xStart<xEnd && yStart<yEnd)

end

def dispose

return if disposed?

@help.dispose if @help

@help=nil

i=0;len=@autotileInfo.length;while i<len

  if @autotileInfo[i]

     @autotileInfo[i].dispose

     @autotileInfo[i]=nil

  end

  i+=1

end

i=0;len=@regularTileInfo.length;while i<len

  if @regularTileInfo[i]

     @regularTileInfo[i].dispose

     @regularTileInfo[i]=nil

  end

  i+=1

end

i=0;len=@tiles.length;while i<len

  @tiles[i].dispose

  @tiles[i]=nil

  i+=2

end

i=0;len=@autosprites.length;while i<len

  @autosprites[i].dispose

  @autosprites[i]=nil

  i+=2

end

if @layer0

  @layer0.bitmap.dispose if !@layer0.disposed?

  @layer0.bitmap=nil if !@layer0.disposed?

  @layer0.dispose

  @layer0=nil

end

if @flash

  @flash.bitmap.dispose if !@flash.disposed?

  @flash.bitmap=nil if !@flash.disposed?

  @flash.dispose

  @flash=nil

end

for i in 0...7

  self.autotiles[i]=nil

end

@tiles.clear

@autosprites.clear

@autotileInfo.clear

@regularTileInfo.clear

@tilemap=nil

@tileset=nil

@priorities=nil

@selfviewport.dispose

@selfviewport=nil

@disposed=true

end

 

def bltAutotile(bitmap,x,y,id,frame)

  return if frame<0

  autotile=@autotiles[id/48-1]

  return if !autotile

  if autotile.height==32

    anim=frame*32

    src_rect=Rect.new(anim,0,32,32)

    bitmap.blt(x,y,autotile,src_rect)

  else

    anim=frame*96

    id%=48

    tiles = Autotiles[id>>3][id&7]

    src=Rect.new(0,0,0,0)

    for i in 0...4

      tile_position = tiles[i] - 1

      src.set(tile_position % 6 * 16 + anim,

       tile_position / 6 * 16, 16, 16)

      bitmap.blt(i%2*16+x,i/2*16+y, autotile, src)

    end

  end

end

 

def autotileNumFrames(id)

  autotile=@autotiles[id/48-1]

  return 0 if !autotile || autotile.disposed?

  frames=1

  if autotile.height==32

   frames=autotile.width/32

  else

   frames=autotile.width/96

  end

  return frames

end

 

def autotileFrame(id)

  autotile=@autotiles[id/48-1]

  return -1 if !autotile || autotile.disposed?

  frames=1

  if autotile.height==32

   frames=autotile.width/32

  else

   frames=autotile.width/96

  end

  return (Graphics.frame_count/Animated_Autotiles_Frames)%frames

end

 

def repaintAutotiles

for i in [email=0...@autotileInfo.length]0...@autotileInfo.length[/email]

  next if !@autotileInfo[i]

  frame=autotileFrame(i)

  bltAutotile(@autotileInfo[i],0,0,i,frame)

end

end

 

def getAutotile(sprite,id)

  anim=autotileFrame(id)

  return if anim<0

  bitmap=@autotileInfo[id]

  if !bitmap

    bitmap=Bitmap.new(32,32)

    bltAutotile(bitmap,0,0,id,anim)

    @autotileInfo[id]=bitmap

  end

  sprite.bitmap=bitmap if !sprite.equal?(bitmap) || sprite.bitmap!=bitmap

end

 

def getRegularTile(sprite,id)

if false

  sprite.bitmap=@tileset if !sprite.equal?(@tileset) || sprite.bitmap!=@tileset

  sprite.src_rect.set((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)

else

  bitmap=@regularTileInfo[id]

  if !bitmap

   bitmap=Bitmap.new(32,32)

   rect=Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)

   bitmap.blt(0,0,@tileset,rect)

   @regularTileInfo[id]=bitmap

  end

  sprite.bitmap=bitmap if !sprite.equal?(bitmap) || sprite.bitmap!=bitmap

end

end

 

def addTile(tiles,count,xpos,ypos,id)

   if id>=384

     if count>=tiles.length

      sprite=Sprite.new(@viewport)

      tiles.push(sprite,0)

     else

      sprite=tiles[count]

      tiles[count+1]=0

     end

     sprite.visible=@visible

     sprite.x=xpos

     sprite.y=ypos

     getRegularTile(sprite,id)

     spriteZ=(@priorities[id]==0||!@priorities[id]) ? 0 : ypos+@priorities[id]*32+32

     sprite.z=spriteZ

     count+=2

   else

     if count>=tiles.length

      sprite=Sprite.new(@viewport)

      tiles.push(sprite,1)

     else

      sprite=tiles[count]

      tiles[count+1]=1

     end

     sprite.visible=@visible

     sprite.x=xpos

     sprite.y=ypos

     getAutotile(sprite,id)

     spriteZ=(@priorities[id]==0||!@priorities[id]) ? 0 : ypos+@priorities[id]*32+32

     sprite.z=spriteZ

     count+=2

   end

   return count

end

 

def refresh_tileset

i=0;len=@regularTileInfo.length;while i<len

  if @regularTileInfo[i]

     @regularTileInfo[i].dispose

     @regularTileInfo[i]=nil

  end

  i+=1

end

@regularTileInfo.clear

@priotiles.clear

ysize=@map_data.ysize

xsize=@map_data.xsize

zsize=@map_data.zsize

if xsize>100 || ysize>100

  @fullyrefreshed=false

else

  for z in 0...zsize

   for y in 0...ysize

    for x in 0...xsize

     id = @map_data[x, y, z]

     next if id==0 || !@priorities[id]

     next if @priorities[id]==0

     @priotiles.push([x,y,z,id])

    end

   end

  end

  @fullyrefreshed=true

end

end

 

def refresh_flash

if @flash_data && !@flash

  @flash=Sprite.new(viewport)

  @flash.visible=true

  @flash.z=1

  @flash.blend_type=1

  @flash.bitmap=Bitmap.new(@viewport.rect.width*2,@viewport.rect.height*2)

  @firsttimeflash=true

elsif !@flash_data && @flash

  @flash.bitmap.dispose if @flash.bitmap

  @flash.dispose

  @flash=nil

  @firsttimeflash=false

end

end

 

def refresh_autotiles

i=0;len=@autotileInfo.length;while i<len

  if @autotileInfo[i]

     @autotileInfo[i].dispose

     @autotileInfo[i]=nil

  end

  i+=1

end

i=0;len=@autosprites.length;while i<len

  if @autosprites[i]

     @autosprites[i].dispose

     @autosprites[i]=nil

  end

  i+=2

end

@autosprites.clear

@autotileInfo.clear

@prioautotiles.clear

hasanimated=false

for i in 0...7

  numframes=autotileNumFrames(48*(i+1))

  hasanimated=true if numframes>=2

  @framecount[i]=numframes

end

if hasanimated

  ysize=@map_data.ysize

  xsize=@map_data.xsize

  zsize=@map_data.zsize

  if xsize>100 || ysize>100

    @fullyrefreshedautos=false

  else

    for y in 0...ysize

     for x in 0...xsize

      haveautotile=false

      for z in 0...zsize

       id = @map_data[x, y, z]

       next if id==0 || id>=384 || @priorities[id]!=0 || !@priorities[id]

       next if @framecount[id/48-1]<2

       haveautotile=true

       break

      end

      @prioautotiles.push([x,y]) if haveautotile

     end

    end

    @fullyrefreshedautos=true

  end

else

  @fullyrefreshedautos=true

end

end

 

def map_data=(value)

@map_data=value

@tilesetChanged=true

end

 

def refreshFlashSprite

return if !@flash || @flash_data.nil?

ptX=@ox-@oxFlash

ptY=@oy-@oyFlash

if !@firsttimeflash && !@usedsprites &&

    ptX>=0 && [email=ptX+@viewport.rect.width]ptX+@viewport.rect.width[/email]<=@flash.bitmap.width &&

    ptY>=0 && [email=ptY+@viewport.rect.height]ptY+@viewport.rect.height[/email]<=@flash.bitmap.height

  @flash.ox=0

  @flash.oy=0

  @flash.src_rect.set(ptX.round,ptY.round,

     @viewport.rect.width,@viewport.rect.height)

  return

end

width=@flash.bitmap.width

height=@flash.bitmap.height

bitmap=@flash.bitmap

ysize=@map_data.ysize

xsize=@map_data.xsize

zsize=@map_data.zsize

@firsttimeflash=false

@oxFlash=@ox-(width>>2)

@oyFlash=@oy-(height>>2)

@flash.ox=0

@flash.oy=0

@flash.src_rect.set(width>>2,height>>2,

     @viewport.rect.width,@viewport.rect.height)

@flash.bitmap.clear

@oxFlash=@oxFlash.floor

@oyFlash=@oyFlash.floor

xStart=(@oxFlash>>5)

xStart=0 if xStart<0

yStart=(@oyFlash>>5)

yStart=0 if yStart<0

xEnd=xStart+(width>>5)+1

yEnd=yStart+(height>>5)+1

xEnd=xsize if xEnd>=xsize

yEnd=ysize if yEnd>=ysize

if xStart<xEnd && yStart<yEnd

  yrange=yStart...yEnd

  xrange=xStart...xEnd

  tmpcolor=Color.new(0,0,0,0)

  for y in yrange

   ypos=(y<<5)-@oyFlash

   for x in xrange

     xpos=(x<<5)-@oxFlash

     id = @flash_data[x, y, 0]

     r=(id>>8)&15

     g=(id>>4)&15

     b=(id)&15

     tmpcolor.set(r*16,g*16,b*16)

     bitmap.fill_rect(xpos,ypos,32,32,tmpcolor)

   end

  end

end

end

 

 

def refreshLayer0(autotiles=false)

ptX=@ox-@oxLayer0

ptY=@oy-@oyLayer0

if !autotiles && !@firsttime && !@usedsprites &&

    ptX>=0 && [email=ptX+@viewport.rect.width]ptX+@viewport.rect.width[/email]<=@layer0.bitmap.width &&

    ptY>=0 && [email=ptY+@viewport.rect.height]ptY+@viewport.rect.height[/email]<=@layer0.bitmap.height

  if @layer0clip

   @layer0.ox=0

   @layer0.oy=0

   @layer0.src_rect.set(ptX.round,ptY.round,

     @viewport.rect.width,@viewport.rect.height)

  else

   @layer0.ox=ptX.round

   @layer0.oy=ptY.round

   @layer0.src_rect.set(0,0,@layer0.bitmap.width,@layer0.bitmap.height)

  end

  return true

end

width=@layer0.bitmap.width

height=@layer0.bitmap.height

bitmap=@layer0.bitmap

ysize=@map_data.ysize

xsize=@map_data.xsize

zsize=@map_data.zsize

if autotiles

  return true if @fullyrefreshedautos && @prioautotiles.length==0

  return true if !shown?

  xStart=(@oxLayer0>>5)

  xStart=0 if xStart<0

  yStart=(@oyLayer0>>5)

  yStart=0 if yStart<0

  xEnd=xStart+(width>>5)+1

  yEnd=yStart+(height>>5)+1

  xEnd=xsize if xEnd>xsize

  yEnd=ysize if yEnd>ysize

  return true if xStart>=xEnd || yStart>=yEnd

  trans=Color.new(0,0,0,0)

  temprect=Rect.new(0,0,0,0)

  tilerect=Rect.new(0,0,32,32)

  range=0...zsize

  overallcount=0

  count=0

  if !@fullyrefreshedautos

   for y in yStart..yEnd

    for x in xStart..xEnd

     haveautotile=false

     for z in range

      id = @map_data[x, y, z]

      next if id<48 || id>=384 || @priorities[id]!=0 || !@priorities[id]

      next if @framecount[id/48-1]<2

      haveautotile=true

      break

     end

     next if !haveautotile

     overallcount+=1

     xpos=(x<<5)-@oxLayer0

     ypos=(y<<5)-@oyLayer0

     bitmap.fill_rect(xpos,ypos,0,0,trans) if overallcount<=2000

     for z in range

      id = @map_data[x,y,z]

      next if id<48 || @priorities[id]!=0 || !@priorities[id]

      if overallcount>2000

       count=addTile(@autosprites,count,xpos,ypos,id)

       next

      elsif id>=384

       temprect.set((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)

       bitmap.blt(xpos,ypos,@tileset,temprect)

      else

       tilebitmap=@autotileInfo[id]

       if !tilebitmap

        anim=autotileFrame(id)

        next if anim<0

        tilebitmap=Bitmap.new(32,32)

        bltAutotile(tilebitmap,0,0,id,anim)

        @autotileInfo[id]=tilebitmap

       end

       bitmap.blt(xpos,ypos,tilebitmap,tilerect)

      end

     end

    end

   end

  else

   for tile in @prioautotiles

    x=tile[0]

    y=tile[1]

    next if x<xStart||x>xEnd

    next if y<yStart||y>yEnd

    overallcount+=1

    xpos=(x<<5)-@oxLayer0

    ypos=(y<<5)-@oyLayer0

    bitmap.fill_rect(xpos,ypos,0,0,trans) if overallcount<=2000

    for z in range

     id = @map_data[x,y,z]

     next if id<48 || @priorities[id]!=0 || !@priorities[id]

     if overallcount>2000

      count=addTile(@autosprites,count,xpos,ypos,id)

      next

     elsif id>=384

      temprect.set((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)

      bitmap.blt(xpos,ypos,@tileset,temprect)

     else

      tilebitmap=@autotileInfo[id]

      if !tilebitmap

        anim=autotileFrame(id)

        next if anim<0

        tilebitmap=Bitmap.new(32,32)

        bltAutotile(tilebitmap,0,0,id,anim)

        @autotileInfo[id]=tilebitmap

      end

      bitmap.blt(xpos,ypos,tilebitmap,tilerect)

     end

    end

   end

  end

  Graphics.frame_reset if overallcount>2000

  @usedsprites=false

  return true

end

return false if @usedsprites

@firsttime=false

@oxLayer0=@ox-(width>>2)

@oyLayer0=@oy-(height>>2)

if @layer0clip

  @layer0.ox=0

  @layer0.oy=0

  @layer0.src_rect.set(width>>2,height>>2,

     @viewport.rect.width,@viewport.rect.height)

else

  @layer0.ox=(width>>2)

  @layer0.oy=(height>>2)

end

@layer0.bitmap.clear

@oxLayer0=@oxLayer0.floor

@oyLayer0=@oyLayer0.floor

xStart=(@oxLayer0>>5)

xStart=0 if xStart<0

yStart=(@oyLayer0>>5)

yStart=0 if yStart<0

xEnd=xStart+(width>>5)+1

yEnd=yStart+(height>>5)+1

xEnd=xsize if xEnd>=xsize

yEnd=ysize if yEnd>=ysize

if xStart<xEnd && yStart<yEnd

  tmprect=Rect.new(0,0,0,0)

  yrange=yStart...yEnd

  xrange=xStart...xEnd

  for z in 0...zsize

   for y in yrange

    ypos=(y<<5)-@oyLayer0

    for x in xrange

     xpos=(x<<5)-@oxLayer0

     id = @map_data[x, y, z]

     next if id==0 || @priorities[id]!=0 || !@priorities[id]

     if id>=384

       tmprect.set((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)

       bitmap.blt(xpos,ypos,@tileset,tmprect)

     else

       frame=autotileFrame(id)

       bltAutotile(bitmap,xpos,ypos,id,frame)

     end

    end

   end

  end

  Graphics.frame_reset

end

return true

end

def getResizeFactor

  return $ResizeFactor ? $ResizeFactor : 1.0

end

def ox=(val)

   val=(val*getResizeFactor).to_i

   val=(val/getResizeFactor).to_i

   wasshown=self.shown?

   @ox=val.floor

   @nowshown=(!wasshown && self.shown?)

end

def oy=(val)

   val=(val*getResizeFactor).to_i

   val=(val/getResizeFactor).to_i

   wasshown=self.shown?

   @oy=val.floor

   @nowshown=(!wasshown && self.shown?)

end

def visible=(val)

   wasshown=@visible

   @visible=val

   @nowshown=(!wasshown && val)

end

def refresh(autotiles=false)

@oldOx=@ox

@oldOy=@oy

usesprites=false

if @layer0

  @layer0.visible=@visible

  usesprites=!refreshLayer0(autotiles)

  if autotiles && !usesprites

   return

  end

else

  usesprites=true

end

refreshFlashSprite

vpx=@viewport.rect.x

vpy=@viewport.rect.y

vpr=@viewport.rect.width+vpx

vpb=@viewport.rect.height+vpy

xsize=@map_data.xsize

ysize=@map_data.ysize

minX=(@ox/32)-1

maxX=((@ox+@viewport.rect.width)/32)+1

minY=(@oy/32)-1

maxY=((@oy+@viewport.rect.height)/32)+1

minX=0 if minX<0

minX=xsize-1 if minX>=xsize

maxX=0 if maxX<0

maxX=xsize-1 if maxX>=xsize

minY=0 if minY<0

minY=ysize-1 if minY>=ysize

maxY=0 if maxY<0

maxY=ysize-1 if maxY>=ysize

count=0

if minX<maxX && minY<maxY

  @usedsprites=usesprites || @usedsprites

  if @layer0

   @layer0.visible=false if usesprites

  end

  if @fullyrefreshed

   for prio in @priotiles

    next if prio[0]<minX||prio[0]>maxX

    next if prio[1]<minY||prio[1]>maxY

    id=prio[3]

    xpos=(prio[0]<<5)-@ox

    ypos=(prio[1]<<5)-@oy

    count=addTile(@tiles,count,xpos,ypos,id)

   end

  else

   for z in 0...@map_data.zsize

    for y in minY..maxY

     for x in minX..maxX

      id = @map_data[x, y, z]

      next if id==0 || !@priorities[id]

      next if @priorities[id]==0

      xpos=(x<<5)-@ox

      ypos=(y<<5)-@oy

      count=addTile(@tiles,count,xpos,ypos,id)

     end

    end

   end

  end

end

if count<@tiles.length

  bigchange=(count<=(@tiles.length*2/3)) && (@tiles.length*2/3)>25

  j=count;len=@tiles.length;while j<len

   sprite=@tiles[j]

   @tiles[j+1]=-1

   if bigchange

    sprite.dispose

    @tiles[j]=nil

    @tiles[j+1]=nil

   elsif !@tiles[j].disposed?

    sprite.visible=false if sprite.visible

   end

   j+=2

  end

  @tiles.compact! if bigchange

end

end

 

end

RTH's Tilemap class
Code:
#==============================================================================

# Tilemap

#------------------------------------------------------------------------------

# Author of THIS VERSION: RTH

#==============================================================================

 

class Tilemap

 

  # Autotile Update Rate

  AUTOTILE_UPDATE = 10

 

  # Autotiles Index (Dont Change these numbers)

  INDEX = [

    [ [27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],

      [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12] ],

    [ [27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],

      [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12] ],

    [ [25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],

      [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],

    [ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],

      [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46] ],

    [ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],

      [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],

    [ [37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],

      [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8] ]

  ]

 

  attr_accessor :ox

  attr_accessor :oy

  attr_accessor :tileset

  attr_accessor :autotiles

  attr_accessor :priorities

  attr_accessor :map_data

 

  def initialize(viewport)

    @viewport = viewport

    @swidth = (@viewport.rect.width / 32)

    @sheight = (@viewport.rect.height / 32)

    @data = nil

    @data_priorities = nil

    @priorities = nil

    @map_data = nil

    @tileset = nil

    @autotiles = []

    @sprites = {}

    @bitmaps = {}

    @cache = {}

    @need_counters = []

    @counter = []

    @max_counters = []

    @ox = 0

    @oy = 0

    @time_counter = 1

    @need_refresh = false

  end

 

  def refresh

    @need_refresh = false

    @table = Table.new(384)

    @size = 0

    @data = @map_data

    @data_priorities = @priorities

    min_x = [@ox / 32 - 1, 0].max

    min_y = [@oy / 32 - 1, 0].max

    max_x = [min_x + @swidth + 1 * 2, @data.xsize - 1].min

    max_y = [min_y + @sheight + 1 * 2, @data.ysize - 1].min

    (min_x..max_x).each {|x|

      (min_y..max_y).each {|y|

        (0..2).each {|z|

          tile_id = @data[x, y, z]

          next if tile_id == 0

          priority = @priorities[tile_id]

          key = [x, y, z, priority]

          @sprites[key] = Sprite.new(@viewport)

          @sprites[key].x = x * 32 - @ox

          @sprites[key].y = y * 32 - @oy

          @sprites[key].z = (y * 32 - @oy) + ((priority + 1) * 32)

          if tile_id < 384

            tile = get_autotile(tile_id)

          else

            tile = get_tile(tile_id)

          end

          @sprites[key].bitmap = tile

        }

      }

    }

  end

 

  def get_autotile(tile_id)

    if tile_id >= 384

      return get_tile(tile_id)

    end

    autotile = @autotiles[(tile_id/48) - 1]

    n = (autotile.width / 96)

    if @bitmaps[tile_id].nil?

      @bitmaps[tile_id] = []

    end

    if n > 1

      if @table[tile_id] == 0

        @counter[tile_id] = 0

        @max_counters[tile_id] = n

        @table[tile_id] = 1

        @size += 1

      end

    end

    for i in 0...n

      @bitmaps[tile_id][i] = get_tile(tile_id, i)

    end

    if @counter[tile_id].nil?

      return @bitmaps[tile_id][0]

    end

    return @bitmaps[tile_id][@counter[tile_id]]

  end

 

  def get_tile(tile_id, c=0)

    key = [tile_id, c]

    if @cache[key].nil?

      @cache[key] = Bitmap.new(32, 32)

      if tile_id < 384

        anim = c * 96

        id = tile_id % 48

        tiles = INDEX[id >> 3][id % 8]

        autotile = @autotiles[(tile_id/48) - 1]

        for i in 0...4

          tile_position = tiles[i] - 1

          rect = Rect.new(tile_position % 6 * 16 + anim, tile_position / 6 * 16, 16, 16)

          @cache[key].blt((i%2) * 16, (i/2) * 16, autotile, rect)

        end

      else

        @cache[key].blt(0, 0, @tileset, Rect.new((tile_id - 384) % 8 * 32, (tile_id - 384) / 8 * 32, 32, 32))

      end

    end

    return @cache[key]

  end

 

  def tileset=(valor)

    for v in @cache.values

      v.dispose

    end

    @cache = {}

    @tileset = valor

    @need_refresh = true

  end

 

  def dispose

    @cache.values.each {|v| v.dispose }

    @cache = {}

    @bitmaps.values.each {|a|

      next if a.nil?

      a.each {|v|

        next if v.nil?

        v.dispose unless v.disposed?

      }

    }

    @sprites.values.each {|sprite|

      next if sprite.nil?

      sprite.dispose

    }

    @sprites = {}

  end

 

  def update

    if @data != @map_data or @priorities != @data_priorities or @need_refresh

      refresh

      return

    end

    min_x = [@ox / 32 - 1, 0].max

    min_y = [@oy / 32 - 1, 0].max

    max_x = [min_x + @swidth + 1 * 2, @data.xsize - 1].min

    max_y = [min_y + @sheight + 1 * 2, @data.ysize - 1].min

    if AUTOTILE_UPDATE > 0

      @time_counter = (@time_counter + 1) % AUTOTILE_UPDATE

    end

    checked = []

    for x in min_x..max_x

      rx = ((x * 32) - @ox)

      cx = (rx < 0 or rx > (@swidth - 32))

      ax = (((rx + 32) < 0) or (rx > @viewport.rect.width))

      for y in min_y..max_y

        ry = ((y * 32) - @oy)

        cy = (ry < 0 or ry > (@sheight - 32))

        ay = (((ry + 32) < 0) or (ry > @viewport.rect.height))

        for z in 0..2

          tile_id = @data[x, y, z]

          next if tile_id == 0

          priority = @priorities[tile_id]

          key = [x, y, z, priority]

          if ay or ax

            if @sprites[key] != nil

              @sprites[key].dispose

              @sprites[key] = nil

            end

            next

          end

          if @sprites[key].nil?

            @sprites[key] = Sprite.new(@viewport)

            @sprites[key].x = rx

            @sprites[key].y = ry

            @sprites[key].z = ry + ((priority + 1) * 32)

            if tile_id < 384

              tile = get_autotile(tile_id)

            else

              tile = get_tile(tile_id)

            end

            @sprites[key].bitmap = tile

            next

          end

          if @changed_ox or cy

            if @sprites[key].x != rx

              @sprites[key].x = rx

            end

          end

          if @changed_oy or cx

            if @sprites[key].y != ry

              @sprites[key].y = ry

              @sprites[key].z = ry + ((priority + 1) * 32)

            end

          end

          next if (@time_counter != 0)

          if @table[tile_id] == 1

            if checked[tile_id] != true

              @counter[tile_id] = (@counter[tile_id] + 1) % @max_counters[tile_id]

              checked[tile_id] = true

            end

            @sprites[key].bitmap = @bitmaps[tile_id][@counter[tile_id]]

          end

        end

      end

    end

    if @changed_ox

      @changed_ox = false

    end

    if @changed_oy

      @changed_oy = false

    end

  end

 

  def ox=(valor)

    return if @ox == valor

    @ox = valor

    @changed_ox = true

  end

 

  def oy=(valor)

    return if @oy == valor

    @oy = valor

    @changed_oy = true

  end

 

end

ok, this is all!! ^_^
Maybe it's not so easy to understand what i need, i'll make an example...
immaginedrn.png

See? that piece of green has Layer priority 1*
this mean that if my character is in the same spot of (or above) that tile, this will be showed over me, if instead i'm located under that piece of green, the character must be showed over the tile.
for a general rule:
TILE's layer priority = N
if ((Y of an Event < Y of the tile + N) and N!=0)
TILE's Z > Event's Z
else
TILE's Z < Event's Z

surely there's no need to explain it XD but to avoid question such as "what do you mean", "can you explain this layer priority thing" or others... i've write it XD
It's been a long time since my last script work... so i'm not good at this anymore... i hope that someone out there can help!! :) thanks!! :D
 
Ok, i've done quite everything... there's only one problem left for the smoothness, and some random glitch around the map (when you zoom IN or OUT) i'll post all the class that i've edited, i hope that at least whit this someone will find the freetime to help me out XD also thinking that after that i'll post this script to the public: a Zoom script without the SDK.

Game_Map
Code:
#==============================================================================

# ** Game_Map

#------------------------------------------------------------------------------

#  This class handles the map. It includes scrolling and passable determining

#  functions. Refer to "$game_map" for the instance of this class.

#==============================================================================

class Game_Map

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_accessor :tileset_name             # tileset file name

  attr_accessor :autotile_names           # autotile file name

  attr_accessor :panorama_name            # panorama file name

  attr_accessor :panorama_hue             # panorama hue

  attr_accessor :fog_name                 # fog file name

  attr_accessor :fog_hue                  # fog hue

  attr_accessor :fog_opacity              # fog opacity level

  attr_accessor :fog_blend_type           # fog blending method

  attr_accessor :fog_zoom                 # fog zoom rate

  attr_accessor :fog_sx                   # fog sx

  attr_accessor :fog_sy                   # fog sy

  attr_accessor :battleback_name          # battleback file name

  attr_accessor :display_x                # display x-coordinate * 128

  attr_accessor :display_y                # display y-coordinate * 128

  attr_accessor :need_refresh             # refresh request flag

  attr_accessor :tilemap_settings

  attr_reader   :passages                 # passage table

  attr_reader   :priorities               # prioroty table

  attr_reader   :terrain_tags             # terrain tag table

  attr_reader   :events                   # events

  attr_reader   :fog_ox                   # fog x-coordinate starting point

  attr_reader   :fog_oy                   # fog y-coordinate starting point

  attr_reader   :fog_tone                 # fog color tone

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    @map_id = 0

    @display_x = 0

    @display_y = 0

################################################################################

    @tilemap_settings = Tilemap_Settings.new

################################################################################

  end

  #--------------------------------------------------------------------------

  # * Setup

  #     map_id : map ID

  #--------------------------------------------------------------------------

  def setup(map_id)

    # Put map ID in @map_id memory

    @map_id = map_id

    # Load map from file and set @map

    @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))

    # set tile set information in opening instance variables

    tileset = $data_tilesets[@map.tileset_id]

    @tileset_name = tileset.tileset_name

    @autotile_names = tileset.autotile_names

    @panorama_name = tileset.panorama_name

    @panorama_hue = tileset.panorama_hue

    @fog_name = tileset.fog_name

    @fog_hue = tileset.fog_hue

    @fog_opacity = tileset.fog_opacity

    @fog_blend_type = tileset.fog_blend_type

    @fog_zoom = tileset.fog_zoom

    @fog_sx = tileset.fog_sx

    @fog_sy = tileset.fog_sy

    @battleback_name = tileset.battleback_name

    @passages = tileset.passages

    @priorities = tileset.priorities

    @terrain_tags = tileset.terrain_tags

    # Initialize displayed coordinates

    @display_x = 0

    @display_y = 0

    # Clear refresh request flag

    @need_refresh = false

    # Set map event data

    @events = {}

    for i in @map.events.keys

      @events[i] = Game_Event.new(@map_id, @map.events[i])

    end

    # Set common event data

    @common_events = {}

    for i in 1...$data_common_events.size

      @common_events[i] = Game_CommonEvent.new(i)

    end

    # Initialize all fog information

    @fog_ox = 0

    @fog_oy = 0

    @fog_tone = Tone.new(0, 0, 0, 0)

    @fog_tone_target = Tone.new(0, 0, 0, 0)

    @fog_tone_duration = 0

    @fog_opacity_duration = 0

    @fog_opacity_target = 0

    # Initialize scroll information

    @scroll_direction = 2

    @scroll_rest = 0

    @scroll_speed = 4

################################################################################

    # Initialize zoom information

    @zoom_rest = 0

    @zoom_speed = 2

    @tilemap_settings = Tilemap_Settings.new

    @tilemap_settings.map = @map

################################################################################

  end

################################################################################

  #--------------------------------------------------------------------------

  # * Start Zoom

  #     focus  : zoom value to reach

  #     speed  : zoom speed

  #--------------------------------------------------------------------------

  def start_zoom(x,y,focus, speed)

    if x > 0

      @x_zoom=x

    elsif x < 0

      @x_zoom=@events[-x].x

    else

      @x_zoom=$game_player.x

    end

    if y > 0

      @y_zoom=y

    elsif y < 0

      @y_zoom=@events[-y].y

    else

      @y_zoom=$game_player.y

    end

    @zoom_rest = (focus-@tilemap_settings.zoom_x).abs

    @zoom_speed = speed*((focus-@tilemap_settings.zoom_x)/@zoom_rest)

  end

  def default_zoom(x,y,coef)

    if x > 0

      @x_zoom=x

    elsif x < 0

      @x_zoom=@events[-x].x

    else

      @x_zoom=$game_player.x

    end

    if y > 0

      @y_zoom=y

    elsif y < 0

      @y_zoom=@events[-y].y

    else

      @y_zoom=$game_player.y

    end

    $game_map.tilemap_settings.zoom_x = coef

    $game_map.tilemap_settings.zoom_y = coef

    $game_player.center(@x_zoom,@y_zoom)

    @zoom_rest = 0

  end

  #--------------------------------------------------------------------------

  # * Determine if Zooming

  #--------------------------------------------------------------------------

  def zooming?

    return @zoom_rest > 0

  end

################################################################################

  #--------------------------------------------------------------------------

  # * Get Map ID

  #--------------------------------------------------------------------------

  def map_id

    return @map_id

  end

  #--------------------------------------------------------------------------

  # * Get Width

  #--------------------------------------------------------------------------

  def width

    return @map.width

  end

  #--------------------------------------------------------------------------

  # * Get Height

  #--------------------------------------------------------------------------

  def height

    return @map.height

  end

  #--------------------------------------------------------------------------

  # * Get Encounter List

  #--------------------------------------------------------------------------

  def encounter_list

    return @map.encounter_list

  end

  #--------------------------------------------------------------------------

  # * Get Encounter Steps

  #--------------------------------------------------------------------------

  def encounter_step

    return @map.encounter_step

  end

  #--------------------------------------------------------------------------

  # * Get Map Data

  #--------------------------------------------------------------------------

  def data

    return @map.data

  end

  #--------------------------------------------------------------------------

  # * Automatically Change Background Music and Backround Sound

  #--------------------------------------------------------------------------

  def autoplay

    if @map.autoplay_bgm

      $game_system.bgm_play(@map.bgm)

    end

    if @map.autoplay_bgs

      $game_system.bgs_play(@map.bgs)

    end

  end

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    # If map ID is effective

    if @map_id > 0

      # Refresh all map events

      for event in @events.values

        event.refresh

      end

      # Refresh all common events

      for common_event in @common_events.values

        common_event.refresh

      end

    end

    # Clear refresh request flag

    @need_refresh = false

  end

  #--------------------------------------------------------------------------

  # * Scroll Down

  #     distance : scroll distance

  #--------------------------------------------------------------------------

  def scroll_down(distance)

    @display_y = [@display_y + distance, (self.height*@tilemap_settings.zoom_y - 15) * 128/tilemap_settings.zoom_y].min

  end

  #--------------------------------------------------------------------------

  # * Scroll Left

  #     distance : scroll distance

  #--------------------------------------------------------------------------

  def scroll_left(distance)

    @display_x = [@display_x - distance, 0].max

  end

  #--------------------------------------------------------------------------

  # * Scroll Right

  #     distance : scroll distance

  #--------------------------------------------------------------------------

  def scroll_right(distance)

    @display_x = [@display_x + distance, (self.width*@tilemap_settings.zoom_x - 20) * 128/tilemap_settings.zoom_x].min

  end

  #--------------------------------------------------------------------------

  # * Scroll Up

  #     distance : scroll distance

  #--------------------------------------------------------------------------

  def scroll_up(distance)

    @display_y = [@display_y - distance, 0].max

  end

  #--------------------------------------------------------------------------

  # * Determine Valid Coordinates

  #     x          : x-coordinate

  #     y          : y-coordinate

  #--------------------------------------------------------------------------

  def valid?(x, y)

    return (x >= 0 and x < width and y >= 0 and y < height)

  end

  #--------------------------------------------------------------------------

  # * Determine if Passable

  #     x          : x-coordinate

  #     y          : y-coordinate

  #     d          : direction (0,2,4,6,8,10)

  #                  *  0,10 = determine if all directions are impassable

  #     self_event : Self (If event is determined passable)

  #--------------------------------------------------------------------------

  def passable?(x, y, d, self_event = nil)

    # If coordinates given are outside of the map

    unless valid?(x, y)

      # impassable

      return false

    end

    # Change direction (0,2,4,6,8,10) to obstacle bit (0,1,2,4,8,0)

    bit = (1 << (d / 2 - 1)) & 0x0f

    # Loop in all events

    for event in events.values

      # If tiles other than self are consistent with coordinates

      if event.tile_id >= 0 and event != self_event and

         event.x == x and event.y == y and not event.through

        # If obstacle bit is set

        if @passages[event.tile_id] & bit != 0

          # impassable

          return false

        # If obstacle bit is set in all directions

        elsif @passages[event.tile_id] & 0x0f == 0x0f

          # impassable

          return false

        # If priorities other than that are 0

        elsif @priorities[event.tile_id] == 0

          # passable

          return true

        end

      end

    end

    # Loop searches in order from top of layer

    for i in [2, 1, 0]

      # Get tile ID

      tile_id = data[x, y, i]

      # Tile ID acquistion failure

      if tile_id == nil

        # impassable

        return false

      # If obstacle bit is set

      elsif @passages[tile_id] & bit != 0

        # impassable

        return false

      # If obstacle bit is set in all directions

      elsif @passages[tile_id] & 0x0f == 0x0f

        # impassable

        return false

      # If priorities other than that are 0

      elsif @priorities[tile_id] == 0

        # passable

        return true

      end

    end

    # passable

    return true

  end

  #--------------------------------------------------------------------------

  # * Determine Thicket

  #     x          : x-coordinate

  #     y          : y-coordinate

  #--------------------------------------------------------------------------

  def bush?(x, y)

    if @map_id != 0

      for i in [2, 1, 0]

        tile_id = data[x, y, i]

        if tile_id == nil

          return false

        elsif @passages[tile_id] & 0x40 == 0x40

          return true

        end

      end

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Determine Counter

  #     x          : x-coordinate

  #     y          : y-coordinate

  #--------------------------------------------------------------------------

  def counter?(x, y)

    if @map_id != 0

      for i in [2, 1, 0]

        tile_id = data[x, y, i]

        if tile_id == nil

          return false

        elsif @passages[tile_id] & 0x80 == 0x80

          return true

        end

      end

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Get Terrain Tag

  #     x          : x-coordinate

  #     y          : y-coordinate

  #--------------------------------------------------------------------------

  def terrain_tag(x, y)

    if @map_id != 0

      for i in [2, 1, 0]

        tile_id = data[x, y, i]

        if tile_id == nil

          return 0

        elsif @terrain_tags[tile_id] > 0

          return @terrain_tags[tile_id]

        end

      end

    end

    return 0

  end

  #--------------------------------------------------------------------------

  # * Get Designated Position Event ID

  #     x          : x-coordinate

  #     y          : y-coordinate

  #--------------------------------------------------------------------------

  def check_event(x, y)

    for event in $game_map.events.values

      if event.x == x and event.y == y

        return event.id

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Start Scroll

  #     direction : scroll direction

  #     distance  : scroll distance

  #     speed     : scroll speed

  #--------------------------------------------------------------------------

  def start_scroll(direction, distance, speed)

    @scroll_direction = direction

    @scroll_rest = distance * 128

    @scroll_speed = speed

  end

  #--------------------------------------------------------------------------

  # * Determine if Scrolling

  #--------------------------------------------------------------------------

  def scrolling?

    return @scroll_rest > 0

  end

  #--------------------------------------------------------------------------

  # * Start Changing Fog Color Tone

  #     tone     : color tone

  #     duration : time

  #--------------------------------------------------------------------------

  def start_fog_tone_change(tone, duration)

    @fog_tone_target = tone.clone

    @fog_tone_duration = duration

    if @fog_tone_duration == 0

      @fog_tone = @fog_tone_target.clone

    end

  end

  #--------------------------------------------------------------------------

  # * Start Changing Fog Opacity Level

  #     opacity  : opacity level

  #     duration : time

  #--------------------------------------------------------------------------

  def start_fog_opacity_change(opacity, duration)

    @fog_opacity_target = opacity * 1.0

    @fog_opacity_duration = duration

    if @fog_opacity_duration == 0

      @fog_opacity = @fog_opacity_target

    end

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # Refresh map if necessary

    if $game_map.need_refresh

      refresh

    end

    # If scrolling

    if @scroll_rest > 0

      # Change from scroll speed to distance in map coordinates

      distance = 2 ** @scroll_speed

      # Execute scrolling

      case @scroll_direction

      when 2  # Down

        scroll_down(distance)

      when 4  # Left

        scroll_left(distance)

      when 6  # Right

        scroll_right(distance)

      when 8  # Up

        scroll_up(distance)

      end

      # Subtract distance scrolled

      @scroll_rest -= distance

    end

    # Update map event

    for event in @events.values

      event.update

    end

    # Update common event

    for common_event in @common_events.values

      common_event.update

    end

    # Manage fog scrolling

    @fog_ox -= @fog_sx / 8.0

    @fog_oy -= @fog_sy / 8.0

    # Manage change in fog color tone

    if @fog_tone_duration >= 1

      d = @fog_tone_duration

      target = @fog_tone_target

      @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d

      @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d

      @fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d

      @fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d

      @fog_tone_duration -= 1

    end

    # Manage change in fog opacity level

    if @fog_opacity_duration >= 1

      d = @fog_opacity_duration

      @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d

      @fog_opacity_duration -= 1

    end

################################################################################

    @zoom_rest = 0 if @zoom_rest.nil?

    if @zoom_rest > 0

      # Change from zoom speed to focus in map coordinates

      focus = 0.1 * @zoom_speed

      # Execute zooming

      @tilemap_settings.zoom_x+=focus

      @tilemap_settings.zoom_y+=focus

      # Subtract focus zoomed

      @zoom_rest -= focus.abs

      $game_player.center(@x_zoom,@y_zoom)

    end

################################################################################

  end

end

Game_Character
Code:
#==============================================================================

# ** Game_Character (part 1)

#------------------------------------------------------------------------------

#  This class deals with characters. It's used as a superclass for the

#  Game_Player and Game_Event classes.

#==============================================================================

 

class Game_Character

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_reader   :id                       # ID

  attr_reader   :x                        # map x-coordinate (logical)

  attr_reader   :y                        # map y-coordinate (logical)

  attr_reader   :real_x                   # map x-coordinate (real * 128)

  attr_reader   :real_y                   # map y-coordinate (real * 128)

  attr_reader   :tile_id                  # tile ID (invalid if 0)

  attr_reader   :character_name           # character file name

  attr_reader   :character_hue            # character hue

  attr_reader   :opacity                  # opacity level

  attr_reader   :blend_type               # blending method

  attr_reader   :direction                # direction

  attr_reader   :pattern                  # pattern

  attr_reader   :move_route_forcing       # forced move route flag

  attr_reader   :through                  # through

  attr_accessor :animation_id             # animation ID

  attr_accessor :transparent              # transparent flag

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    @id = 0

    @x = 0

    @y = 0

    @real_x = 0

    @real_y = 0

    @tile_id = 0

    @character_name = ""

    @character_hue = 0

    @opacity = 255

    @blend_type = 0

    @direction = 2

    @pattern = 0

    @move_route_forcing = false

    @through = false

    @animation_id = 0

    @transparent = false

    @original_direction = 2

    @original_pattern = 0

    @move_type = 0

    @move_speed = 4

    @move_frequency = 6

    @move_route = nil

    @move_route_index = 0

    @original_move_route = nil

    @original_move_route_index = 0

    @walk_anime = true

    @step_anime = false

    @direction_fix = false

    @always_on_top = false

    @anime_count = 0

    @stop_count = 0

    @jump_count = 0

    @jump_peak = 0

    @wait_count = 0

    @locked = false

    @prelock_direction = 0

  end

  #--------------------------------------------------------------------------

  # * Determine if Moving

  #--------------------------------------------------------------------------

  def moving?

    # If logical coordinates differ from real coordinates,

    # movement is occurring.

    return (@real_x != @x * 128 or @real_y != @y * 128)

  end

  #--------------------------------------------------------------------------

  # * Determine if Jumping

  #--------------------------------------------------------------------------

  def jumping?

    # A jump is occurring if jump count is larger than 0

    return @jump_count > 0

  end

  #--------------------------------------------------------------------------

  # * Straighten Position

  #--------------------------------------------------------------------------

  def straighten

    # If moving animation or stop animation is ON

    if @walk_anime or @step_anime

      # Set pattern to 0

      @pattern = 0

    end

    # Clear animation count

    @anime_count = 0

    # Clear prelock direction

    @prelock_direction = 0

  end

  #--------------------------------------------------------------------------

  # * Force Move Route

  #     move_route : new move route

  #--------------------------------------------------------------------------

  def force_move_route(move_route)

    # Save original move route

    if @original_move_route == nil

      @original_move_route = @move_route

      @original_move_route_index = @move_route_index

    end

    # Change move route

    @move_route = move_route

    @move_route_index = 0

    # Set forced move route flag

    @move_route_forcing = true

    # Clear prelock direction

    @prelock_direction = 0

    # Clear wait count

    @wait_count = 0

    # Move cutsom

    move_type_custom

  end

  #--------------------------------------------------------------------------

  # * Determine if Passable

  #     x : x-coordinate

  #     y : y-coordinate

  #     d : direction (0,2,4,6,8)

  #         * 0 = Determines if all directions are impassable (for jumping)

  #--------------------------------------------------------------------------

  def passable?(x, y, d)

    # Get new coordinates

    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)

    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)

    # If coordinates are outside of map

    unless $game_map.valid?(new_x, new_y)

      # impassable

      return false

    end

    # If through is ON

    if @through

      # passable

      return true

    end

    # If unable to leave first move tile in designated direction

    unless $game_map.passable?(x, y, d, self)

      # impassable

      return false

    end

    # If unable to enter move tile in designated direction

    unless $game_map.passable?(new_x, new_y, 10 - d)

      # impassable

      return false

    end

    # Loop all events

    $game_map.events.each_value {|event|

      # If coordinates are consistent with move destination and through is OFF

      if event.x == new_x && event.y == new_y && !event.through

        # If self is event or partner graphic as character

        if self != $game_player || event.character_name != ''

          # impassable

          return false

        end

      end

    }

    # If player coordinates are consistent with move destination

    if $game_player.x == new_x && $game_player.y == new_y

      # If through is OFF and your own graphic is the character

      if !$game_player.through && @character_name != ''

        # impassable

        return false

      end

    end

    # passable

    return true

  end

  #--------------------------------------------------------------------------

  # * Lock

  #--------------------------------------------------------------------------

  def lock

    # If already locked

    if @locked

      # End method

      return

    end

    # Save prelock direction

    @prelock_direction = @direction

    # Turn toward player

    turn_toward_player

    # Set locked flag

    @locked = true

  end

  #--------------------------------------------------------------------------

  # * Determine if Locked

  #--------------------------------------------------------------------------

  def lock?

    return @locked

  end

  #--------------------------------------------------------------------------

  # * Unlock

  #--------------------------------------------------------------------------

  def unlock

    # If not locked

    unless @locked

      # End method

      return

    end

    # Clear locked flag

    @locked = false

    # If direction is not fixed and prelock direction is saved

    if !@direction_fix && @prelock_direction != 0

      # Restore prelock direction

      @direction = @prelock_direction

    end

  end

  #--------------------------------------------------------------------------

  # * Move to Designated Position

  #     x : x-coordinate

  #     y : y-coordinate

  #--------------------------------------------------------------------------

  def moveto(x, y)

    @x = x % $game_map.width

    @y = y % $game_map.height

    @real_x = @x * 128

    @real_y = @y * 128

    @prelock_direction = 0

  end

  #--------------------------------------------------------------------------

  # * Get Screen X-Coordinates

  #--------------------------------------------------------------------------

  def screen_x

    zx = $game_map.tilemap_settings.zoom_x

    # Get screen coordinates from real coordinates and map display position

    return (@real_x - $game_map.display_x + 3*zx) / 4*zx + 16*zx

  end

  #--------------------------------------------------------------------------

  # * Get Screen Y-Coordinates

  #--------------------------------------------------------------------------

  def screen_y

    zy = $game_map.tilemap_settings.zoom_y

    # Get screen coordinates from real coordinates and map display position

    y = (@real_y - $game_map.display_y + 3*zy) / 4*zy + 32*zy

    # Make y-coordinate smaller via jump count

    if @jump_count >= @jump_peak

      n = @jump_count - @jump_peak

    else

      n = @jump_peak - @jump_count

    end

    return y - (@jump_peak * @jump_peak - n * n) / 2

  end

  #--------------------------------------------------------------------------

  # * Get Screen Z-Coordinates

  #     height : character height

  #--------------------------------------------------------------------------

  def screen_z(height = 0)

    zy = $game_map.tilemap_settings.zoom_y

    # If display flag on closest surface is ON

    if @always_on_top

      # 999, unconditional

      return 999

    end

    # Get screen coordinates from real coordinates and map display position

    z = (@real_y - $game_map.display_y + 3*zy) / 4*zy + 32*zy

    # If tile

    if @tile_id > 0

      # Add tile priority * 32

      return z + $game_map.priorities[@tile_id] * 32*zy

    # If character

    else

      # If height exceeds 32, then add 31

      return z + ((height > 32) ? 31 : 0)

    end

  end

  #--------------------------------------------------------------------------

  # * Get Thicket Depth

  #--------------------------------------------------------------------------

  def bush_depth

    # If tile, or if display flag on the closest surface is ON

    if @tile_id > 0 or @always_on_top

      return 0

    end

    # If element tile other than jumping, then 12; anything else = 0

    return (@jump_count == 0 && $game_map.bush?(@x, @y)) ? 12 : 0

  end

  #--------------------------------------------------------------------------

  # * Get Terrain Tag

  #--------------------------------------------------------------------------

  def terrain_tag

    return $game_map.terrain_tag(@x, @y)

  end

end

Spriteset_Map
Code:
#==============================================================================

# ** Spriteset_Map

#------------------------------------------------------------------------------

#  This class brings together map screen sprites, tilemaps, etc.

#  It's used within the Scene_Map class.

#==============================================================================

class Spriteset_Map

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    # Make viewports

    @viewport1 = Viewport.new(0, 0, 640, 480)

    @viewport2 = Viewport.new(0, 0, 640, 480)

    @viewport3 = Viewport.new(0, 0, 640, 480)

    @viewport2.z = 200

    @viewport3.z = 5000

    # Make tilemap

    @tilemap = Tilemap.new(@viewport1)

    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)

    for i in 0..6

      autotile_name = $game_map.autotile_names[i]

      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)

    end

    @tilemap.map_data = $game_map.data

    @tilemap.priorities = $game_map.priorities

################################################################################

    # Set Tilemap Settings

    @tilemap.tilemap_settings = $game_map.tilemap_settings

################################################################################

    # Make panorama plane

    @panorama = Plane.new(@viewport1)

    @panorama.z = -1000

    # Make fog plane

    @fog = Plane.new(@viewport1)

    @fog.z = 3000

    # Make character sprites

    @character_sprites = []

    for i in $game_map.events.keys.sort

      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])

      @character_sprites.push(sprite)

    end

    @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))

    # Make weather

    @weather = RPG::Weather.new(@viewport1)

    # Make picture sprites

    @picture_sprites = []

    for i in 1..50

      @picture_sprites.push(Sprite_Picture.new(@viewport2,

        $game_screen.pictures[i]))

    end

    # Make timer sprite

    @timer_sprite = Sprite_Timer.new

    # Frame update

    update

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  def dispose

    # Dispose of tilemap

    @tilemap.tileset.dispose

    for i in 0..6

      @tilemap.autotiles[i].dispose

    end

    @tilemap.dispose

    # Dispose of panorama plane

    @panorama.dispose

    # Dispose of fog plane

    @fog.dispose

    # Dispose of character sprites

    for sprite in @character_sprites

      sprite.dispose

    end

    # Dispose of weather

    @weather.dispose

    # Dispose of picture sprites

    for sprite in @picture_sprites

      sprite.dispose

    end

    # Dispose of timer sprite

    @timer_sprite.dispose

    # Dispose of viewports

    @viewport1.dispose

    @viewport2.dispose

    @viewport3.dispose

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # If panorama is different from current one

    if @panorama_name != $game_map.panorama_name or

       @panorama_hue != $game_map.panorama_hue

      @panorama_name = $game_map.panorama_name

      @panorama_hue = $game_map.panorama_hue

      if @panorama.bitmap != nil

        @panorama.bitmap.dispose

        @panorama.bitmap = nil

      end

      if @panorama_name != ""

        @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)

      end

      Graphics.frame_reset

    end

    # If fog is different than current fog

    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue

      @fog_name = $game_map.fog_name

      @fog_hue = $game_map.fog_hue

      if @fog.bitmap != nil

        @fog.bitmap.dispose

        @fog.bitmap = nil

      end

      if @fog_name != ""

        @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)

      end

      Graphics.frame_reset

    end

    # Update tilemap

    @tilemap.ox = $game_map.display_x / 4 *$game_map.tilemap_settings.zoom_x

    @tilemap.oy = $game_map.display_y / 4 *$game_map.tilemap_settings.zoom_y

    @tilemap.update

    # Update panorama plane

    @panorama.ox = $game_map.display_x / 8

    @panorama.oy = $game_map.display_y / 8

    # Update fog plane

    @fog.zoom_x = $game_map.fog_zoom / 100.0

    @fog.zoom_y = $game_map.fog_zoom / 100.0

    @fog.opacity = $game_map.fog_opacity

    @fog.blend_type = $game_map.fog_blend_type

    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox

    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy

    @fog.tone = $game_map.fog_tone

    # Update character sprites

################################################################################

    for sprite in @character_sprites

      sprite.zoom_x = $game_map.tilemap_settings.zoom_x

      sprite.zoom_y = $game_map.tilemap_settings.zoom_y

      sprite.update

    end

################################################################################

    # Update weather graphic

    @weather.type = $game_screen.weather_type

    @weather.max = $game_screen.weather_max

    @weather.ox = $game_map.display_x / 4

    @weather.oy = $game_map.display_y / 4

    @weather.update

    # Update picture sprites

    for sprite in @picture_sprites

      sprite.update

    end

    # Update timer sprite

    @timer_sprite.update

    # Set screen color tone and shake position

    @viewport1.tone = $game_screen.tone

    @viewport1.ox = $game_screen.shake

    # Set screen flash color

    @viewport3.color = $game_screen.flash_color

    # Update viewports

    @viewport1.update

    @viewport3.update

  end

end

Scene_Map
Code:
#==============================================================================

# ** Scene_Map

#------------------------------------------------------------------------------

#  This class performs map screen processing.

#==============================================================================

 

class Scene_Map

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Make sprite set

    @spriteset = Spriteset_Map.new

    # Make message window

    @message_window = Window_Message.new

    # Transition run

    Graphics.transition

    # Main loop

    loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      # Frame update

      update

      # Abort loop if screen is changed

      if $scene != self

        break

      end

    end

    # Prepare for transition

    Graphics.freeze

    # Dispose of sprite set

    @spriteset.dispose

    # Dispose of message window

    @message_window.dispose

    # If switching to title screen

    if $scene.is_a?(Scene_Title)

      # Fade out screen

      Graphics.transition

      Graphics.freeze

    end

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # Loop

    loop do

      # Update map, interpreter, and player order

      # (this update order is important for when conditions are fulfilled 

      # to run any event, and the player isn't provided the opportunity to

      # move in an instant)

      $game_map.update

      $game_system.map_interpreter.update

      $game_player.update

      # Update system (timer), screen

      $game_system.update

      $game_screen.update

      # Abort loop if player isn't place moving

      unless $game_temp.player_transferring

        break

      end

      # Run place move

      transfer_player

      # Abort loop if transition processing

      if $game_temp.transition_processing

        break

      end

    end

    # Update sprite set

    @spriteset.update

    # Update message window

    @message_window.update

    # If game over

    if $game_temp.gameover

      # Switch to game over screen

      $scene = Scene_Gameover.new

      return

    end

    # If returning to title screen

    if $game_temp.to_title

      # Change to title screen

      $scene = Scene_Title.new

      return

    end

    # If transition processing

    if $game_temp.transition_processing

      # Clear transition processing flag

      $game_temp.transition_processing = false

      # Execute transition

      if $game_temp.transition_name == ""

        Graphics.transition(20)

      else

        Graphics.transition(40, "Graphics/Transitions/" +

          $game_temp.transition_name)

      end

    end

    # If showing message window

    if $game_temp.message_window_showing

      return

    end

    # If encounter list isn't empty, and encounter count is 0

    if $game_player.encounter_count == 0 and $game_map.encounter_list != []

      # If event is running or encounter is not forbidden

      unless $game_system.map_interpreter.running? or

             $game_system.encounter_disabled

        # Confirm troop

        n = rand($game_map.encounter_list.size)

        troop_id = $game_map.encounter_list[n]

        # If troop is valid

        if $data_troops[troop_id] != nil

          # Set battle calling flag

          $game_temp.battle_calling = true

          $game_temp.battle_troop_id = troop_id

          $game_temp.battle_can_escape = true

          $game_temp.battle_can_lose = false

          $game_temp.battle_proc = nil

        end

      end

    end

    # If B button was pressed

    if Input.trigger?(Input::B)

      # If event is running, or menu is not forbidden

      unless $game_system.map_interpreter.running? or

             $game_system.menu_disabled

        # Set menu calling flag or beep flag

        $game_temp.menu_calling = true

        $game_temp.menu_beep = true

      end

    end

    # If debug mode is ON and F9 key was pressed

    if $DEBUG and Input.press?(Input::F9)

      # Set debug calling flag

      $game_temp.debug_calling = true

    end

    # If player is not moving

    unless $game_player.moving?

      # Run calling of each screen

      if $game_temp.battle_calling

        call_battle

      elsif $game_temp.shop_calling

        call_shop

      elsif $game_temp.name_calling

        call_name

      elsif $game_temp.menu_calling

        call_menu

      elsif $game_temp.save_calling

        call_save

      elsif $game_temp.debug_calling

        call_debug

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Battle Call

  #--------------------------------------------------------------------------

  def call_battle

    # Clear battle calling flag

    $game_temp.battle_calling = false

    # Clear menu calling flag

    $game_temp.menu_calling = false

    $game_temp.menu_beep = false

    # Make encounter count

    $game_player.make_encounter_count

    # Memorize map BGM and stop BGM

    $game_temp.map_bgm = $game_system.playing_bgm

    $game_system.bgm_stop

    # Play battle start SE

    $game_system.se_play($data_system.battle_start_se)

    # Play battle BGM

    $game_system.bgm_play($game_system.battle_bgm)

    # Straighten player position

    $game_player.straighten

    # Switch to battle screen

    $scene = Scene_Battle.new

  end

  #--------------------------------------------------------------------------

  # * Shop Call

  #--------------------------------------------------------------------------

  def call_shop

    # Clear shop call flag

    $game_temp.shop_calling = false

    # Straighten player position

    $game_player.straighten

    # Switch to shop screen

    $scene = Scene_Shop.new

  end

  #--------------------------------------------------------------------------

  # * Name Input Call

  #--------------------------------------------------------------------------

  def call_name

    # Clear name input call flag

    $game_temp.name_calling = false

    # Straighten player position

    $game_player.straighten

    # Switch to name input screen

    $scene = Scene_Name.new

  end

  #--------------------------------------------------------------------------

  # * Menu Call

  #--------------------------------------------------------------------------

  def call_menu

    # Clear menu call flag

    $game_temp.menu_calling = false

    # If menu beep flag is set

    if $game_temp.menu_beep

      # Play decision SE

      $game_system.se_play($data_system.decision_se)

      # Clear menu beep flag

      $game_temp.menu_beep = false

    end

    # Straighten player position

    $game_player.straighten

    # Switch to menu screen

    $scene = Scene_Menu.new

  end

  #--------------------------------------------------------------------------

  # * Save Call

  #--------------------------------------------------------------------------

  def call_save

    # Straighten player position

    $game_player.straighten

    # Switch to save screen

    $scene = Scene_Save.new

  end

  #--------------------------------------------------------------------------

  # * Debug Call

  #--------------------------------------------------------------------------

  def call_debug

    # Clear debug call flag

    $game_temp.debug_calling = false

    # Play decision SE

    $game_system.se_play($data_system.decision_se)

    # Straighten player position

    $game_player.straighten

    # Switch to debug screen

    $scene = Scene_Debug.new

  end

  #--------------------------------------------------------------------------

  # * Player Place Move

  #--------------------------------------------------------------------------

  def transfer_player

    # Clear player place move call flag

    $game_temp.player_transferring = false

    # If move destination is different than current map

    if $game_map.map_id != $game_temp.player_new_map_id

      # Set up a new map

      $game_map.setup($game_temp.player_new_map_id)

    end

    # Set up player position

    $game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)

    # Set player direction

    case $game_temp.player_new_direction

    when 2  # down

      $game_player.turn_down

    when 4  # left

      $game_player.turn_left

    when 6  # right

      $game_player.turn_right

    when 8  # up

      $game_player.turn_up

    end

    # Straighten player position

    $game_player.straighten

    # Update map (run parallel process event)

    $game_map.update

    # Remake sprite set

    @spriteset.dispose

    @spriteset = Spriteset_Map.new

    # If processing transition

    if $game_temp.transition_processing

      # Clear transition processing flag

      $game_temp.transition_processing = false

      # Execute transition

      Graphics.transition(20)

    end

    # Run automatic change for BGM and BGS set on the map

    $game_map.autoplay

    # Frame reset

    Graphics.frame_reset

    # Update input information

    Input.update

  end

################################################################################

  def zoom(x,y,coef,spd)

    if !$game_map.zooming?

      $game_map.start_zoom(x,y,coef,spd)

    end

  end

  def zoom_d(x,y,coef)

    if !$game_map.zooming?

      $game_map.default_zoom(x,y,coef)

    end

  end

################################################################################

end

TileMap by RTH, Modified for the zoom abilities with settings similar to the SephirothSpawn' ones.
Code:
#==============================================================================

# ** Tilemap_Settings

#==============================================================================

 

class Tilemap_Settings

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_accessor :map

  attr_accessor :tone

  attr_accessor :hue

  attr_accessor :zoom_x

  attr_accessor :zoom_y

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize(map = nil)

    # Set Instance Variables

    @map = map

    @tone = nil

    @hue = 0

    @zoom_x = 1.0

    @zoom_y = 1.0

  end

end

 

#==============================================================================

# Tilemap

#------------------------------------------------------------------------------

# Author of THIS VERSION: RTH

#==============================================================================     

class Tilemap

  

  # Autotile Update Rate

  AUTOTILE_UPDATE = 10

     

  # Autotiles Index (Dont Change these numbers)

  INDEX = [

    [ [27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],

      [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12] ],

    [ [27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],

      [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12] ],

    [ [25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],

      [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],

    [ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],

      [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46] ],

    [ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],

      [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],

    [ [37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],

      [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8] ]

  ]

  

  attr_accessor :ox

  attr_accessor :oy

  attr_accessor :tileset

  attr_accessor :autotiles

  attr_accessor :priorities

  attr_accessor :map_data

################################################################################

  attr_accessor :tilemap_settings

################################################################################

  

  def initialize(viewport)

################################################################################

    @tilemap_settings  = nil   # Special Tilemap Settings

    @zoom_x   = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_x

    @zoom_y   = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_y

    @tone     = @tilemap_settings.nil? ? nil : @tilemap_settings.tone

    @hue      = @tilemap_settings.nil? ? 0   : @tilemap_settings.hue

################################################################################

    @viewport = viewport

    # Dimensioni della mappa visualizzata

    #( /32 = schermo 640x480 ... /64 = schermo 320x240 )

    @swidth  = (@viewport.rect.width  / 32) /@zoom_x

    @sheight = (@viewport.rect.height / 32) /@zoom_y

    # Creates Blank Instance Variables

    @data              = nil

    @data_priorities   = nil

    @priorities        = nil   # Refers to Tileset Priorities

    @map_data          = nil   # Refers to 3D Array Of Tile Settings

    @tileset           = nil   # Refers to Tileset Bitmap

    @autotiles         = []    # Refers to Array of Autotile Bitmaps

    @sprites           = {}

    @bitmaps           = {}

    @cache             = {}

    @need_counters     = []

    @counter           = []

    @max_counters      = []

    @ox                = 0     # Bitmap Offsets          

    @oy                = 0     # Bitmap Offsets

    @time_counter      = 1

    @need_refresh      = false

  end

  

  def refresh

################################################################################

    zx = zox = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_x

    zy = zoy = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_y

    if (zox != 1.0) and (zox != 2.0)

      zox += 0.05

    end

    if (zoy != 1.0) and (zoy != 2.0)

      zoy += 0.05

    end################################################################################

    @need_refresh = false

    @table = Table.new(384)

    @size = 0

    @data = @map_data

    @data_priorities = @priorities

    #

    min_x = [Integer(@ox / (32*zx) - 1), 0].max

    min_y = [Integer(@oy / (32*zy) - 1), 0].max

    max_x = [min_x + Integer(@swidth + 1 * 2), @data.xsize - 1].min

    max_y = [min_y + Integer(@sheight + 1 * 2), @data.ysize - 1].min

    (min_x..max_x).each {|x|

      (min_y..max_y).each {|y|

        (0..2).each {|z|

          tile_id = @data[x, y, z]

          next if tile_id == 0

          priority = @priorities[tile_id]

          key = [x, y, z, priority]

          #Posizione dei Tiles, viene dopo riaggiornata,

          #dipende anche da altri punti del codice

          @sprites[key] = Sprite.new(@viewport)

################################################################################

          @sprites[key].x = x * 32*zx - @ox

          @sprites[key].y = y * 32*zy - @oy

          @sprites[key].zoom_x = zox

          @sprites[key].zoom_y = zoy

          @sprites[key].z = (y * 32*zy - @oy) + ((priority + 1) * 32*zy)

################################################################################

          if tile_id < 384

            tile = get_autotile(tile_id)

          else

            tile = get_tile(tile_id)

          end

          @sprites[key].bitmap = tile

        }

      }

    }

  end

  

  def get_autotile(tile_id)

    if tile_id >= 384

      return get_tile(tile_id)

    end

    autotile = @autotiles[(tile_id/48) - 1]

    n = (autotile.width / 96)

    if @bitmaps[tile_id].nil?

      @bitmaps[tile_id] = []

    end

    if n > 1

      if @table[tile_id] == 0

        @counter[tile_id] = 0

        @max_counters[tile_id] = n

        @table[tile_id] = 1

        @size += 1

      end

    end

    for i in 0...n

      @bitmaps[tile_id][i] = get_tile(tile_id, i)

    end

    if @counter[tile_id].nil?

      return @bitmaps[tile_id][0]

    end

    return @bitmaps[tile_id][@counter[tile_id]]

  end

  

  def get_tile(tile_id, c=0)

    key = [tile_id, c]

    if @cache[key].nil?

      #??? forse il rettangolo che contiene il tileset

      @cache[key] = Bitmap.new(32, 32)

      if tile_id < 384

        anim = c * 96

        id = tile_id % 48

        tiles = INDEX[id >> 3][id % 8]

        autotile = @autotiles[(tile_id/48) - 1]

        for i in 0...4

          tile_position = tiles[i] - 1

          rect = Rect.new(tile_position % 6 * 16 + anim, tile_position / 6 * 16, 16, 16)

          @cache[key].blt((i%2) * 16, (i/2) * 16, autotile, rect)

        end

      else

        #I primi due moltiplicatori decidono a quale distanza l'uno dall'altro prelevare i Tile

        #Gli ultimi 2 numeri indicano la dimensione del Rettangolo del Tile

        #(Non agiscono sulla grafica, ma solo su come viene usato il Tileset, meglio lasciarlo stare)

        @cache[key].blt(0, 0, @tileset, Rect.new((tile_id - 384) % 8 * 32, (tile_id - 384) / 8 * 32, 32, 32))

      end

    end

    return @cache[key]

  end

  

  def tileset=(valor)

    for v in @cache.values

      v.dispose

    end

    @cache = {}

    @tileset = valor

    @need_refresh = true

  end

  

  def dispose

    @cache.values.each {|v| v.dispose }

    @cache = {}

    @bitmaps.values.each {|a|

      next if a.nil?

      a.each {|v|

        next if v.nil?

        v.dispose unless v.disposed?

      }

    }

    @sprites.values.each {|sprite|

      next if sprite.nil?

      sprite.dispose

    }

    @sprites = {}

  end

  

  def update

################################################################################

    zx = zox = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_x

    zy = zoy = @tilemap_settings.nil? ? 1.0 : @tilemap_settings.zoom_y

    if (zox != 1.0) and (zox != 2.0)

      zox += 0.05

    end

    if (zoy != 1.0) and (zoy != 2.0)

      zoy += 0.05

    end

################################################################################

    if @data != @map_data or @priorities != @data_priorities or @need_refresh

      refresh

      return

    end

    #???

    min_x = [Integer(@ox / (32*zx) - 1), 0].max

    min_y = [Integer(@oy / (32*zy) - 1), 0].max

    max_x = [min_x + Integer(@swidth + 1 * 2), @data.xsize - 1].min

    max_y = [min_y + Integer(@sheight+ 1 * 2), @data.ysize - 1].min

    if AUTOTILE_UPDATE > 0

      @time_counter = (@time_counter + 1) % AUTOTILE_UPDATE

    end

    checked = []

    for x in min_x..max_x

      #Ho trovato qualcosa... questi numeri indicano a che distanza aggiornare

      #i tilesets...

################################################################################

      rx = ((x * 32*zx) - @ox)

      cx = (rx < 0 or rx > (@swidth - 32*zx))

      ax = (((rx + 32*zx) < - 32*zx) or (rx > @viewport.rect.width + 32*zx))

      for y in min_y..max_y

        ry = ((y * 32*zy) - @oy)

        cy = (ry < 0 or ry > (@sheight - 32*zy))

        ay = (((ry + 32*zy) < - 32*zy) or (ry > @viewport.rect.height + 32*zy))

################################################################################

        for z in 0..2

          tile_id = @data[x, y, z]

          next if tile_id == 0

          priority = @priorities[tile_id]

          key = [x, y, z, priority]

          if ay or ax

            if @sprites[key] != nil

              @sprites[key].dispose

              @sprites[key] = nil

            end

            next

          end

          #Qui si stabiliscono le priorità dei Tilesets, sulla posizione

          #dei chara e dei tile a loro intorno...

################################################################################

          if @sprites[key].nil?

            @sprites[key] = Sprite.new(@viewport)

            @sprites[key].x = rx

            @sprites[key].y = ry

            @sprites[key].zoom_x = zox 

            @sprites[key].zoom_y = zoy

            @sprites[key].z = ry + ((priority + 1) * 32*zy)

################################################################################

            if tile_id < 384

              tile = get_autotile(tile_id)

            else

              tile = get_tile(tile_id)

            end

            @sprites[key].bitmap = tile

            next

          end

          if @changed_ox or cy

            if @sprites[key].x != rx

              @sprites[key].x = rx

              @sprites[key].zoom_x = zox 

              @sprites[key].zoom_y = zoy

            end

          end

################################################################################

          if @changed_oy or cx

            if @sprites[key].y != ry

              @sprites[key].y = ry

              @sprites[key].zoom_x = zox 

              @sprites[key].zoom_y = zoy

              @sprites[key].z = ry + ((priority + 1) * 32*zy)

            end

          end

################################################################################

          next if (@time_counter != 0)

          if @table[tile_id] == 1

            if checked[tile_id] != true

              @counter[tile_id] = (@counter[tile_id] + 1) % @max_counters[tile_id]

              checked[tile_id] = true

            end

            @sprites[key].bitmap = @bitmaps[tile_id][@counter[tile_id]]

          end

        end

      end

    end

    if @changed_ox

      @changed_ox = false

    end

    if @changed_oy

      @changed_oy = false

    end

################################################################################

    # Zoom X, Zoom Y, and Tone Changes

    unless @tilemap_settings.nil?

      if @zoom_x != @tilemap_settings.zoom_x

        @zoom_x = @tilemap_settings.zoom_x

        refresh

        update

        #@sprites[key].zoom_x = @zoom_x

      end

      if @zoom_y != @tilemap_settings.zoom_y

        @zoom_y = @tilemap_settings.zoom_y

        refresh

        update

        #@sprites[key].zoom_y = @zoom_y

      end

    end

################################################################################

  end

  

  def ox=(valor)

    return if @ox == valor

    @ox = valor

    @changed_ox = true

  end

  

  def oy=(valor)

    return if @oy == valor

    @oy = valor

    @changed_oy = true

  end

end

The graphic problem is that sometimes, at the edge of the map, some old tiles (not updated) remains...
Another issue is that the Grass eventually walk over you (it's surelly a problem with the Y coordinate of the tile and character that has a value too high or low)
the most annoying bug is that the Zoom IN or Zoom OUT, no matter how slow you put the settings for the animation, have a lot of lag!! this is one feature that would be great like a Smooth zoom effect, personally i want to use it with an ABS, for the attacks, to give my game something more to look at during the battles, it will be also a good extra for the cutscenes.
can someone take a look at it? the first 2 bug are easilly fixable, the third one is the one i really need someone else to work at it... unfortunatly i'm not able to do it, i need someone with more skills!! :) thank you all.

EDIT: All the thing i've changed in the original scripts was putted between 2 lines of # (except for some edit i've forgot to segnalize)

SOLVED
I've found a solution to all the question with the time i've spent on the script, fortunatly... i've few more question, i'll try to ask here as well
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top