查看: 2945|回复: 1

[已经解决] 如何使“战斗镜头”和“敌人动态化”脚本兼容

[复制链接]
梦石
0
星屑
50
在线时间
108 小时
注册时间
2010-8-16
回帖
45
发表于 2015-8-18 15:16:00 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
请问如何使“战斗动态镜头”和“敌人动态化”两个脚本相兼容?
不过如果做起来很复杂的话就不劳烦您了(实在不行就只能舍弃一个了)

[pre lang="ruby"]#==============================================================================
# ★ RGSS3_バトラー表示拡張 Ver1.02
#==============================================================================
=begin

作者:tomoaky
webサイト:ひきも記 (http://hikimoki.sakura.ne.jp/)

戦闘シーンにおいてエネミーのスプライトに以下の効果を適用します。
  ・ランダムに左右反転
  ・Y座標を元に拡大縮小をおこない遠近感を演出
  ・一定間隔で拡大縮小をおこない息遣いを演出
  
行動不可状態のエネミーは息遣いが自動的に一時停止します

2012.04.05  Ver1.02
 ・アクターグラフィックに効果を適用しないように修正
    デフォルトの戦闘シーンでは特に意味はありません

2011.12.20  Ver1.01
  ・解像度に合わせて遠近効果の基準となるY座標を自動計算するように修正

2011.12.15  Ver1.0
  公開

=end

#==============================================================================
# □ 設定項目
#==============================================================================
module TMBSPREX
  # 不适用镜像翻转的小队IDで指定
  NO_MIRROR_TROOP = []
  
  # 不适用镜像翻转的敌人IDで指定
  NO_MIRROR_ENEMY = []
  
  # 遠近効果不适用的小队をIDで指定
  NO_ZOOM_TROOP = []
  
  # 遠近効果不适用的敌人をIDで指定
  NO_ZOOM_ENEMY = []
  
  # 呼吸效果不适用的小队をIDで指定
  NO_BREATH_TROOP = []
  
  # 呼吸效果不适用的敌人をIDで指定
  NO_BREATH_ENEMY = []
end
# 【目前1/3的几率镜像翻转】
#==============================================================================
# ■ Sprite_Battler
#==============================================================================
class Sprite_Battler < Sprite_Base
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  alias tmbsprex_sprite_battler_initialize initialize
  def initialize(viewport, battler = nil)
    tmbsprex_sprite_battler_initialize(viewport, battler)
    if battler && !battler.actor?
      unless TMBSPREX::NO_MIRROR_TROOP.include?($game_troop.troop.id)
        unless TMBSPREX::NO_MIRROR_ENEMY.include?(battler.enemy.id)
          self.mirror = (rand(3) == 0)      # 1/3的几率镜像翻转
        end
      end
      unless TMBSPREX::NO_ZOOM_TROOP.include?($game_troop.troop.id)
        unless TMBSPREX::NO_ZOOM_ENEMY.include?(battler.enemy.id)
          border_y = Graphics.height * 65 / 100
          self.zoom_x = (battler.screen_y - border_y) * 0.005 + 1.0
        end
      end
      unless TMBSPREX::NO_BREATH_TROOP.include?($game_troop.troop.id)
        unless TMBSPREX::NO_BREATH_ENEMY.include?(battler.enemy.id)
          @zoom_max = rand(30) + 150
          @zoom_count = rand(@zoom_max)
        end
      end
      @use_tmbsprex = true
    end
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  alias tmbsprex_sprite_battler_update update
  def update
    tmbsprex_sprite_battler_update
    if @use_tmbsprex
      self.zoom_y = self.zoom_x
      self.z = 50 + self.y
      if @zoom_max && @battler.movable?
        @zoom_count += 1
        @zoom_count = 0 if @zoom_count == @zoom_max
        f = Math.sin(Math::PI * @zoom_count / (@zoom_max / 2))
        self.zoom_y += f * 0.015 + 0.015
      end
    end
  end
end
[/pre]



[pre lang="ruby"]#==============================================================================
# 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 / 255.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
  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[/pre]

评分

参与人数 1赞 +1 收起 理由
13176593952 + 1

查看全部评分

梦石
0
星屑
880
在线时间
253 小时
注册时间
2015-1-24
回帖
95
发表于 2015-8-22 22:16:16 | 显示全部楼层
新建脚本,添加
#==============================================================================
# ■ Spriteset_Battle
#------------------------------------------------------------------------------
#  处理战斗画面的精灵的类。本类在 Scene_Battle 类的内部使用。
#==============================================================================
class Spriteset_Battle
  #--------------------------------------------------------------------------
  # ☆ 刷新敌人坐标
  #--------------------------------------------------------------------------
  def update_enemy_position
    for sprite in @enemy_sprites
      next if sprite.nil? || sprite.battler.nil?
      sprite.zoom_x = @battle_camera.zoom + sprite.zx
      sprite.zoom_y = @battle_camera.zoom + sprite.zy
      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

评分

参与人数 1梦石 +1 收起 理由
taroxd + 1 认可答案

查看全部评分

原创恐怖解谜  岛语
   原创悬疑解谜 雪疑
      原创悬疑风格伪R剧 《抉择CHoice》   【黑历史】

             一只来自北方的泥亾工作室,欢迎骚扰
回复 1 0

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部