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:
Poccil's Tilemap class
RTH's Tilemap class
ok, this is all!! ^_^
Maybe it's not so easy to understand what i need, i'll make an example...
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
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...
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