03-03-2008, 06:48 AM
Widescreen
by Selwyn
by Selwyn
INTRODUCTION
Selwyn @ RMXP.Org Wed Jan 31, 2007 Wrote:I'm reposting a revision of my old script.
This script allows to give your game a widescreen effect for cutscenes for example. When you turn the widescreen mode on, the screen size retracts smoothly to the size you set.
Every Infos and Explanations within the script's header.
SCREENSHOTS
SCRIPT
The Script
[code]#==============================================================================
# ? WScreen
#------------------------------------------------------------------------------
# ?By Selwyn, Widescreen effect script
# released the 1st of February
#
# This script allows to give some cutscenes a 'widescreen' effect.
#
# The script is off by default (when you first start the game).
#
# By default, when the widescreen mode is turned on, it hides one tile at the
# top of the screen and one tile a the bottom.
#
# By default, the transition_speed is 3, you can change this value just a
# few lines below
#
# To turn the script on, put 'WScreen.turn_on' in a call script command of
# an event. Turn it off with 'WScreen.turn_off'
#
# To change the number tiles hidden in widescreen, use the following function
# in a call script command of an event :
# 'WScreen.size = NUMBER'
#
#==============================================================================
module WScreen
#--------------------------------------------------------------------------
# ? define instance variables
#--------------------------------------------------------------------------
@state = false
@tile_size = 1
@transition_speed = 3
#--------------------------------------------------------------------------
# ? WScreen.on?
# checks if the widescreen mode is on.
#--------------------------------------------------------------------------
def self.on?
return @state
end
#--------------------------------------------------------------------------
# ? WScreen.off?
# checks if the widescreen mode is off.
#--------------------------------------------------------------------------
def self.off?
return !@state
end
#--------------------------------------------------------------------------
# ? WScreen.turn_on
# turns the widescreen mode on.
#--------------------------------------------------------------------------
def self.turn_on
@state = true
$game_player.center($game_player.x, $game_player.y)
end
#--------------------------------------------------------------------------
# ? WScreen.turn_off
# turns the widescreen mode off.
#--------------------------------------------------------------------------
def self.turn_off
@state = false
$game_player.center($game_player.x, $game_player.y)
end
#--------------------------------------------------------------------------
# ? WScreen.size
# returns the number of hidden tiles when the widescreen mode is on.
#--------------------------------------------------------------------------
def self.size
return on? ? @tile_size : 0
end
#--------------------------------------------------------------------------
# ? WScreen.size = INTEGER
# set the number of tiles to hide when the widescreen mode is on.
#--------------------------------------------------------------------------
def self.size=(value)
@tile_size = [value % 9, 1].min
$game_player.center($game_player.x, $game_player.y)
end
#--------------------------------------------------------------------------
# ? WScreen.speed
# returns the transition speed between the off and on modes.
#--------------------------------------------------------------------------
def self.speed
return @transition_speed
end
end
#==============================================================================
# ? Game_Map
#------------------------------------------------------------------------------
# ?
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# ? scroll_down
#--------------------------------------------------------------------------
def scroll_down(distance)
ntiles = 15 - WScreen.size * 2
@display_y = [@display_y + distance, (self.height - ntiles) * 128].min
end
end
#==============================================================================
# ? Game_Player
#------------------------------------------------------------------------------
# ?
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ? center_y
#--------------------------------------------------------------------------
def center_y
n = 240 - WScreen.size * 32
return (n - 16) * 4
end
#--------------------------------------------------------------------------
# ? center
#--------------------------------------------------------------------------
def center(x, y)
max_x = ($game_map.width - 20) * 128
ntiles = 15 - WScreen.size * 2
max_y = ($game_map.height - ntiles) * 128
$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
#--------------------------------------------------------------------------
# ? update
#--------------------------------------------------------------------------
def update
last_moving = moving?
unless moving? or $game_system.map_interpreter.running? or
@move_route_forcing or $game_temp.message_window_showing
case Input.dir4
when 2
move_down
when 4
move_left
when 6
move_right
when 8
move_up
end
end
last_real_x = @real_x
last_real_y = @real_y
super
if @real_y > last_real_y and @real_y - $game_map.display_y > center_y
$game_map.scroll_down(@real_y - last_real_y)
end
if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
$game_map.scroll_left(last_real_x - @real_x)
end
if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
$game_map.scroll_right(@real_x - last_real_x)
end
if @real_y < last_real_y and @real_y - $game_map.display_y < center_y
$game_map.scroll_up(last_real_y - @real_y)
end
unless moving?
if last_moving
result = check_event_trigger_here([1,2])
if result == false
unless $DEBUG and Input.press?(Input::CTRL)
if @encounter_count > 0
@encounter_count -= 1
end
end
end
end
if Input.trigger?(Input::C)
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
end
end
end
end
#==============================================================================
# ? Spriteset_Map
#------------------------------------------------------------------------------
# ?
#==============================================================================
class Spriteset_Map
alias init_widescreen initialize
alias update_widescreen update
#--------------------------------------------------------------------------
# ? update
#--------------------------------------------------------------------------
def initialize
init_widescreen
if @viewport1.rect.height > 480 - (WScreen.size * 64)
@viewport1.rect.height = @viewport2.rect.height =
@viewport3.rect.height = 480 - (WScreen.size * 64)
oy = (480 - @viewport1.rect.height) / 2
@viewport1.rect.y = @viewport2.rect.y = @viewport3.rect.y = oy
end
end
#--------------------------------------------------------------------------
# ? update
#--------------------------------------------------------------------------
def update
sy = 480 - (WScreen.size * 64)
h = @viewport1.rect.height
if h != sy
n = [((sy - h) / WScreen.speed).abs, 1].max
@viewport1.rect.height += h > sy ? - n : n
@viewport2.rect.height += h > sy ? - n : n
@viewport3.rect.height += h > sy ? - n : n
oy = (480 - @viewport1.rect.height) / 2
@viewport1.rect.y = @viewport2.rect.y = @viewport3.rect.y = oy
end
update_widescreen
end
end[code]
# ? WScreen
#------------------------------------------------------------------------------
# ?By Selwyn, Widescreen effect script
# released the 1st of February
#
# This script allows to give some cutscenes a 'widescreen' effect.
#
# The script is off by default (when you first start the game).
#
# By default, when the widescreen mode is turned on, it hides one tile at the
# top of the screen and one tile a the bottom.
#
# By default, the transition_speed is 3, you can change this value just a
# few lines below
#
# To turn the script on, put 'WScreen.turn_on' in a call script command of
# an event. Turn it off with 'WScreen.turn_off'
#
# To change the number tiles hidden in widescreen, use the following function
# in a call script command of an event :
# 'WScreen.size = NUMBER'
#
#==============================================================================
module WScreen
#--------------------------------------------------------------------------
# ? define instance variables
#--------------------------------------------------------------------------
@state = false
@tile_size = 1
@transition_speed = 3
#--------------------------------------------------------------------------
# ? WScreen.on?
# checks if the widescreen mode is on.
#--------------------------------------------------------------------------
def self.on?
return @state
end
#--------------------------------------------------------------------------
# ? WScreen.off?
# checks if the widescreen mode is off.
#--------------------------------------------------------------------------
def self.off?
return !@state
end
#--------------------------------------------------------------------------
# ? WScreen.turn_on
# turns the widescreen mode on.
#--------------------------------------------------------------------------
def self.turn_on
@state = true
$game_player.center($game_player.x, $game_player.y)
end
#--------------------------------------------------------------------------
# ? WScreen.turn_off
# turns the widescreen mode off.
#--------------------------------------------------------------------------
def self.turn_off
@state = false
$game_player.center($game_player.x, $game_player.y)
end
#--------------------------------------------------------------------------
# ? WScreen.size
# returns the number of hidden tiles when the widescreen mode is on.
#--------------------------------------------------------------------------
def self.size
return on? ? @tile_size : 0
end
#--------------------------------------------------------------------------
# ? WScreen.size = INTEGER
# set the number of tiles to hide when the widescreen mode is on.
#--------------------------------------------------------------------------
def self.size=(value)
@tile_size = [value % 9, 1].min
$game_player.center($game_player.x, $game_player.y)
end
#--------------------------------------------------------------------------
# ? WScreen.speed
# returns the transition speed between the off and on modes.
#--------------------------------------------------------------------------
def self.speed
return @transition_speed
end
end
#==============================================================================
# ? Game_Map
#------------------------------------------------------------------------------
# ?
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# ? scroll_down
#--------------------------------------------------------------------------
def scroll_down(distance)
ntiles = 15 - WScreen.size * 2
@display_y = [@display_y + distance, (self.height - ntiles) * 128].min
end
end
#==============================================================================
# ? Game_Player
#------------------------------------------------------------------------------
# ?
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ? center_y
#--------------------------------------------------------------------------
def center_y
n = 240 - WScreen.size * 32
return (n - 16) * 4
end
#--------------------------------------------------------------------------
# ? center
#--------------------------------------------------------------------------
def center(x, y)
max_x = ($game_map.width - 20) * 128
ntiles = 15 - WScreen.size * 2
max_y = ($game_map.height - ntiles) * 128
$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
#--------------------------------------------------------------------------
# ? update
#--------------------------------------------------------------------------
def update
last_moving = moving?
unless moving? or $game_system.map_interpreter.running? or
@move_route_forcing or $game_temp.message_window_showing
case Input.dir4
when 2
move_down
when 4
move_left
when 6
move_right
when 8
move_up
end
end
last_real_x = @real_x
last_real_y = @real_y
super
if @real_y > last_real_y and @real_y - $game_map.display_y > center_y
$game_map.scroll_down(@real_y - last_real_y)
end
if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
$game_map.scroll_left(last_real_x - @real_x)
end
if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
$game_map.scroll_right(@real_x - last_real_x)
end
if @real_y < last_real_y and @real_y - $game_map.display_y < center_y
$game_map.scroll_up(last_real_y - @real_y)
end
unless moving?
if last_moving
result = check_event_trigger_here([1,2])
if result == false
unless $DEBUG and Input.press?(Input::CTRL)
if @encounter_count > 0
@encounter_count -= 1
end
end
end
end
if Input.trigger?(Input::C)
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
end
end
end
end
#==============================================================================
# ? Spriteset_Map
#------------------------------------------------------------------------------
# ?
#==============================================================================
class Spriteset_Map
alias init_widescreen initialize
alias update_widescreen update
#--------------------------------------------------------------------------
# ? update
#--------------------------------------------------------------------------
def initialize
init_widescreen
if @viewport1.rect.height > 480 - (WScreen.size * 64)
@viewport1.rect.height = @viewport2.rect.height =
@viewport3.rect.height = 480 - (WScreen.size * 64)
oy = (480 - @viewport1.rect.height) / 2
@viewport1.rect.y = @viewport2.rect.y = @viewport3.rect.y = oy
end
end
#--------------------------------------------------------------------------
# ? update
#--------------------------------------------------------------------------
def update
sy = 480 - (WScreen.size * 64)
h = @viewport1.rect.height
if h != sy
n = [((sy - h) / WScreen.speed).abs, 1].max
@viewport1.rect.height += h > sy ? - n : n
@viewport2.rect.height += h > sy ? - n : n
@viewport3.rect.height += h > sy ? - n : n
oy = (480 - @viewport1.rect.height) / 2
@viewport1.rect.y = @viewport2.rect.y = @viewport3.rect.y = oy
end
update_widescreen
end
end[code]
HOW TO USE
Put the above code in a new section above main.
TERMS AND CONDITIONS
As always, Give Credit and Enjoy!