#==============================================================================
# F14 - 战斗镜头 - By芙蕾娅
#------------------------------------------------------------------------------
# ★ - 新增 ☆ - 修改 ■ - 删除 ● - 无变更
#==============================================================================
module Freya
# 镜头帧速,数字越小越快
Camera_Frame_Speed = 12
# 镜头放大率,正常大小1.0,默认放大1.2
Take_Zoom = 1.2
# 背景增大率,默认0.1
# 避免默认素材背景在镜头移动后出现黑边所做的处理
Back_Zoom = 0.1
end
#==============================================================================
# ■ Battle_Camera
#------------------------------------------------------------------------------
# 保存着战斗镜头的讯息
#==============================================================================
class Battle_Camera
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :x
attr_accessor :y
attr_accessor :zoom
attr_accessor :new_zoom
attr_reader :center_width
attr_reader :center_height
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize
@x = @new_x = @center_width = Graphics.width / 2
@y = @new_y = @center_height = Graphics.height / 1.5
@zoom = @new_zoom = 1.0
@frame_speed = Freya::Camera_Frame_Speed
end
#--------------------------------------------------------------------------
# ● 初始化帧率
#--------------------------------------------------------------------------
def reset_frame_speed
@frame_speed = Freya::Camera_Frame_Speed
end
#--------------------------------------------------------------------------
# ● 设置镜头瞄准对象
#--------------------------------------------------------------------------
def look(target,zoom=nil,speed=nil)
if target.is_a?(Game_Enemy)
reset_frame_speed
@new_x = target.screen_x
@new_y = target.screen_y
@new_zoom = zoom unless zoom.nil?
@frame_speed = speed unless speed.nil?
end
end
#--------------------------------------------------------------------------
# ● 将镜头移至中心
#--------------------------------------------------------------------------
def center(zoom = 1.0)
@new_x = @center_width
@new_y = @center_height
@new_zoom = zoom
end
#--------------------------------------------------------------------------
# ● 计算x坐标
#--------------------------------------------------------------------------
def battler_x(battler)
distance = battler.screen_x - @x
value = distance * (@zoom - 1.0)
pos = battler.screen_x - (@x - @center_width)
return pos + value
end
#--------------------------------------------------------------------------
# ● 计算y坐标
#--------------------------------------------------------------------------
def battler_y(battler)
distance = battler.screen_y - @y
value = distance * (@zoom - 1.0)
pos = battler.screen_y - (@y - @center_height)
return pos + value
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
if @x != @new_x
@x = (@new_x - @x > 0) ?
[@x + move_speed_x, @new_x].min : [@x - move_speed_x, @new_x].max
end
if @y != @new_y
@y = (@new_y - @y > 0) ?
[@y + move_speed_y, @new_y].min : [@y - move_speed_y, @new_y].max
end
if @zoom != @new_zoom
@zoom = (@new_zoom - @zoom > 0) ?
[@zoom + zoom_speed, @new_zoom].min : [@zoom - zoom_speed, @new_zoom].max
end
end
#--------------------------------------------------------------------------
# ● 镜头x坐标与指定点x坐标的距离
#--------------------------------------------------------------------------
def dis_x
(@x - @new_x).abs
end
#--------------------------------------------------------------------------
# ● 镜头y坐标与指定点y坐标的距离
#--------------------------------------------------------------------------
def dis_y
(@y - @new_y).abs
end
#--------------------------------------------------------------------------
# ● 镜头放大率与指定放大率的差距
#--------------------------------------------------------------------------
def dis_zoom
(@zoom - @new_zoom).abs
end
#--------------------------------------------------------------------------
# ● 镜头x坐标移动速度
#--------------------------------------------------------------------------
def move_speed_x
return [(dis_x / @frame_speed).to_i, 1].max
end
#--------------------------------------------------------------------------
# ● 镜头y坐标移动速度
#--------------------------------------------------------------------------
def move_speed_y
return [(dis_y / @frame_speed).to_i, 1].max
end
#--------------------------------------------------------------------------
# ● 镜头缩放速度
#--------------------------------------------------------------------------
def zoom_speed
return [(dis_zoom / @frame_speed), 0.01].max
end
end
#==============================================================================
# ■ Sprite_Battler
#------------------------------------------------------------------------------
# 显示战斗者的精灵。根据 Game_Battler 类的实例自动变化。
#==============================================================================
class Sprite_Battler < Sprite_Base
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :hp_gauge
#--------------------------------------------------------------------------
# ☆ 设置动画的精灵
#--------------------------------------------------------------------------
def animation_set_sprites(frame)
cell_data = frame.cell_data
set_animation_origin
@ani_sprites.each_with_index do |sprite, i|
next unless sprite
pattern = cell_data[i, 0]
if !pattern || pattern < 0
sprite.visible = false
next
end
sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
sprite.visible = true
sprite.src_rect.set(pattern % 5 * 192,
pattern % 100 / 5 * 192, 192, 192)
if @ani_mirror
sprite.x = @ani_ox - cell_data[i, 1]
sprite.y = @ani_oy + cell_data[i, 2]
sprite.angle = (360 - cell_data[i, 4])
sprite.mirror = (cell_data[i, 5] == 0)
else
sprite.x = @ani_ox + cell_data[i, 1]
sprite.y = @ani_oy + cell_data[i, 2]
sprite.angle = cell_data[i, 4]
sprite.mirror = (cell_data[i, 5] == 1)
end
sprite.z = self.z + 300 + i
sprite.ox = 96
sprite.oy = 96
sprite.zoom_x = cell_data[i, 3] / 100.0 * self.zoom_x
sprite.zoom_y = cell_data[i, 3] / 100.0 * self.zoom_y
sprite.opacity = cell_data[i, 6] * self.opacity / 1.0
sprite.blend_type = cell_data[i, 7]
end
end
end
#==============================================================================
# ■ Spriteset_Battle
#------------------------------------------------------------------------------
# 处理战斗画面的精灵的类。本类在 Scene_Battle 类的内部使用。
#==============================================================================
class Spriteset_Battle
#--------------------------------------------------------------------------
# ★ 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :battle_camera
#--------------------------------------------------------------------------
# ☆ 初始化对象
#--------------------------------------------------------------------------
alias initialize_freya_camera initialize
def initialize
create_camera
initialize_freya_camera
end
#--------------------------------------------------------------------------
# ★ 创建镜头
#--------------------------------------------------------------------------
def create_camera
@battle_camera = Battle_Camera.new
end
#--------------------------------------------------------------------------
# ☆ 更新画面
#--------------------------------------------------------------------------
alias update_freya_camera update
def update
update_freya_camera
update_camera
actor_opacity = 0
end
#--------------------------------------------------------------------------
# ● 刷新镜头
#--------------------------------------------------------------------------
def update_camera
@battle_camera.update
update_battleback_position
update_enemy_position
end
#--------------------------------------------------------------------------
# ● 刷新背景坐标
#--------------------------------------------------------------------------
def update_battleback_position
zom = Freya::Take_Zoom + Freya::Back_Zoom
zoom = @back1_sprite.zoom_x = @back2_sprite.zoom_x = @battle_camera.zoom * zom
zoom = @back1_sprite.zoom_y = @back2_sprite.zoom_y = @battle_camera.zoom * zom
x = @back1_sprite.ox
y = @back1_sprite.oy
bbx = (x - (@battle_camera.x - @battle_camera.center_width))
bby = (y - (@battle_camera.y - @battle_camera.center_height))
@back1_sprite.x = @back2_sprite.x = bbx
@back1_sprite.y = @back2_sprite.y = bby
end
#--------------------------------------------------------------------------
# ● 刷新敌人坐标
#--------------------------------------------------------------------------
def update_enemy_position
for sprite in @enemy_sprites
next if sprite.nil? || sprite.battler.nil?
sprite.zoom_x = @battle_camera.zoom
sprite.zoom_y = @battle_camera.zoom
sprite.x = @battle_camera.battler_x(sprite.battler)
sprite.y = @battle_camera.battler_y(sprite.battler)
unless sprite.hp_gauge.nil?
sprite.hp_gauge.x = sprite.x - sprite.hp_gauge.width / 2
sprite.hp_gauge.y = sprite.y
end
end
end
end
#==============================================================================
# ■ Scene_Battle
#------------------------------------------------------------------------------
# 战斗画面
#==============================================================================
class Scene_Battle < Scene_Base
#--------------------------------------------------------------------------
# ★ 获取镜头
#--------------------------------------------------------------------------
def camera
return @spriteset.battle_camera
end
#--------------------------------------------------------------------------
# ☆ 使用技能/物品
#--------------------------------------------------------------------------
def use_item
camera.look(@subject,Freya::Take_Zoom)
wait(Freya::Camera_Frame_Speed)
item = @subject.current_action.item
@log_window.display_use_item(@subject, item)
@subject.use_item(item)
refresh_status
targets = @subject.current_action.make_targets.compact
camera.look(targets,Freya::Take_Zoom)
wait(Freya::Camera_Frame_Speed)
show_animation(targets, item.animation_id)
targets.each {|target| item.repeats.times { invoke_item(target, item) } }
camera.center
end
#--------------------------------------------------------------------------
# ☆ 应用技能/物品效果
#--------------------------------------------------------------------------
alias apply_item_effects_freya_camera apply_item_effects
def apply_item_effects(target, item)
camera.look(target, Freya::Take_Zoom)
wait(Freya::Camera_Frame_Speed)
apply_item_effects_freya_camera(target, item)
end
#--------------------------------------------------------------------------
# ☆ 发动反击
#--------------------------------------------------------------------------
alias invoke_counter_attack_freya_camera invoke_counter_attack
def invoke_counter_attack(target, item)
camera.look(target, Freya::Take_Zoom)
wait(Freya::Camera_Frame_Speed)
invoke_counter_attack_freya_camera(target, item)
end
#--------------------------------------------------------------------------
# ☆ 发动反射魔法攻击
#--------------------------------------------------------------------------
alias invoke_magic_reflection_freya_camera invoke_magic_reflection
def invoke_magic_reflection(target, item)
camera.look(target, Freya::Take_Zoom)
wait(Freya::Camera_Frame_Speed)
invoke_magic_reflection_freya_camera(target, item)
end
#--------------------------------------------------------------------------
# ☆ 显示普通动画
#--------------------------------------------------------------------------
def show_normal_animation(targets, animation_id, mirror = false)
animation = $data_animations[animation_id]
if animation
camera.center if animation.to_screen?
targets.each do |target|
camera.look(target, Freya::Take_Zoom) unless animation.to_screen?
target.animation_id = animation_id
target.animation_mirror = mirror
abs_wait_short unless animation.to_screen?
end
abs_wait_short if animation.to_screen?
end
end
end