=begin
SCRIPT CREATED BY NEWOLD
20-09-2013
FREE USE
DESCRIPTION
Displays a transition similar to Paper Mario game in Game Cube
(Great for use before changing scene!!!)
(You can watch a preview in this video in minute 3:13
http://www.youtube.com/watch?v=RayrWDD7O10
)
******************************** INSTRUCTION ********************************
Put over main script.
You call this transition using command call script and write this code
---------------------------------------------------------------------------
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
PPT.set(
'image*',
'fx*',
Columns*,Rows*,EventsList*)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
---------------------------------------------------------------------------
and change values marked with * with the following:
--------------------------------------------------------------------------------
- image* : filename of the image to display in your game folder.
You can add an animated image that is divided into several rows and columns
adding at the end the name of the image as follows:
[a number] (Example: [7]) indicates that the image is divided into
x columns (7 columns in the example)
[a number, other number] (Ejemplo: [7,5]) indicates that the image is divided into
x columns and y rows (7 columns and 5 rows in the example)
examples:
flower <- image called flower divided into 1 column and 1 row
flower[2] <- image called flower divided into 2 column and 1 row
flower[2,2] <- image called flower divided into 2 columns and 2 rows
--------------------------------------------------------------------------------
- fx* : filename of the sound to play when each image appear.
(nil if you don't want to put a sound)
--------------------------------------------------------------------------------
- Columns* : Number of columns of images that will be on display
--------------------------------------------------------------------------------
- Rows* : Number of rows of images that will be on display
--------------------------------------------------------------------------------
- EventsList* : List of ids corresponding to events that will be updated
while playing the transition ([ID 1, ID 2, ID 3, ...])
--------------------------------------------------------------------------------
Global Example:
PPT.set(
'Graphics/Pictures/Image01[6,1]',
'Audio/SE/sound01',
5,4,[5,6,1,16])
=end
#==============================================================================
module PPT
#--------------------------------------------------------------------------
def PPT.set(image,fx=nil,dH=16,dV=16,events_list=[])
@fx = fx
@dH = dH
@dV = dV
@max = @dH * @dV
@x, @y = 0, 0
@hidden = false
@sprites = []
@mode1 = 0
@mode2 = 0
@cnt = 1
@events_list = events_list
if defined?(Graphics.width) and defined?(Graphics.height)
@w, @h = Graphics.width, Graphics.height
else
@w, @h = 640, 480
end
w, h = @w/@dH,@h/@dV
@modX = (@w - (w * @dH)) / 2
@modY = (@h - (h * @dV)) / 2
@b = Bitmap.new(@w/@dH,@h/@dV)
image.match(/\[(\d+)]|\[(\d+),(\d+)]/)
unless $2.nil?
@frameW, @frameH = [$2.to_i,1].max, [$3.to_i,1].max
else
@frameW = $1.nil? ? 1 : [$1.to_i,1].max
@frameH = 1
end
begin
@pattern = Bitmap.new(image)
rescue => e
@pattern = Bitmap.new(1,1)
end
rect = Rect.new(0,0,@pattern.width/@frameW,@pattern.height/@frameH)
@b.stretch_blt(@b.rect,@pattern,rect)
self.run
end
#--------------------------------------------------------------------------
def PPT.eliminate_sprites
@showing_sprites = false
z = 255.0 / @sprites.size
z2 = 255 - z
@sprites.reverse.each {|s|
Audio.se_play(@fx) rescue nil
@background.opacity = z2
z2 -= z
for i in 0...5
s.zoom_x -= 0.2
if $scene.is_a?(Scene_Map)
$scene.update
end
Graphics.update
end
s.dispose
}
@background.dispose; @background = nil;
@sprites = []
set_finish_process
end
#--------------------------------------------------------------------------
def PPT.set_finish_process(v=true)
@finish_process = v
end
#--------------------------------------------------------------------------
def PPT.showing_sprites?
return @showing_sprites
end
#--------------------------------------------------------------------------
def PPT.in_process?
return false if @sprites.nil?
return @sprites.size > 0
end
#--------------------------------------------------------------------------
def PPT.finish_process?
return false if @finish_process.nil?
return @finish_process
end
#--------------------------------------------------------------------------
def PPT.events_list
return @events_list
end
#--------------------------------------------------------------------------
private
#--------------------------------------------------------------------------
def self.run
@background = Sprite.new
@background.bitmap = Bitmap.new(@w,@h)
@background.bitmap.fill_rect(0,0,@w,@h,Color.new(0,0,0))
@background.z = 50000000
@background.opacity = 0
z = (255.0/(@dH*@dV))
z2 = z
while @max > 0
self.create_sprite
@background.opacity = z2
z2 += z
@max -= 1
end
@background.opacity = 255
self.animation_sprites
@showing_sprites = true
set_finish_process
end
#--------------------------------------------------------------------------
def self.create_sprite
Audio.se_play(@fx) rescue nil
w, h = @w/@dH,@h/@dV
s = Sprite.new
s.bitmap = @b
s.x = @x + @b.width / 2 + @modX
s.y = @y + @modY
s.ox = @b.width / 2
s.zoom_x = 0.2
s.z = 50000000
Graphics.update
for i in 0...4
s.zoom_x += 0.2
Graphics.update
end
@sprites << s
if @mode1 == 0 and @mode2 == 0
if @cnt == @dH or exist_sprite_in(@x + w,@y)
@mode2 = 1; @y += h; @cnt = 2
else
@x += w; @cnt += 1
end
elsif @mode1 == 0 and @mode2 == 1
if @cnt == @dV or exist_sprite_in(@x,@y+h)
@mode1 = 1; @x -= w; @cnt = 2
else
@y += h; @cnt += 1
end
elsif @mode1 == 1 and @mode2 == 1
if @cnt == @dH or exist_sprite_in(@x - w,@y)
@mode2 = 0; @y -= h; @cnt = 2
else
@x -= w; @cnt += 1
end
elsif @mode1 == 1 and @mode2 == 0
if @cnt == @dV or exist_sprite_in(@x,@y-h)
@mode1 = 0; @x += w; @cnt = 2
else
@y -= h; @cnt += 1
end
end
end
#--------------------------------------------------------------------------
def self.exist_sprite_in(x,y)
@sprites.each {|s| return true if s.x - s.ox - @modX == x and s.y - @modY == y}
return false
end
#--------------------------------------------------------------------------
def self.animation_sprites
frameW, frameH = 0, 0
n = (@frameW > 1 or @frameH > 1) ? 60 : 30
n.times {
Graphics.update
if Graphics.frame_count % 2 == 0
w = @pattern.width/@frameW * frameW
h = @pattern.height/@frameH * frameH
frameW += 1
if frameW >= @frameW
frameW = 0
frameH += 1
if frameH >= @frameH
frameH = 0
end
end
rect = Rect.new(w,h,@pattern.width/@frameW,@pattern.height/@frameH)
@b.clear
@b.stretch_blt(@b.rect,@pattern,rect)
end
}
rect = Rect.new(0,0,@pattern.width/@frameW,@pattern.height/@frameH)
@b.clear
@b.stretch_blt(@b.rect,@pattern,rect)
Graphics.update
end
#--------------------------------------------------------------------------
end
#==============================================================================
#==============================================================================
class Game_Event < Game_Character
unless defined?(newUpdateByNewold)
alias newUpdateByNewold update
end
def update
if (PPT.in_process? and PPT.events_list.include?(@id)) or
not PPT.in_process?
newUpdateByNewold
end
end
end
#==============================================================================
#==============================================================================
if Window_Message.superclass.name == 'Window_Selectable'
t = "class Window_Message < Window_Selectable;"
else
t = "class Window_Message < Window_Base"
end
t += "
unless defined?(newUpdateByNewold)
alias newUpdateByNewold update
end
def update
unless PPT.in_process?
newUpdateByNewold
end
end
end"
eval t
#==============================================================================
#==============================================================================
module Graphics
class << self
unless defined?(Graphics.updateGraphicsBynewold)
alias updateGraphicsBynewold update
end
def update
if PPT.showing_sprites?
PPT.eliminate_sprites
end
if PPT.finish_process?
PPT.set_finish_process(false)
end
updateGraphicsBynewold
end
unless defined?(Graphics.transitionGraphicsBynewold)
alias transitionGraphicsBynewold transition
end
def transition(*args)
if PPT.in_process? or PPT.finish_process?
transitionGraphicsBynewold(0)
else
transitionGraphicsBynewold(*args)
end
end
if defined?(Graphics.brightness)
unless defined?(Graphics.brightnessGraphicsBynewold)
alias brightnessGraphicsBynewold brightness
end
def brightness(*args)
unless PPT.in_process? or PPT.finish_process?
brightnessGraphicsBynewold(*args)
else
return 0
end
end
end
end
end
#==============================================================================