Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # Custom Resolution (DLL-less)
- # Authors: ForeverZer0, KK20, LiTTleDRAgo
- # Version: 0.97a
- # Date: 3.2.2014
- #===============================================================================
- # LiTTleDRAgo's Notes
- #===============================================================================
- # Note that X in the notes below means that it's no longer true
- #
- #===============================================================================
- # KK20's Notes
- #===============================================================================
- # Introduction:
- #
- # This script is intended to create screen resolutions other than 640 x 480.
- # The script comes with its own Tilemap rewrite in order to combat larger
- # screen resolutions (because anything beyond 640 x 480 is not drawn).
- #
- # Instructions:
- #
- # Place script above 'Main'. Probably best to put it below all your other
- # custom scripts.
- # This version does not require the 'screenshot.dll'.
- #
- # Things to Consider:
- #
- # X Fullscreen will change the resolution back to 640 x 480. A solution is in
- # the works.
- # - Transitions do not work properly on larger resolutions. You can use a
- # Transitions Add-Ons script if you want better transitions (otherwise, all
- # you will get is the default fade in/out). Links listed below.
- # - Custom scripts that draw windows to the screen will most likely need edits.
- # - Larger resolutions = more processing power = more lag
- #
- #
- # ***************************************************************************
- # * THIS IS STILL A WORK IN PROGRESS; IF YOU FIND ANYTHING PLEASE REPORT IT *
- # ***************************************************************************
- #
- # Links:
- # - Fantasist's Transitions Pack
- # http://forum.chaos-project.com/index.php/topic,1390.0.html
- # - ForeverZer0's Add-ons
- # http://forum.chaos-project.com/index.php/topic,7862.0.html
- # - ThallionDarkshine's Add-ons
- # http://forum.chaos-project.com/index.php/topic,12655.0.html
- # - Drago Transition Pack
- # http://forum.chaos-project.com/index.php/topic,13488.0.html
- #
- #===============================================================================
- # ForeverZer0's Notes from v0.93 (outdated information)
- #===============================================================================
- # Introduction:
- #
- # My goal in creating this script was to create a system that allowed the user
- # to set the screen size to something other than 640 x 480, but not have make
- # huge sacrifices in compatibility and performance. Although the script is
- # not simply Plug-and-Play, it is about as close as one can achieve with a
- # script of this nature.
- #
- # Instructions:
- #
- # X Place the "screenshot.dll" from Fantasist's Transition Pack script, which
- # can be found here: http://www.sendspace.com/file/yjd54h in your game folder
- # - Place this script above main, below default scripts.
- # - In my experience, unchecking "Reduce Screen Flickering" actually helps the
- # screen not to flicker. Open menu with F1 while playing and set this to what
- # you get the best results with.
- #
- # Features:
- #
- # X Totally re-written Tilemap and Plane class. Both classes were written to
- # display the map across any screen size automatically. The Tilemap class
- # is probably even more efficient than the original, which will help offset
- # any increased lag due to using a larger screen size with more sprites
- # being displayed.
- # - Every possible autotile graphic (48 per autotile) will be cached for the
- # next time that tile is used.
- # - Autotile animation has been made as efficient as possible, with a system
- # that stores their coodinates, but only if they change. This greatly reduces
- # the number of iterations at each update.
- # X System creates an external file to save pre-cached data priorities and
- # autotiles. This will decrease any loading times even more, and only takes a
- # second, depending on the number of maps you have.
- # - User defined autotile animation speed. Can change with script calls.
- # - Automatic re-sizing of Bitmaps and Viewports that are 640 x 480 to the
- # defined resolution, unless explicitely over-ridden in the method call.
- # The graphics themselves will not be resized, but any existing scripts that
- # use the normal screen size will already be configured to display different
- # sizes of graphics for transitions, battlebacks, pictures, fogs, etc.
- # X Option to have a log file ouput each time the game is ran, which can alert
- # you to possible errors with map sizes, etc.
- #
- # Issues/Bugs/Possible Bugs:
- #
- # - Graphic related scripts and your graphics will need to be customized to
- # fit the new screen size, so this script is not for everyone.
- # X The Z-axis for the Plane class, which is used for Fogs and Panoramas has
- # been altered. It is now multiplied by 1000. This will likely be a minor
- # issue for most, since this class is very rarely used except for Fogs and
- # Panoramas, which are already far above and below respectfully.
- # - Normal transitions using graphics cannot be used. With the exception of
- # a standard fade, like that used when no graphic is defined will be used.
- # Aside from that, only special transitions from Transition Pack can be
- # used.
- #===============================================================================
- # Credits/Thanks:
- # - ForeverZer0, for script.
- # - Creators of the Transition Pack and Screenshot.dll
- # - Selwyn, for base resolution script
- # - KK20, for Version 0.94 and above and the Tilemap class
- # - LiTTleDRAgo, for his Core Engine script to remove screenshot.dll dependency
- #===============================================================================
- # CONFIGURATION
- #===============================================================================
- SCREEN = [1024,576]
- # Define the resolution of the game screen. These values can be anything
- # within reason. Centering, viewports, etc. will all be taken care of, but it
- # is recommended that you use values divisible by 32 for best results.
- UPDATE_COUNT = 8
- # Define the number of frames between autotile updates. The lower the number,
- # the faster the animations cycle. This can be changed in-game with the
- # following script call: $game_map.autotile_speed = SPEED
- #===============================================================================
- # ** Resolution
- #===============================================================================
- class Resolution
- attr_reader :version, :width, :height
- def initialize
- # Define version.
- @version = 0.971
- # Set instance variables for calling basic Win32 functions.
- ini = Win32API.new('kernel32', 'GetPrivateProfileString','PPPPLP', 'L')
- ini.call('Game', 'Title', '', (title = "\0" * 256), 256, '.\\Game.ini')
- title.delete!("\0")
- @window = LiTTleDRAgo.hwnd
- @metrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
- # Set default size, displaying error if size is larger than the hardware.
- default_size = self.size
- if default_size[0] < SCREEN[0] || default_size[1] < SCREEN[1]
- print("\"#{title}\" requires a minimum screen resolution of [#{SCREEN[0]} x #{SCREEN[1]}]\r\n\r\n" +
- "\tYour Resolution: [#{default_size[0]} x #{default_size[1]}]")
- exit
- end
- # Apply resolution change.
- enable_tilemap(true)
- change_resolution(SCREEN[0], SCREEN[1])
- end
- #--------------------------------------------------------------------------
- def size
- # Returns the screen size of the machine.
- return [@metrics.call(0), @metrics.call(1)]
- end
- #--------------------------------------------------------------------------
- def enable_tilemap(value = true)
- @enable = value
- end
- #--------------------------------------------------------------------------
- def enabled?
- @enable
- end
- #--------------------------------------------------------------------------
- def fullscreen?
- size.at(0) == Graphics.width
- end
- #--------------------------------------------------------------------------
- # * New method: change_resolution
- #--------------------------------------------------------------------------
- unless method_defined?(:change_resolution)
- def change_resolution(w = @width, h = @height)
- @set_window_long ||= Win32API.new('user32', 'SetWindowLong', 'LIL', 'L')
- @set_window_pos ||= Win32API.new('user32', 'SetWindowPos', 'LLIIIII', 'I')
- w, h = (w / 32.0).ceil * 32, (h / 32.0).ceil * 32
- x, y = (size[0] - w) / 2, (size[1] - h) / 2
- @set_window_long.call(@window, -16, 0x14CA0000)
- @set_window_pos.call(@window, 0, x, y, w + 6, h + 26, 0)
- if @width != w || @height != h
- @width, @height = w, h
- end
- end
- end
- #--------------------------------------------------------------------------
- end
- #==============================================================================
- # ** Drago - Core Engine
- # Version : 1.39
- # Contact : littledrago.blogspot.com / forum.chaos-project.com
- #==============================================================================
- # =============================================================================
- # NOTE:
- # -----------------------------------------------------------------------------
- # This is a devtool for me to make me easier for scripting
- # If you want to use this, put above all custom script & below Scene_Debug
- #
- # Note that I'm changing a bit RGSS language in this script, so probably some
- # syntax in this script won't work if you use them somewhere else
- #
- # =============================================================================
- module LiTTleDRAgo
- #-------------------------------------------------------------------------
- # * Constant
- #-------------------------------------------------------------------------
- VX = defined?(Window_ActorCommand)
- VXA = defined?(Window_BattleActor)
- RGSS1 = defined?(Hangup)
- RGSS2 = RUBY_VERSION == '1.8.1' && !RGSS1
- RGSS3 = RUBY_VERSION == '1.9.2'
- APPPATHDRAGO = "#{ENV['APPDATA']}/Drago/"
- end
- #==============================================================================
- # ** CoreDLL
- #------------------------------------------------------------------------------
- #
- #==============================================================================
- module CoreDLL
- #-------------------------------------------------------------------------
- # * Constant
- #-------------------------------------------------------------------------
- Rtlmemory_pi = Win32API.new('kernel32','RtlMoveMemory','pii','i')
- Rtlmemory_ip = Win32API.new('kernel32','RtlMoveMemory','ipi','i')
- #-------------------------------------------------------------------------
- # * Get the game window handle (specific to game)
- #-------------------------------------------------------------------------
- unless method_defined?(:hwnd)
- def hwnd
- @window_find ||= Win32API.new('user32', 'FindWindowEx', %w(l l p p), 'i')
- @game_window ||= @window_find.call(0,0,"RGSS Player",0)
- return @game_window
- end
- end
- #-------------------------------------------------------------------------
- # * Get the Game Window's width and height
- #-------------------------------------------------------------------------
- unless method_defined?(:client_size)
- def client_size
- @window_c_rect ||= Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
- @window_c_rect.call(self.hwnd, (rect = [0, 0, 0, 0].pack('l4')))
- right, bottom = rect.unpack('l4')[2..3]
- return right, bottom
- end
- end
- #--------------------------------------------------------------------------
- # * snap_to_bitmap
- #--------------------------------------------------------------------------
- unless method_defined?(:snap_to_bitmap)
- def snap_to_bitmap
- @getdc ||= Win32API.new('user32','GetDC','i','i')
- @ccdc ||= Win32API.new('gdi32','CreateCompatibleDC','i','i')
- @ccbitmap ||= Win32API.new('gdi32','CreateCompatibleBitmap','iii','i')
- @deleteobject ||= Win32API.new('gdi32','DeleteObject','i','i')
- @bitblt ||= Win32API.new('gdi32','BitBlt','iiiiiiiii','i')
- @setdibits ||= Win32API.new('gdi32','SetDIBits','iiiiipi','i')
- @getdibits ||= Win32API.new('gdi32','GetDIBits','iiiiipi','i')
- @selectobject ||= Win32API.new('gdi32','SelectObject','ii','i')
- bitmap = Bitmap.new((width = Graphics.width), (height = Graphics.height))
- info = [40,width,height,1,32,0,0,0,0,0,0].pack('LllSSLLllLL')
- hDC = @ccdc.call((dc = @getdc.call(hwnd)))
- hBM = @ccbitmap.call(dc, width, height)
- @deleteobject.call(@selectobject.call(hDC, hBM))
- @setdibits.call(hDC, hBM, 0, height, (address = bitmap.address), info, 0)
- @bitblt.call(hDC, 0, 0, width, height, dc, 0, 0, 0xCC0020)
- @getdibits.call(hDC, hBM, 0, height, address, info, 0)
- @deleteobject.call(hBM)
- @deleteobject.call(hDC)
- bitmap
- end
- end
- end
- LiTTleDRAgo.extend(CoreDLL)
- #==============================================================================
- # ** Graphics
- #------------------------------------------------------------------------------
- # This module handles all Graphics
- #==============================================================================
- class << Graphics
- #--------------------------------------------------------------------------
- # ● Redefined method: width, height, snap_to_bitmap
- #--------------------------------------------------------------------------
- unless method_defined?(:width)
- def width
- LiTTleDRAgo.client_size.at(0)
- end
- end
- unless method_defined?(:height)
- def height
- LiTTleDRAgo.client_size.at(1)
- end
- end
- unless method_defined?(:snap_to_bitmap)
- def snap_to_bitmap
- LiTTleDRAgo.snap_to_bitmap
- end
- end
- end
- #==============================================================================
- # ■ Bitmap
- #------------------------------------------------------------------------------
- #
- #==============================================================================
- class Bitmap
- #----------------------------------------------------------------------------
- # ● Constant
- #----------------------------------------------------------------------------
- RtlMoveMemory_pi = CoreDLL::Rtlmemory_pi
- RtlMoveMemory_ip = CoreDLL::Rtlmemory_ip
- #----------------------------------------------------------------------------
- # ● New method: address
- #----------------------------------------------------------------------------
- unless method_defined?(:address)
- def address
- @address ||= (
- RtlMoveMemory_pi.call(a="\0"*4, __id__*2+16, 4)
- RtlMoveMemory_pi.call(a, a.unpack('L')[0]+8, 4)
- RtlMoveMemory_pi.call(a, a.unpack('L')[0]+16, 4)
- a.unpack('L')[0]
- )
- end
- end
- end
- #===============================================================================
- # ** END OF Drago - Core Engine
- #===============================================================================
- #===============================================================================
- # ** Graphics
- #===============================================================================
- class << Graphics
- unless method_defined?(:zer0_graphics_transition)
- alias_method(:zer0_graphics_transition, :transition)
- def transition(duration = 8, *args)
- # Call default transition if no instance of the resolution is defined.
- if $resolution == nil
- zer0_graphics_transition(duration, *args)
- else
- # Skip this section and instantly transition graphics if duration is 0.
- if duration > 0
- # Take a snapshot of the the screen, overlaying screen with graphic.
- #$resolution.snapshot
- zer0_graphics_transition(0)
- # Create screen instance
- viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- sprite = Sprite.new(viewport)
- sprite.bitmap = Graphics.snap_to_bitmap
- # Use a simple fade if transition is not defined.
- fade = 255 / duration
- duration.times { (sprite.opacity -= fade) && update }
- # Dispose sprite and delete snapshot file.
- [sprite, sprite.bitmap, viewport].each {|obj| obj.dispose }
- end
- zer0_graphics_transition(0)
- end
- end
- end
- end
- #===============================================================================
- # ** RPG::Cache
- #===============================================================================
- class << RPG::Cache
- AUTO_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]
- ].freeze
- alias_method :autotile_cr_tilemap, :autotile
- def autotile(filename)
- return autotile_cr_tilemap(filename) unless $resolution.enabled?
- key = "Graphics/Autotiles/#{filename}"
- if !@cache.include?(key) || @cache[key].disposed?
- # Cache the autotile graphic.
- @cache[key] = (filename == '') ? Bitmap.new(128, 96) : Bitmap.new(key)
- # Cache each configuration of this autotile.
- new_bm = self.format_autotiles(@cache[key], filename)
- @cache[key].dispose
- @cache[key] = new_bm
- end
- return @cache[key]
- end
- def format_autotiles(bitmap, filename)
- if bitmap.height > 32
- frames = bitmap.width / 96
- template = Bitmap.new(256*frames,192)
- # Create a bitmap to use as a template for creation.
- (0..frames-1).each{|frame|
- (0...6).each {|i| (0...8).each {|j| AUTO_INDEX[8*i+j].each {|number|
- number -= 1
- x, y = 16 * (number % 6), 16 * (number / 6)
- rect = Rect.new(x + (frame * 96), y, 16, 16)
- template.blt((32 * j + x % 32) + (frame * 256), 32 * i + y % 32, bitmap, rect)
- }}}}
- return template
- else
- return bitmap
- end
- end
- end
- #===============================================================================
- # ** Tilemap_DataTable
- #===============================================================================
- class Tilemap_DataTable
- attr_accessor :table, :updates
- def [](x,y=nil,z=nil)
- return @table[x,y,z] unless z.nil?
- return @table[x,y] unless y.nil?
- return @table[x]
- end
- def []=(x,y,z=nil,t_id=nil)
- t_id && updates.push([x,y,z,t_id])
- t_id ? (@table[x,y,z] = t_id) : (z.nil? ? @table[x] = y : @table[x,y] = z)
- end
- define_method(:initialize) { |table| @table = table }
- define_method(:updates) { @updates ||= [] }
- define_method(:updated?) { updates.size >= 1 }
- def method_missing(sym, *a, &blk) table.send(sym, *a, &blk) end
- end
- #===============================================================================
- # ** CRTilemap
- #===============================================================================
- class CRTilemap
- #---------------------------------------------------------------------------
- # * Public Instance Variables
- #---------------------------------------------------------------------------
- attr_reader :map_data, :ox, :oy, :viewport, :tile_sprites
- attr_accessor :tileset, :autotiles, :priorities
- define_method(:width) { $resolution.width / 32 + 2 }
- define_method(:height) { $resolution.height / 32 + 2 }
- def initialize(viewport)
- # Initialize instance variables to store required data.
- @viewport, @autotiles, @tile_sprites, @ox, @oy = viewport, [], [], 0, 0
- @current_frame, @total_frames = [], []
- @tilemap_drawn = false
- @ox_oy_set = [false, false]
- # Get priority data for this tileset from instance of Game_Map.
- @priorities = $game_map.priorities
- # Holds all the Sprite instances of animating tiles (keys based on tile's ID)
- @animating_tiles = {}
- # Game map's x/y location of the top left corner tile
- @corner_tile_loc = [-1,-1]
- end
- #-----------------------------------------------------------------------------
- # Initialize all tile sprites. Draws three sprites per (x,y).
- #-----------------------------------------------------------------------------
- def init_tiles
- # Determine how many frames of animation this autotile has
- for i in 0..6
- bm = @autotiles[i]
- if bm.nil?
- @total_frames = 1
- elsif bm.height > 32
- @total_frames[i] = bm.width / 256
- else
- @total_frames[i] = bm.width / 32
- end
- @current_frame[i] = 0
- end
- # Turn on flag that the tilemap sprites have been initialized
- @tilemap_drawn = true
- @animating_tiles.clear
- @zoom_x = $game_map.respond_to?(:zoom_x) ? $game_map.zoom_x : 1.0
- @zoom_y = $game_map.respond_to?(:zoom_y) ? $game_map.zoom_y : 1.0
- # Create a sprite and viewport to use for each priority level.
- (0...(width * height)*3).each do |i|
- @tile_sprites[i/3] ||= []
- unless @tile_sprites[i/3][i%3].is_a?(Sprite) && !@tile_sprites[i/3][i%3].disposed?
- @tile_sprites[i/3][i%3] = Sprite.new(@viewport)
- end
- # Rename to something shorter and easier to work with for below
- tile = @tile_sprites[i/3][i%3]
- # Assign tile's respective ID value
- tile.instance_variable_set(:@tile_sprite_id, i)
- # Draw sprite at index location (ex. ID 0 should always be the top-left sprite)
- tile.x = (i % (width*3) / 3 * 32) - 32 + (@ox % 32)
- tile.y = (i / (width*3) * 32) - 32 + (@oy % 32)
- tile.zoom_x = @zoom_x
- tile.zoom_y = @zoom_y
- tile.x = tile.x * tile.zoom_x
- tile.y = tile.y * tile.zoom_y
- map_x, map_y = (tile.x/tile.zoom_x+@ox)/32, (tile.y/tile.zoom_y+@oy)/32
- @corner_tile_loc = [map_x, map_y] if i == 0
- # If the tile happens to be drawn along the outside borders of the map
- if map_x < 0 || map_x >= $game_map.width || map_y < 0 || map_y >= $game_map.height
- tile.z = 0
- tile.bitmap = RPG::Cache.picture('')
- tile.src_rect.set(0,0,0,0)
- else # Tile is actually on the map
- tile_update(tile,i%3)
- end
- end
- # Sprite ID located at top left corner (ranges from 0..map_width * map_height
- @corner_index = 0
- end
- #-----------------------------------------------------------------------------
- # Makes update to ox and oy. Sprites out of range will be moved based on these
- # two values.
- #-----------------------------------------------------------------------------
- def ox=(ox)
- time = Time.now
- return (@ox = ox) && @ox_oy_set[0] = true unless @tilemap_drawn
- return if @ox == ox
- # Shift all tiles left or right by the difference
- shift = (@ox - ox) * @zoom_x
- @tile_sprites.flatten.each{|tile| tile.x += shift }
- @ox = ox
- # Determine if columns need to be shifted
- col_num = @corner_index
- while (t = @tile_sprites[col_num]) && (t[0].x/t[0].zoom_x <= -49 || t[0].x/t[0].zoom_x >= -17)
- @corner_tile_loc[0] += (shift < 0 ? 1 : -1)
- modTileId = (($resolution.width + 64) * ($resolution.height + 64)) /1024
- # If new ox is greater than old ox
- if shift < 0
- # Move all sprites in left column to the right side and change bitmaps
- # and z-values
- (0...height).each do |n|
- j = (width * n + col_num) % modTileId
- @tile_sprites[j].each_index do |i|
- tile = @tile_sprites[j][i]
- tile.x += (64 + $resolution.width) * tile.zoom_x
- tile_update(tile,i)
- end
- end
- # New corner should be the tile immediately right of the previous tile
- col_num /= width
- col_num *= width
- @corner_index = (@corner_index + 1) % width + col_num
- else
- # Shift right column to the left
- # Gets the right column
- row_index = col_num / width
- row_index *= width
- col_num = (@corner_index - 1) % width + row_index
- (0...height).each do |n|
- j = (width * n + col_num) % modTileId
- @tile_sprites[j].each_index do |i|
- tile = @tile_sprites[j][i]
- tile.x -= (64 + $resolution.width) * tile.zoom_x
- tile_update(tile,i)
- end
- end
- col_num /= width
- col_num *= width
- @corner_index = (@corner_index - 1) % width + col_num
- end
- col_num = @corner_index
- end #end of while
- puts Time.now - time
- end
- #-----------------------------------------------------------------------------
- # Makes update to ox and oy. Sprites out of range will be moved based on these
- # two values.
- #-----------------------------------------------------------------------------
- def oy=(oy)
- time = Time.now
- return (@oy = oy) && @ox_oy_set[1] = true unless @tilemap_drawn
- return if @oy == oy
- # Shift all tiles up or down by the difference, and change z-value
- shift = (@oy - oy)
- @tile_sprites.each_index do |j|
- @tile_sprites[j].each_index do |i|
- # Get each individual tile on each layer
- tile = @tile_sprites[j][i]
- tile.y += shift * @zoom_y
- priority = tile.instance_variable_get(:@priorities)
- next unless priority.is_a?(Integer) && priority > 0
- tile.z = 32 + (tile.y.floor / 32) * 32 + priority * 32 * tile.zoom_y
- end
- end
- @oy = oy
- # Determine if rows need to be shifted
- row_num = @corner_index
- while (t = @tile_sprites[row_num]) && (t[0].y/t[0].zoom_y <= -49 || t[0].y/t[0].zoom_y >= -17)
- # Needed for resetting the new corner index much later.
- modTileId = (($resolution.width+64)*($resolution.height+64))/1024
- @corner_tile_loc[1] += (shift < 0 ? 1 : -1)
- # If new oy is greater than old oy
- if shift < 0
- row_num /= width
- row_num *= width
- # Move all sprites in top row to the bottom side and change bitmaps
- # and z-values
- (0...width).each do |n|
- # Run through each triad of sprites from left to right
- j = n + row_num
- @tile_sprites[j].each_index do |i|
- # Get each individual tile on each layer
- tile = @tile_sprites[j][i]
- tile.y += (64 + $resolution.height) * tile.zoom_y
- tile_update(tile,i)
- end
- end
- @corner_index = (@corner_index + width) % modTileId
- else
- row_num = (@corner_index - width) % modTileId
- row_num /= width
- row_num *= width
- (0...width).each do|n|
- # Run through each triad of sprites from left to right
- j = n + row_num
- @tile_sprites[j] && @tile_sprites[j].each_index do |i|
- # Get each individual tile on each layer
- tile = @tile_sprites[j][i]
- tile.y -= (64 + $resolution.height) * tile.zoom_y
- tile_update(tile,i)
- end
- end
- @corner_index = (@corner_index - width) % modTileId
- end
- row_num = @corner_index
- end # end of while
- puts Time.now - time
- end
- #-----------------------------------------------------------------------------
- # tile_update
- #-----------------------------------------------------------------------------
- def tile_update(tile,i,z = true)
- tile_sprite_id = tile.instance_variable_get(:@tile_sprite_id)
- @animating_tiles.delete(tile_sprite_id)
- # Determine what map coordinate this tile now resides at...
- map_x, map_y = (tile.x/tile.zoom_x+@ox).round/32, (tile.y/tile.zoom_y+@oy).round/32
- # ...and get its tile_id
- tile_id = i.is_a?(String) ? i.to_i : @map_data[map_x,map_y,i]
- tile.instance_variable_set(:@tile_id, tile_id)
- tile.zoom_x = @zoom_x
- tile.zoom_y = @zoom_y
- # If no tile exists here (effectively out of array bounds)
- if tile_id.nil?
- tile.z = [map_y * 32, 1].max
- tile.z *= tile.zoom_y
- tile.bitmap = RPG::Cache.picture('')
- tile.src_rect.set(0,0,0,0)
- tile.instance_variable_set(:@priorities, nil)
- return
- else # Tile exists. Figure out its z-coordinate based on priority
- tile.instance_variable_set(:@priorities, @priorities[tile_id])
- if @priorities[tile_id] == 0
- tile.z = 0
- else
- tile.z = 32 + (tile.y / 32).floor * 32
- tile.z += @priorities[tile_id] * 32
- tile.z *= tile.zoom_y
- end
- end
- # If empty tile
- if tile_id == 0
- tile.bitmap = RPG::Cache.picture('')
- tile.src_rect.set(0,0,0,0)
- # If not an autotile
- elsif tile_id >= 384
- tile.bitmap = @tileset
- tile.src_rect.set(((tile_id - 384) % 8) * 32,((tile_id - 384) / 8) *32, 32, 32)
- else # Autotile
- auto_id = tile_id/48-1
- tile.bitmap = @autotiles[auto_id]
- tile.src_rect.set(((tile_id % 48) % 8)*32 + @current_frame[auto_id] * 256,((tile_id % 48) / 8)*32, 32, 32)
- @animating_tiles[tile_sprite_id] = tile if @total_frames[auto_id] > 1
- end
- end
- #-----------------------------------------------------------------------------
- # Dispose all the tile sprites
- #-----------------------------------------------------------------------------
- def dispose
- # Dispose all of the sprites
- @tile_sprites.flatten.each {|tile| tile.dispose }
- @tile_sprites.clear
- @animating_tiles.clear
- end
- #-----------------------------------------------------------------------------
- # Set map data
- #-----------------------------------------------------------------------------
- def map_data=(data)
- # Set the map data to new class
- @map_data = data.is_a?(Tilemap_DataTable) ? data : Tilemap_DataTable.new(data)
- @map_data.table = @map_data.table.clone
- @map_data.updates = []
- @animating_tiles.clear
- @tilemap_drawn = false
- end
- #---------------------------------------------------------------------------
- # * New method: method_missing
- #---------------------------------------------------------------------------
- def method_missing(val,*a,&b)
- en = tile_sprites.flatten.find_all {|s|s.respond_to?(val.to_sym)}
- if en.empty?
- text = "Undefined method #{val} at #{self.inspect}"
- raise(NoMethodError,text,caller(1))
- end
- return en.map {|s| s.send(val.to_sym,*a,&b)}
- end
- #-----------------------------------------------------------------------------
- # Update the tile sprites; make changes to the map_data and update autotiles
- #-----------------------------------------------------------------------------
- def update
- # Can't update anything if the ox and oy have not yet been set
- return unless @ox_oy_set.at(0) && @ox_oy_set.at(1)
- # If the tilemap sprites have not been initialized, GO DO IT
- draw_tilemap = !@tilemap_drawn
- # If zoom variable has been changed
- draw_tilemap ||= @zoom_x != $game_map.zoom_x || @zoom_y != $game_map.zoom_y
- init_tiles if draw_tilemap
- # If made any changes to $game_map.data, the proper graphics will be drawn
- if @map_data.updated?
- @map_data.updates.each do |item|
- x,y,z,tile_id = item
- # If this changed tile is visible on screen
- if x.between?(@corner_tile_loc.at(0), @corner_tile_loc.at(0)+(width - 1)) &&
- y.between?(@corner_tile_loc.at(1), @corner_tile_loc.at(1)+(height - 1))
- x_dif = x - @corner_tile_loc.at(0)
- y_dif = y - @corner_tile_loc.at(1)
- id = @corner_index + x_dif
- id -= width if id / width > @corner_index / width
- id += y_dif * width
- id -= width * height if id >= width * height
- tile = @tile_sprites[id][z]
- tile_update(tile,tile_id.to_s)
- end
- end
- @map_data.updates = []
- end
- # Update the sprites.
- if Graphics.frame_count % $game_map.autotile_speed == 0
- # Increase current frame of tile by one, looping by width.
- for i in 0..6
- @current_frame[i] = (@current_frame[i] + 1) % @total_frames[i]
- end
- @animating_tiles.each_value do |tile|
- frames = tile.bitmap.width
- tile.src_rect.set((tile.src_rect.x + 256) % frames, tile.src_rect.y, 32, 32)
- end
- end
- end
- end
- #===============================================================================
- # Game_Map
- #===============================================================================
- class Game_Map
- attr_writer :tile_size, :map_edge
- attr_reader :cr_map_data
- $@ || alias_method(:zer0_map_edge_setup, :setup)
- $@ || alias_method(:drg_scroll_right_adjust, :scroll_right)
- $@ || alias_method(:drg_scroll_down_adjust, :scroll_down)
- def setup(map_id)
- # Call original method.
- zer0_map_edge_setup(map_id)
- # Change Map's data into a special Table class
- @cr_map_data = Tilemap_DataTable.new(@map.data)
- end
- def scroll_right(distance)
- # Find point that the map edge meets the screen edge, using custom size.
- result = [@display_x + distance, map_edge.at(0) / zoom_x].min
- drg_scroll_right_adjust(distance)
- @display_x = result
- end
- def scroll_down(distance)
- # Find point that the map edge meets the screen edge, using custom size.
- result = [@display_y + distance, map_edge.at(1) / zoom_y].min
- drg_scroll_down_adjust(distance)
- @display_y = result
- end
- def tile_size
- [_w = ($resolution.width / 32.0).ceil,
- _h = ($resolution.height / 32.0).ceil]
- end
- def map_edge
- [_w = [(width * zoom_x - tile_size.at(0)) * 128, 0].max,
- _h = [(height * zoom_y - tile_size.at(1)) * 128, 0].max]
- end
- def autotile_speed=(speed)
- # Keep the speed above 0 to prevent the ZeroDivision Error.
- @autotile_speed = [speed, 1].max
- end
- define_method(:autotile_speed) { @autotile_speed ||= UPDATE_COUNT }
- define_method(:zoom_x) { @zoom_x ||= 1.0 }
- define_method(:zoom_y) { @zoom_y ||= 1.0 }
- end
- #===============================================================================
- # ** Game_Player
- #===============================================================================
- class Game_Player
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- $@ || alias_method(:drg_adjust_viewport_center, :center)
- #--------------------------------------------------------------------------
- # * Aliased method: center
- #--------------------------------------------------------------------------
- def center(x, y)
- drg_adjust_viewport_center(x, y)
- # Recalculate the screen center based on the new resolution.
- max_x = $game_map.map_edge.at(0) / $game_map.zoom_x
- max_y = $game_map.map_edge.at(1) / $game_map.zoom_y
- $game_map.display_x = [0, [(x * 32*4) - CENTER_X, max_x].min].max
- $game_map.display_y = [0, [(y * 32*4) - CENTER_Y, max_y].min].max
- end
- end
- #==============================================================================
- # ** Viewport
- #------------------------------------------------------------------------------
- #
- #==============================================================================
- class Viewport
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- $@ || alias_method(:zer0_viewport_resize_init, :initialize)
- #--------------------------------------------------------------------------
- # * Aliased method: initialize
- #--------------------------------------------------------------------------
- def initialize(*args)
- default = Rect.new(0, 0, $resolution.width, $resolution.height)
- if args.size == 0 || args == [0, 0, 640, 480]
- # If argument is nil, use default resolution.
- zer0_viewport_resize_init(default)
- else
- # Call method normally.
- zer0_viewport_resize_init(*args)
- end
- end
- #--------------------------------------------------------------------------
- # * New method: resize
- #--------------------------------------------------------------------------
- unless method_defined?(:resize)
- def resize(*args)
- # Resize the viewport. Can call with (X, Y, WIDTH, HEIGHT) or (RECT).
- self.rect = args[0].is_a?(Rect) ? args[0] : Rect.new(*args)
- end
- end
- #--------------------------------------------------------------------------
- # * New method: update_viewport_sizes
- #--------------------------------------------------------------------------
- unless method_defined?(:update_viewport_sizes)
- def update_viewport_sizes
- map = $game_map
- w, h = Graphics.width, Graphics.height
- hor = map.respond_to?(:loop_horizontal?) && map.loop_horizontal?
- ver = map.respond_to?(:loop_vertical?) && map.loop_vertical?
- dx = w > map.width * 32 && !hor ? (w - map.width * 32) / 2 : 0
- dw = hor ? w : [w, map.width * 32].min
- dy = h > map.height * 32 && !ver ? (h - map.height * 32) / 2 : 0
- dh = ver ? h : [h, map.height * 32].min
- resize(Rect.new(dx, dy, dw, dh))
- end
- end
- end
- #===============================================================================
- # ** Plane
- #===============================================================================
- class CRPlane < Sprite
- def z=(z)
- # Change the Z value of the viewport, not the sprite.
- super(z * 1000)
- end
- def ox=(ox)
- return if @bitmap == nil
- # Have viewport stay in loop on X-axis.
- super(ox % @bitmap.width)
- end
- def oy=(oy)
- return if @bitmap == nil
- # Have viewport stay in loop on Y-axis.
- super(oy % @bitmap.height)
- end
- def bitmap
- # Return the single bitmap, before it was tiled.
- return @bitmap
- end
- def bitmap=(tile)
- @bitmap = tile
- # Calculate the number of tiles it takes to span screen in both directions.
- xx = 1 + ($resolution.width.to_f / tile.width).ceil
- yy = 1 + ($resolution.height.to_f / tile.height).ceil
- # Create appropriately sized bitmap, then tile across it with source image.
- plane = Bitmap.new(@bitmap.width * xx, @bitmap.height * yy)
- (0..xx).each {|x| (0..yy).each {|y|
- plane.blt(x * @bitmap.width, y * @bitmap.height, @bitmap, @bitmap.rect)
- }}
- # Set the bitmap to the sprite through its super class (Sprite).
- super(plane)
- end
- # Redefine methods dealing with coordinates (defined in super) to do nothing.
- define_method(:x) {|*x|}
- define_method(:y) {|*y|}
- define_method(:x=) {|*x|}
- define_method(:y=) {|*y|}
- end
- #==============================================================================
- # ** Spriteset_Map
- #------------------------------------------------------------------------------
- # This class brings together map screen sprites, tilemaps, etc.
- # It's used within the Scene_Map class.
- #==============================================================================
- class Spriteset_Map
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- # Checked whether :drg_spriteset_viewport_adjust is already exist
- # Drago - Core Engine already has this method
- unless method_defined?(:drg_spriteset_viewport_adjust)
- # Method Aliasing
- alias_method :drg_spriteset_viewport_adjust, :update
- #--------------------------------------------------------------------------
- # * Aliased method: update
- #--------------------------------------------------------------------------
- def update(*args)
- # If resolution is changing
- if viewport_size_change?
- @viewport_map_width = $game_map.width
- @viewport_map_height = $game_map.height
- @viewport_screen_width = Graphics.width
- @viewport_screen_height = Graphics.height
- # Change all viewport resolution
- [@viewport1,@viewport2,@viewport3].each { |v| v.update_viewport_sizes }
- end
- drg_spriteset_viewport_adjust(*args)
- end
- end
- #--------------------------------------------------------------------------
- # * New method: viewport_size_change?
- #--------------------------------------------------------------------------
- def viewport_size_change?
- return true if @viewport_map_width != $game_map.width
- return true if @viewport_map_height != $game_map.height
- return true if @viewport_screen_width != Graphics.width
- return true if @viewport_screen_height != Graphics.height
- end
- #--------------------------------------------------------------------------
- # * New method: reload_tilemap
- #--------------------------------------------------------------------------
- def reload_tilemap
- @tilemap.respond_to?(:dispose) && @tilemap.dispose
- @tilemap = $resolution.enabled? ? CRTilemap.new(@viewport1) : 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 = $resolution.enabled? ? $game_map.cr_map_data : $game_map.data
- @tilemap.priorities = $game_map.priorities
- end
- end
- #==============================================================================
- # ** Graphics
- #------------------------------------------------------------------------------
- # This module handles all Graphics
- #==============================================================================
- class << Graphics
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- unless method_defined?(:drg_spriteset_viewport_adjust)
- alias_method :drg_spriteset_viewport_adjust, :update
- #--------------------------------------------------------------------------
- # * Aliased method: update
- #--------------------------------------------------------------------------
- def update(*args)
- check_center_player
- drg_spriteset_viewport_adjust(*args)
- end
- #--------------------------------------------------------------------------
- # * New method: check_center_player
- #--------------------------------------------------------------------------
- def check_center_player
- return unless $resolution
- zoom_x = $game_map.respond_to?(:zoom_x) ? $game_map.zoom_x : 1.0
- zoom_y = $game_map.respond_to?(:zoom_y) ? $game_map.zoom_y : 1.0
- if $resolution.fullscreen? || !$resolution.enabled?
- unless Game_Player.const_get(:CENTER_X) == ((640 / 2.0) / zoom_x - 16).ceil * 4
- Game_Player.const_set(:CENTER_X, ((640 / 2.0) / zoom_x - 16).ceil * 4)
- Game_Player.const_set(:CENTER_Y, ((480 / 2.0) / zoom_y - 16).ceil * 4)
- $game_player && $game_player.center($game_player.x,$game_player.y)
- end
- else
- $resolution.change_resolution if viewport_size_change?
- unless Game_Player.const_get(:CENTER_X) == (($resolution.width / 2.0) / zoom_x - 16).ceil * 4
- Game_Player.const_set(:CENTER_X, (($resolution.width / 2.0) / zoom_x - 16).ceil * 4)
- Game_Player.const_set(:CENTER_Y, (($resolution.height / 2.0) / zoom_y - 16).ceil * 4)
- $game_player && $game_player.center($game_player.x,$game_player.y)
- end
- end
- end
- #--------------------------------------------------------------------------
- # * New method: viewport_size_change?
- #--------------------------------------------------------------------------
- def viewport_size_change?
- return false unless $resolution
- return false if $resolution.fullscreen?
- return true if (Graphics.width - $resolution.width).abs > 30
- return true if (Graphics.height - $resolution.height).abs > 30
- end
- end
- end
- #==============================================================================
- # ** Spriteset_Map
- #------------------------------------------------------------------------------
- # This class brings together map screen sprites, tilemaps, etc.
- # It's used within the Scene_Map class.
- #==============================================================================
- class Spriteset_Map
- #--------------------------------------------------------------------------
- # * Public Instance Variable
- #--------------------------------------------------------------------------
- attr_reader :tilemap
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- alias_method :drg_weather_fix_update, :update
- #--------------------------------------------------------------------------
- # * Aliased method: update
- #--------------------------------------------------------------------------
- def update(*args)
- weather_fix_custom_resolution
- drg_weather_fix_update(*args)
- end
- #--------------------------------------------------------------------------
- # * New method: weather_fix_custom_resolution
- #--------------------------------------------------------------------------
- def weather_fix_custom_resolution
- if ($resolution.enabled? && @tilemap.is_a?(Tilemap)) ||
- (!$resolution.enabled? && @tilemap.is_a?(CRTilemap))
- reload_tilemap
- end
- if @panorama.is_a?(Plane)
- z = @panorama.z
- @panorama.dispose if @panorama.respond_to?(:dispose)
- @panorama = CRPlane.new(@viewport1)
- @panorama.z = z
- end
- if @fog.is_a?(Plane)
- z = @fog.z
- @fog.dispose if @fog.respond_to?(:dispose)
- @fog = CRPlane.new(@viewport1)
- @fog.z = z
- end
- if @weather.is_a?(RPG::Weather)
- @weather.dispose if @weather.respond_to?(:dispose)
- @weather = Spriteset_Weather.new(@viewport1)
- end
- end
- end
- #==============================================================================
- # ** Spriteset_Weather
- #------------------------------------------------------------------------------
- # A class for weather effects (rain, storm, and snow). It is used within the
- # Spriteset_Map class.
- #==============================================================================
- class Spriteset_Weather
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :type # Weather type
- attr_accessor :ox # X coordinate of origin
- attr_accessor :oy # Y coordinate of orgin
- attr_reader :power # Intensity
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(viewport = nil)
- @viewport = viewport
- init_members
- create_rain_bitmap
- create_storm_bitmap
- create_snow_bitmap
- end
- #--------------------------------------------------------------------------
- # * Initialize Member Variables
- #--------------------------------------------------------------------------
- def init_members
- @type = :none
- @ox = 0
- @oy = 0
- @power = 0
- @sprites = []
- end
- #--------------------------------------------------------------------------
- # * Free
- #--------------------------------------------------------------------------
- def dispose
- @sprites.each {|sprite| sprite.dispose }
- @rain_bitmap.dispose
- @storm_bitmap.dispose
- @snow_bitmap.dispose
- end
- #--------------------------------------------------------------------------
- # * Particle Color 1
- #--------------------------------------------------------------------------
- def particle_color1
- Color.new(255, 255, 255, 192)
- end
- #--------------------------------------------------------------------------
- # * Particle Color 2
- #--------------------------------------------------------------------------
- def particle_color2
- Color.new(255, 255, 255, 96)
- end
- #--------------------------------------------------------------------------
- # * Create [Rain] Weather Bitmap
- #--------------------------------------------------------------------------
- def create_rain_bitmap
- @rain_bitmap = Bitmap.new(7, 42)
- 7.times {|i| @rain_bitmap.fill_rect(6-i, i*6, 1, 6, particle_color1) }
- end
- #--------------------------------------------------------------------------
- # * Create [Storm] Weather Bitmap
- #--------------------------------------------------------------------------
- def create_storm_bitmap
- @storm_bitmap = Bitmap.new(34, 64)
- 32.times do |i|
- @storm_bitmap.fill_rect(33-i, i*2, 1, 2, particle_color2)
- @storm_bitmap.fill_rect(32-i, i*2, 1, 2, particle_color1)
- @storm_bitmap.fill_rect(31-i, i*2, 1, 2, particle_color2)
- end
- end
- #--------------------------------------------------------------------------
- # * Create [Snow] Weather Bitmap
- #--------------------------------------------------------------------------
- def create_snow_bitmap
- @snow_bitmap = Bitmap.new(6, 6)
- @snow_bitmap.fill_rect(0, 1, 6, 4, particle_color2)
- @snow_bitmap.fill_rect(1, 0, 4, 6, particle_color2)
- @snow_bitmap.fill_rect(1, 2, 4, 2, particle_color1)
- @snow_bitmap.fill_rect(2, 1, 2, 4, particle_color1)
- end
- #--------------------------------------------------------------------------
- # * Set Weather Intensity
- #--------------------------------------------------------------------------
- def power=(power)
- @power = power
- (sprite_max - @sprites.size).times { add_sprite }
- (@sprites.size - sprite_max).times { remove_sprite }
- end
- alias_method :max, :power
- alias_method :max=, :power=
- #--------------------------------------------------------------------------
- # * Get Maximum Number of Sprites
- #--------------------------------------------------------------------------
- def sprite_max
- (@power * 10).to_i
- end
- #--------------------------------------------------------------------------
- # * Add Sprite
- #--------------------------------------------------------------------------
- def add_sprite
- sprite = Sprite.new(@viewport)
- sprite.opacity = 0
- @sprites.push(sprite)
- end
- #--------------------------------------------------------------------------
- # * Delete Sprite
- #--------------------------------------------------------------------------
- def remove_sprite
- sprite = @sprites.pop
- sprite.dispose if sprite
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- update_screen
- @sprites.each {|sprite| update_sprite(sprite) }
- end
- #--------------------------------------------------------------------------
- # * Update Screen
- #--------------------------------------------------------------------------
- def update_screen
- @viewport.tone.set(-dimness, -dimness, -dimness)
- end
- #--------------------------------------------------------------------------
- # * Get Dimness
- #--------------------------------------------------------------------------
- def dimness
- (@power * 6).to_i
- end
- #--------------------------------------------------------------------------
- # * Update Sprite
- #--------------------------------------------------------------------------
- def update_sprite(sprite)
- sprite.ox = @ox
- sprite.oy = @oy
- case @type
- when 1, :rain
- update_sprite_rain(sprite)
- when 2, :storm
- update_sprite_storm(sprite)
- when 3, :snow
- update_sprite_snow(sprite)
- end
- create_new_particle(sprite) if sprite.opacity < 64
- end
- #--------------------------------------------------------------------------
- # * Update Sprite [Rain]
- #--------------------------------------------------------------------------
- def update_sprite_rain(sprite)
- sprite.bitmap = @rain_bitmap
- sprite.x -= 1
- sprite.y += 6
- sprite.opacity -= 12
- end
- #--------------------------------------------------------------------------
- # * Update Sprite [Storm]
- #--------------------------------------------------------------------------
- def update_sprite_storm(sprite)
- sprite.bitmap = @storm_bitmap
- sprite.x -= 3
- sprite.y += 6
- sprite.opacity -= 12
- end
- #--------------------------------------------------------------------------
- # * Update Sprite [Snow]
- #--------------------------------------------------------------------------
- def update_sprite_snow(sprite)
- sprite.bitmap = @snow_bitmap
- sprite.x -= 1
- sprite.y += 3
- sprite.opacity -= 12
- end
- #--------------------------------------------------------------------------
- # * Create New Particle
- #--------------------------------------------------------------------------
- def create_new_particle(sprite)
- sprite.x = rand(Graphics.width + 100) - 100 + @ox
- sprite.y = rand(Graphics.height + 200) - 200 + @oy
- sprite.opacity = 160 + rand(96)
- end
- end
- # Call the resolution, setting it to a global variable for plug-ins.
- $resolution = Resolution.new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement