# *** XRXS's Full-View Battleback & Movable Camera ver.2 *** built 221612
# by XRXS
#==============================================================================
# ** Customization point
#==============================================================================
module XRXS_BP8
#
# Camera Drift Speed
# ( SPEED1 : Distance number of partitions. Smaller values give quicker moves.
# SPEED2 : Lowest drift speed [ unit: Px/F ]
#
SPEED1 = 10
SPEED2 = 8
#
# Setting the width size of the GA
# ( 1024:XGA Size, 640:VGA Size )
GA_W = 900
end
#==============================================================================
# ** Scene_Battle (part 1)
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Start Party Command Phase
#--------------------------------------------------------------------------
alias xrxs_bp8_start_phase2 start_phase2
def start_phase2
if $ao.battle_camera
# Camera: Centering
$xcam.centering
end
# Original Call
xrxs_bp8_start_phase2
end
#--------------------------------------------------------------------------
# * Frame Updat (actor command phase : enemy selection)
#--------------------------------------------------------------------------
alias xrxs_bp8_update_phase3_enemy_select update_phase3_enemy_select
def update_phase3_enemy_select
if $ao.battle_camera
# Acquiring the enemy which currently being selected
enemy = $game_troop.enemies[@enemy_arrow.index]
# Camera: Attention
if @last_enemy_arrow != enemy
$xcam.watch(enemy)
@last_enemy_arrow = enemy
end
end
# Reset Call
xrxs_bp8_update_phase3_enemy_select
end
#--------------------------------------------------------------------------
# * End Enemy Selection
#--------------------------------------------------------------------------
alias xrxs_bp8_end_enemy_select end_enemy_select
def end_enemy_select
if $ao.battle_camera
# Camera: Centering
$xcam.centering
@last_enemy_arrow = nil
end
# Original Call
xrxs_bp8_end_enemy_select
end
#--------------------------------------------------------------------------
# * Frame Update (main phase step 2 : start action)
#--------------------------------------------------------------------------
alias xrxs_bp8_update_phase4_step2 update_phase4_step2
def update_phase4_step2
# Reset Call
xrxs_bp8_update_phase4_step2
if $ao.battle_camera
# In the system is changing to step 3
if @phase4_step == 3
# If the current battler is still on the field
if @active_battler.in_battlefield?
# Camera: Attention
$xcam.watch(@active_battler)
end
end
end
end
#--------------------------------------------------------------------------
# * Frame Update (main phase step 3 : animation for action performer)
#--------------------------------------------------------------------------
alias xrxs_bp8_update_phase4_step3 update_phase4_step3
def update_phase4_step3
# Reset Call
xrxs_bp8_update_phase4_step3
if $ao.battle_camera
# Calculating the average X value of the target to set the camera
x_average = 0
number = 0
cam_target = nil
for target in @target_battlers
if target.in_battlefield?
x_average += target.x
number += 1
cam_target = target
end
end
# If the camera target is found
if number > 0
# Set the object animation's position
animation = $data_animations[@animation2_id]
if animation != nil and animation.position == 3
# Camera: Centering
$xcam.centering
# Camera: Zoom Out
$xcam.zoomout
elsif number == 1
# Camera: Attention
$xcam.watch(cam_target)
else
# Camera: Using the designated X position
$xcam.watch_at(x_average / number)
end
end
end
end
#--------------------------------------------------------------------------
# * Start After Battle Phase
#--------------------------------------------------------------------------
alias xrxs_bp8_start_phase5 start_phase5
def start_phase5
if $ao.battle_camera
# Camera: Centering
$xcam.centering
# Original Call
end
xrxs_bp8_start_phase5
end
end
#------------------------------------------------------------------------------
# To customization point here
#==============================================================================
#------------------------------------------------------------------------------
#
# * Movable camera system *
#
#==============================================================================
# ** XCam
#------------------------------------------------------------------------------
# This class handles the movable camera.
#==============================================================================
class XCam
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :x
attr_reader :y
attr_reader :z
attr_accessor :x_destination
attr_accessor :y_destination
attr_accessor :z_destination
attr_accessor :watch_battler
attr_accessor :freeze_count
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Camera initial position
@x = 320
@y = 240
@z = 100
# Calculation of largest range
@x_max = 0
@y_max = 0
@z_max = XRXS_BP8::GA_W * 37 / 128
# The largest restriction of Z
@z = @z_max if @z > @z_max
# Camera: Centering
self.centering
# Initialization
@freeze_count = 0
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
@moved = false
# Renew of camera position
if @freeze_count > 0
# Freezing count is decreased
@freeze_count -= 1
return
end
# Coordinate acquisition
z_dest = @z_destination
x_dest = @watch_battler == nil ? @x_destination : @watch_battler.x
y_dest = @watch_battler == nil ? @y_destination : 88 + @watch_battler.y/2
# Camera: Z coordinate (priority)
if @z != z_dest
@z = slide(@z, z_dest, @z_speed, 37, @z_max)
@x_max = (@z_max - @z) * 64 / 37
@y_max = (@z_max - @z) * 48 / 37
@moved = true
end
# Camera: X coordinate
if @x != x_dest or @moved
@x = slide(@x, x_dest, @x_speed, 320 - @x_max, 320 + @x_max)
@moved = true
end
# Camera: Y coordinate
if @y != y_dest or @moved
@y = slide(@y, y_dest, @y_speed, 240 - @y_max, 240 + @y_max) ###############
@moved = true
end
end
#--------------------------------------------------------------------------
# * Sliding (Action returned = 'current location' to 'destination location')
#--------------------------------------------------------------------------
def slide(from, to, move_speed, to_min, to_max)
# Distinguishing the result
if (to - from).abs < move_speed
result = to
else
sign = from > to ? -1 : 1
result = from + sign * move_speed
end
# Return with the range
return [[result, to_min].max, to_max].min
end
#--------------------------------------------------------------------------
# * Moved?
#--------------------------------------------------------------------------
def moved?
return @moved
end
#--------------------------------------------------------------------------
# * Set Speed
#--------------------------------------------------------------------------
def set_speed
x_dest = @watch_battler == nil ? @x_destination : @watch_battler.x
y_dest = @watch_battler == nil ? @y_destination : 88 + @watch_battler.y/2
z_dest = @z_destination
@x_speed = [[(x_dest - @x).abs / XRXS_BP8::SPEED1, 1].max, XRXS_BP8::SPEED2].min
@y_speed = [[(y_dest - @y).abs / XRXS_BP8::SPEED1, 1].max, XRXS_BP8::SPEED2].min
@z_speed = [[(z_dest - @z).abs / XRXS_BP8::SPEED1, 1].max, XRXS_BP8::SPEED2].min
end
#--------------------------------------------------------------------------
# * Centering
#--------------------------------------------------------------------------
def centering
@watch_battler = nil
@x_destination = 320
@y_destination = 240
@z_destination = 185
set_speed
end
#--------------------------------------------------------------------------
# * Zoom Out
#--------------------------------------------------------------------------
def zoomout
@z_destination = 222
set_speed
end
#--------------------------------------------------------------------------
# * Watch
#--------------------------------------------------------------------------
def watch(battler)
@watch_battler = battler
@z_destination = 180
set_speed
end
#--------------------------------------------------------------------------
# * Watch At
#--------------------------------------------------------------------------
def watch_at(x)
@watch_battler = nil
@x_destination = x
@y_destination = 240
@z_destination = 185
set_speed
end
#--------------------------------------------------------------------------
# * Zoom
#--------------------------------------------------------------------------
def zoom
return 185.00 / self.z
end
end
#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
# This class deals with battlers. It's used as a superclass for the Game_Actor
# and Game_Enemy classes.
#==============================================================================
class Game_Battler
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :x # Battlefield side position (+ to the right)
attr_reader :y # Battlefield height position (+ lower)
attr_reader :z # Battlefield depth position (+ forewards)
#--------------------------------------------------------------------------
# * In Battlefield?
#--------------------------------------------------------------------------
def in_battlefield?
return false
end
end
#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
# This class handles enemies. It's used within the Game_Troop class
# ($game_troop).
#==============================================================================
class Game_Enemy < Game_Battler
#--------------------------------------------------------------------------
# * In Battlefield
#--------------------------------------------------------------------------
def in_battlefield?
return true
end
#--------------------------------------------------------------------------
# * Object Initialization
# troop_id : troop ID
# member_index : troop member index
#--------------------------------------------------------------------------
alias xrxs_bp8_initialize initialize
def initialize(troop_id, member_index)
if $ao.battle_camera
@z = 0
end
xrxs_bp8_initialize(troop_id, member_index)
end
#--------------------------------------------------------------------------
# * Get Battle Screen X-Coordinate
#--------------------------------------------------------------------------
alias x screen_x
def screen_x
if $ao.battle_camera
return self.x if $xcam == nil
return 320 + (self.x - $xcam.x) * 185 / $xcam.z
else
return x
end
end
#--------------------------------------------------------------------------
# * Get Battle Screen Y-Coordinate
#--------------------------------------------------------------------------
alias y screen_y
def screen_y
if $ao.battle_camera
return self.y if $xcam == nil
return 240 + (self.y - $xcam.y) * 185 / $xcam.z
else
return y
end
end
end
#==============================================================================
# ** Spriteset_Battle
#------------------------------------------------------------------------------
# This class brings together battle screen sprites. It's used within
# the Scene_Battle class.
#==============================================================================
class Spriteset_Battle
#--------------------------------------------------------------------------
# â—‹ Frame Update (movable camera)
#--------------------------------------------------------------------------
def update_xcam
# If the camera position moved
if $xcam.moved?
# Calculating zoom rate from camera position
zoom = 185.00 / $xcam.z
w = XRXS_BP8::GA_W / 2
h = w * 3 / 4
# Setting renewal of background
@battleback_sprite.zoom_x = zoom
@battleback_sprite.zoom_y = zoom
@battleback_sprite.x = (320 - $xcam.x) * zoom - w * (zoom - 1)
@battleback_sprite.y = (240 - $xcam.y) * zoom - h * (zoom - 1)
end
end
end
#==============================================================================
# --- Battle Sprite movable camera application ---
#==============================================================================
module XRXS_Cam_Deal
def update
# Recalls
super
if $ao.battle_camera
# Return if the battler is not in the battlefield
return if @battler == nil or not @battler.in_battlefield?
# Return if the bitmap is empty
return if self.bitmap == nil
# Modifies the zoom rate (the sprite coordinate & camera zoom)
zoom = 1.00 * 185 / (185 - @battler.z)
self.zoom_x = zoom * $xcam.zoom
self.zoom_y = zoom * $xcam.zoom
end
end
end
class Sprite_Battler < RPG::Sprite
include XRXS_Cam_Deal
end
#==============================================================================
# --- Damage following module ---
#==============================================================================
module XRXS_DamageFollow
def update
# Recalls
super
if $ao.battle_camera
# Return if no camera
return if $xcam == nil
# Return if no battler sprite or battler not in the battlefield
return if @battler == nil or not @battler.in_battlefield?
# Calculate the moving values
x_moved = @last_cam_x == nil ? 0 : $xcam.x - @last_cam_x
y_moved = @last_cam_y == nil ? 0 : $xcam.y - @last_cam_y
# Compile thef damage sprite arrangement
damage_sprites = [@_damage_sprite]
damage_sprites += @damage_sprites if @damage_sprites != nil
# Following camera
for sprite in damage_sprites
next if sprite == nil
next if sprite.disposed?
sprite.x -= x_moved
sprite.y -= y_moved
end
# Retain the original camera position
@last_cam_x = $xcam.x
@last_cam_y = $xcam.y
end
end
end
class Sprite_Battler < RPG::Sprite
include XRXS_DamageFollow
end
#==============================================================================
# ** Scene_Battle (part 1)
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
alias xrxs_bp8_main main
def main
if $ao.battle_camera
# Formation of movable camera
$xcam = XCam.new
end
# Original Call
xrxs_bp8_main
# Release the movable camera
$xcam = nil
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias xrxs_bp8_update update
def update
if $ao.battle_camera
# Update the movable camera
$xcam.update
end
# Original Call
xrxs_bp8_update
end
end
#------------------------------------------------------------------------------
#
# * Full-View System *
#
#==============================================================================
# ** Spriteset_Battle
#------------------------------------------------------------------------------
# This class brings together battle screen sprites. It's used within
# the Scene_Battle class.
#==============================================================================
class Spriteset_Battle
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias xrxs_bp8_initialize initialize
def initialize
# Original Call
xrxs_bp8_initialize
if $ao.battle_camera
# Acquiring graphic array
# Drawing up viewport 0
w = XRXS_BP8::GA_W
h = w * 3 / 4
x = 320 - w / 2
y = 200 - h / 2
@viewport0 = Viewport.new(x, y, w, h)
@viewport0.z = 0
# Modifying viewport 1
@viewport1.z += 1
@viewport1.rect.height = 480
# Battleback Recompilation (viewport 0 use)
@battleback_sprite.dispose
@battleback_sprite = Sprite.new(@viewport0)
@battleback_name = ""
# Update Battleback
update_battleback
end
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
alias xrxs_bp8_dispose dispose
def dispose
# Original Call
xrxs_bp8_dispose
if $ao.battle_camera
# Dispose viewport
@viewport0.dispose
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias xrxs_bp8_update update
def update
if $ao.battle_camera
# Frame Renewal (battle back)
update_battleback
# If camera exists, Frame renewal (movable camera)
update_xcam if defined? update_xcam
end
# Original Call
xrxs_bp8_update
if $ao.battle_camera
# Setting the shake position of the picture
@viewport0.ox = $game_screen.shake if @viewport0 != nil
end
end
#--------------------------------------------------------------------------
# * Update Battleback
#--------------------------------------------------------------------------
def update_battleback
# If file name is different from the current one
if @battleback_name != $game_temp.battleback_name
@battleback_name = $game_temp.battleback_name
if @battleback_sprite.bitmap != nil
@battleback_sprite.bitmap.dispose
end
# Acquiring graphic array
w = XRXS_BP8::GA_W
h = w * 3 / 4
# Obtain and resize the battleback
bg = RPG::Cache.battleback(@battleback_name)
xga = Bitmap.new(w, h)
xga.stretch_blt(xga.rect, bg, bg.rect)
# Apply the settings to the battleback
@battleback_sprite.bitmap = xga
end
end
end
#==============================================================================
# ---"If fighting," position correction module of picture "animation" ---
#==============================================================================
module XRXS_FullScreen_AnimationOffset
def animation_set_sprites(sprites, cell_data, position)
super
if $ao.battle_camera
for i in 0..15
sprite = sprites[i]
pattern = cell_data[i, 0]
if sprite == nil or pattern == nil or pattern == -1
next
end
if position == 3
if self.viewport != nil
sprite.y = 160 # Just this one line modification
sprite.y += cell_data[i, 2]
end
end
end
end
end
end
class Sprite_Battler < RPG::Sprite
include XRXS_FullScreen_AnimationOffset
end