Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # DRG Fade Room Effect
- # Version: 3.00
- # Author : LiTTleDRAgo
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- ($imported ||= {})[:drg_fade_effect_room] = 3.00
- module LiTTleDRAgo
- FADE_ROOM = {
- #-----------------------------------------------------------------
- # Editable Section
- #
- # - Format :
- # MAP_ID => "Command",
- #
- # -or-
- #
- # MAP_ID => {
- # 'ROOM_1' => "Command",
- # 'ROOM_2' => "Command",
- # 'ROOM_3' => "Command",
- # },
- #-----------------------------------------------------------------
- 2 => {
- # This area will forever hidden in the map
- # Grid at (0,0) to (20,6) will be hidden WITH the exception
- # at <10,2> to <18,6>
- 'Dark' => "
- <Color = 40, 40, 40, 255>
- (0,0,20,6),<10,2,18,6> #
- (0,7,20,22),<2,7,18,20>
- (2,18,5,20)
- ",
- # This room will be hidden but will showed when player inside the area
- # Room at (10,2) to (18,8) will be hidden and will showed again when
- # player is inside [10,2] to [18,8]
- "Room1" => "
- <Color = 40, 40, 40, 255>
- (10,2,18,8),[10,2,18,8] #
- ",
- # Room at (2,7) to (18,17) will be hidden with the exception
- # <10,7> to <18,8> and will showed again when player is inside
- # [2,7] to [18,17] and not inside {10,7} to {18,8}
- "Room2" => "
- <Color = 40, 40, 40, 255>
- (2,7,18,17),[2,7,18,17],<10,7,18,8>,{10,7,18,8} #
- (6,18,18,20),[2,7,18,17]
- ",
- },
- }
- #-----------------------------------------------------------------
- # End Editable
- #-----------------------------------------------------------------
- end
- RGSS = 1
- RGSS = 2 if Graphics.respond_to?(:brightness)
- RGSS = 3 if Graphics.methods.include?(:play_movie)
- raise "This version is not for RMXP" if RGSS == 1
- #==============================================================================
- # ** Spriteset_Map
- #------------------------------------------------------------------------------
- # This class brings together map screen sprites, tilemaps, etc.
- # It's used within the Scene_Map class.
- #==============================================================================
- class Spriteset_Map
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- alias_method :drg132_update, :update if !method_defined?(:drg132_update)
- alias_method :drg132_dispos, :dispose if !method_defined?(:drg132_dispos)
- #--------------------------------------------------------------------------
- # * Objects Initialization
- #--------------------------------------------------------------------------
- def init_fadesprite
- @fade_sprite.each {|m| m[0].dispose } if @fade_sprite
- @fade_sprite = []
- @fade_effect = a = ($game_system.fade_room[$game_map.map_id] || '').dup
- a = a.invert.keys.join if a && a.is_a?(Hash)
- a.to_s.split(/\n/).each {|a| create_fade_effect(a)} if a
- end
- #--------------------------------------------------------------------------
- # * check_fade_parameter
- #--------------------------------------------------------------------------
- def create_fade_effect(parameter)
- if parameter =~ /<Color = (\d+), (\d+), (\d+)>/i
- j = [$1.to_i,$2.to_i,$3.to_i,255]
- elsif parameter =~ /<Color = (\d+), (\d+), (\d+), (\d+)>/i
- j = [$1.to_i,$2.to_i,$3.to_i,$4.to_i]
- end
- @fade_time = [$1.to_i,$2.to_i] if parameter =~ /<Fade = (\d+), (\d+)>/i
- @fade_oxy = [$1.to_i,$2.to_i] if parameter =~ /<Move = (.+?), (.+?)>/i
- if parameter =~ /<Picture = (.+?), (.+?)>/i
- b = ["#{$1}","#{$2}"]
- b = (b == ['0']*2) ? [1,1] : ["Graphics/#{b.join('/')}"]
- @fade_picture = Bitmap.new(*b)
- end
- @fade_time ||= [16,16]
- @fade_oxy ||= [0,0]
- @fade_picture ||= Bitmap.new(1,1)
- @fade_color = Color.new(*j) if !j.nil? && j[0..2] != [0]*3
- if parameter =~ /\((.+?),(.+?),(\d+),(\d+)\)/
- a, e = [$1.to_i,$2.to_i,$3.to_i,$4.to_i], [-1]*4
- if parameter =~ /\[(\d+),(\d+),(\d+),(\d+)\]/
- e = [$1.to_i,$2.to_i,$3.to_i,$4.to_i]
- elsif parameter =~ /\[(\d+),(\d+)\]/
- e = [$1.to_i,$2.to_i,$1.to_i,$2.to_i]
- end
- elsif parameter =~ /\(\[(\d+),(\d+),(\d+),(\d+)\]\)/
- a = e = [$1.to_i,$2.to_i,$3.to_i,$4.to_i]
- elsif parameter =~ /\(\[(\d+),(\d+)\]\)/
- a = e = [$1.to_i,$2.to_i,$1.to_i,$2.to_i]
- elsif parameter =~ /\((\d+),(\d+)\)/
- a, e = [$1.to_i,$2.to_i,$1.to_i,$2.to_i], [0]*4
- end
- return unless !a.nil? && a.flatten[0].is_a?(Numeric) && @fade_color
- sw = [a[2]-a[0].abs, a[3]-a[1].abs]
- sa = [sw[0] > 0 ? 16 : 0 , sw[1] > 0 ? 16 : 0]
- sa = [0,0]
- x,y = [a[0]*32+sa[0],0].max, [a[1]*32+sa[1],0].max
- w,h = [sw[0]+1,1].max*32,[sw[1]+1,1].max*32
- s = Sprite.new(@viewport1)
- s.bitmap = Bitmap.new(w,h)
- s.bitmap.fill_rect(0,0,s.bitmap.width,s.bitmap.height,@fade_color)
- s.bitmap.stretch_blt(s.bitmap.rect, @fade_picture, @fade_picture.rect)
- s.x, s.y, s.z, tc = x, y, 200, Color.new(*[0]*4)
- mask = [s, e, [], fade_coord_player]
- if parameter =~ /<(\d+),(\d+),(\d+),(\d+)>/
- a,b,c,d = $1.to_i,$2.to_i,$3.to_i,$4.to_i
- s.bitmap.fill_rect(a*32-s.x,b*32-s.y,(c-a+1)*32,(d-b+1)*32,tc)
- elsif parameter =~ /<(\d+),(\d+)>/
- a,b,c,d = $1.to_i, $2.to_i, $1.to_i, $2.to_i
- s.bitmap.fill_rect(a*32-s.x,b*32-s.y,(c-a+1)*32,(d-b+1)*32,tc)
- end
- if parameter =~ /{(\d+),(\d+),(\d+),(\d+)}/
- mask[2] = [$1.to_i, $2.to_i, $3.to_i, $4.to_i]
- elsif parameter =~ /{(\d+),(\d+)}/
- mask[2] = [$1.to_i, $2.to_i,$1.to_i, $2.to_i]
- end
- if parameter =~ /<{(\d+),(\d+),(\d+),(\d+)}>/
- a,b,c,d = $1.to_i,$2.to_i,$3.to_i,$4.to_i
- s.bitmap.fill_rect(a*32-s.x,b*32-s.y,(c-a+1)*32,(d-b+1)*32,tc)
- mask[2] = [a,b,c,d]
- elsif parameter =~ /<{(\d+),(\d+)}>/
- a,b,c,d = $1.to_i,$2.to_i,$1.to_i,$2.to_i
- s.bitmap.fill_rect(a*32-s.x,b*32-s.y,(c-a+1)*32,(d-b+1)*32,tc)
- mask[2] = [a,b,c,d]
- end
- mask[0].ox, mask[0].oy = fade_disp_map
- mask[4..6] = (mask[1][0]..mask[1][2]),(mask[1][1]..mask[1][3]),@fade_time
- mask[7..11] = s.bitmap.dup,0,0,@fade_oxy[0],@fade_oxy[1]
- mask[0].opacity = mask[4] === mask[3][0] && mask[5] === mask[3][1] &&
- (mask[2].empty? || !((mask[2][0]..mask[2][2]) === mask[3][0]&&
- (mask[2][1]..mask[2][3]) === mask[3][1])) ? 0 : 255
- (@fade_sprite ||= []) << mask
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- $game_system.init_fade_room if $game_system.fade_room.nil?
- ($game_system.fade_room[$game_map.map_id] || '') != @fade_effect ||
- @fade_sprite.nil? ? init_fadesprite : @fade_sprite.each {|mask|
- mask[0].ox, mask[0].oy = fade_disp_map
- if mask[1] != [-1]*4
- a = fade_coord_player
- a = [mask[4] === a[0] && mask[5] === a[1] &&
- (mask[2].empty? || !((mask[2][0]..mask[2][2]) === a[0] &&
- (mask[2][1]..mask[2][3]) === a[1])), mask[0].opacity,mask[6]].flatten
- mask[0].opacity = a[0] ? [a[1] - a[3],0].max : [a[1] + a[2], 255].min
- end
- next if mask[10] == 0 && mask[11] == 0
- w,h = mask[0].bitmap.width, mask[0].bitmap.height
- mask[0].bitmap.blt(mask[8],mask[9], mask[7], mask[7].rect )
- mask[0].bitmap.blt(mask[8],h+mask[9], mask[7], mask[7].rect )
- mask[0].bitmap.blt(mask[8],-h+mask[9], mask[7], mask[7].rect )
- mask[0].bitmap.blt(w+mask[8],mask[9], mask[7], mask[7].rect )
- mask[0].bitmap.blt(-w+mask[8],mask[9], mask[7], mask[7].rect )
- mask[0].bitmap.blt(w+mask[8],h+mask[9], mask[7], mask[7].rect )
- mask[0].bitmap.blt(w+mask[8],-h+mask[9], mask[7], mask[7].rect )
- mask[0].bitmap.blt(-w+mask[8],h+mask[9], mask[7], mask[7].rect )
- mask[0].bitmap.blt(-w+mask[8],-h+mask[9], mask[7], mask[7].rect )
- mask[8] = mask[8] >= w || mask[8] <= -w ? 0 : mask[8] + mask[10]
- mask[9] = mask[9] >= h || mask[9] <= -h ? 0 : mask[9] + mask[11] }
- drg132_update
- end
- #--------------------------------------------------------------------------
- # * Frame Dispose
- #--------------------------------------------------------------------------
- def dispose
- (@fade_sprite || []).each {|mask| mask[0].dispose }
- drg132_dispos
- end
- #--------------------------------------------------------------------------
- # * Fade Coord Player
- #--------------------------------------------------------------------------
- def fade_coord_player
- return [$game_player.real_x/128, $game_player.real_y/128] if RGSS == 1
- return [$game_player.x, $game_player.y]
- end
- #--------------------------------------------------------------------------
- # * Fade Display Map
- #--------------------------------------------------------------------------
- def fade_disp_map
- return [$game_map.display_x/4, $game_map.display_y/4] if RGSS == 1
- return [$game_map.display_x/8, $game_map.display_y/8] if RGSS == 2
- return [$game_map.display_x*32, $game_map.display_y*32] if RGSS == 3
- end
- end
- #==============================================================================
- # ** Game_System
- #------------------------------------------------------------------------------
- # This class handles data surrounding the system.
- # Refer to "$game_system" for the instance of this class.
- #==============================================================================
- class Game_System
- #--------------------------------------------------------------------------
- # * init_fade_room
- #--------------------------------------------------------------------------
- def init_fade_room() @fade_room = LiTTleDRAgo::FADE_ROOM end
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :fade_room
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement