class Scene_Battle #-------------------------------------------------------------------------- # ● 公開變數 #-------------------------------------------------------------------------- attr_reader :phase # 戰鬥phase attr_reader :active_battler # 目前行動者 end |
module RPG module Cache def self.battler2(filename, hue) self.load_bitmap("Graphics/Battlers2/", filename, hue) end end end |
self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue) |
self.bitmap = RPG::Cache.battler2(@battler_name, @battler_hue) |
if @battler.is_a?(Game_Actor) and @battler_visible # 不是主狀態的時候稍稍降低點透明度 if $game_temp.battle_main_phase self.opacity += 3 if self.opacity < 255 else self.opacity -= 3 if self.opacity > 207 end end |
# 如果是戰鬥不能或者是隱藏狀態就把透明度設定為 0 if @battler.hidden # or @battler.dead? self.opacity = 0 end |
if @battler.damage == nil and @battler.dead? if @battler.is_a?(Game_Enemy) $game_system.se_play($data_system.enemy_collapse_se) collapse # 移到這裡 else $game_system.se_play($data_system.actor_collapse_se) end # collapse # 註解這個 @battler_visible = false end |
# 檔案名稱和色相與目前情況有差異的情況下 if @battler.battler_name != @battler_name or @battler.battler_hue != @battler_hue # 獲取、設定點陣圖 @battler_name = @battler.battler_name @battler_hue = @battler.battler_hue self.bitmap = RPG::Cache.battler2(@battler_name, @battler_hue) # @width = bitmap.width # @height = bitmap.height setup_motion # 追加一個新方法 self.ox = @width / 2 self.oy = @height # 如果是戰鬥不能或者是隱藏狀態就把透明度設定為 0 if @battler.hidden # or @battler.dead? self.opacity = 0 end end |
#-------------------------------------------------------------------------- # ● 設置Motion變數 #-------------------------------------------------------------------------- def setup_motion @motion_id = 0 # 動作ID (判斷目前是站立、施法、受傷等) @motion_loop = true # motion要不要循環播放 @now_frame = 0 # 目前畫格,也就是顯示該motion哪一張圖 @frame_count = 0 # 目前畫格的時間計數 @frame_wait = 5 # 該畫格的等待時間 @damage_count = 0 # 受傷動作的持續時間 @frame_max = 4 # 每個motion最大frame數 @motion_max = 8 # 最大motion數 @width = bitmap.width / @frame_max @height = bitmap.height / @motion_max end |
#-------------------------------------------------------------------------- # ● 設置Motion變數 #-------------------------------------------------------------------------- def setup_motion @motion_id = 0 # 動作ID (判斷目前是站立、施法、受傷等) @motion_loop = true # motion要不要循環播放 @now_frame = 0 # 目前畫格,也就是顯示該motion哪一張圖 @frame_count = 0 # 目前畫格的時間計數 @frame_wait = 5 # 該畫格的等待時間 @damage_count = 0 # 受傷動作的持續時間 @frame_max = 4 # 每個motion最大frame數 @motion_max = 8 # 最大motion數 # ========== 我方角色 if @battler.is_a?(Game_Actor) case @battler.id when 100 # 100號角色 @frame_max = 6 @motion_max = 10 else # end # ========== 敵方角色 else # end @width = bitmap.width / @frame_max @height = bitmap.height / @motion_max end |
#-------------------------------------------------------------------------- # ● 設置Motion變數 #-------------------------------------------------------------------------- def setup_motion @motion_id = 0 @motion_loop = true @now_frame = 0 @frame_count = 0 @frame_wait = 5 @damage_count = 0 @frame_max = 4 @motion_max = 8 case @battler_name # 如果戰鬥圖名稱是 003-Fighter03 when "003-Fighter03" @frame_max = 6 @motion_max = 12 else # end @width = bitmap.width / @frame_max @height = bitmap.height / @motion_max end |
#-------------------------------------------------------------------------- # ● 刷新目前戰鬥分割圖 #-------------------------------------------------------------------------- def refresh_sprite_sheet self.src_rect.set(@now_frame*@width, @motion_id*@height, @width, @height) end |
src_rect.set(x, y, 寬, 高) |
#-------------------------------------------------------------------------- # ● 變更 motion # id:目標motion id # wait:每個frame的等待 # loop:motion要不要循環播放 #-------------------------------------------------------------------------- def change_motion(id, wait = 5, loop = true) @now_frame = 0 @frame_count = wait @frame_wait = wait @motion_id = id @motion_loop = loop @next_motion = next_data # 刷新目前圖像 refresh_sprite_sheet end |
#-------------------------------------------------------------------------- # ● 一開始的動作 #-------------------------------------------------------------------------- def start_motion # 陣亡 if @battler.dead? change_motion(5) # 重傷或無法行動 elsif @battler.hp < @battler.maxhp/4 || @battler.restriction == 4 change_motion(7) # 一般狀態 else change_motion(0) end end |
@battler_name = @battler.battler_name @battler_hue = @battler.battler_hue self.bitmap = RPG::Cache.battler2(@battler_name, @battler_hue) setup_motion start_motion |
# 傷害 if @battler.damage_pop damage(@battler.damage, @battler.critical) # 受傷motion if @battler.damage.is_a?(Numeric) && @battler.damage > 0 @damage_count = 20 change_motion(3, 5, false) end @battler.damage = nil @battler.critical = false @battler.damage_pop = false end |
if @battler.damage == nil and @battler.dead? if @battler.is_a?(Game_Enemy) $game_system.se_play($data_system.enemy_collapse_se) collapse else $game_system.se_play($data_system.actor_collapse_se) change_motion(5) # 加上這句 end @battler_visible = false end |
update_motion # 追加調用一個新方法 # 設定活動區塊的座標 self.x = @battler.screen_x self.y = @battler.screen_y self.z = @battler.screen_z |
#-------------------------------------------------------------------------- # ● 更新motion #-------------------------------------------------------------------------- def update_motion # ============== 我方角色 if @battler.is_a?(Game_Actor) case @battler.id when 100 # 100號角色 update_actor100_motion else # 其他的角色 update_common_motion end # ============== 敵方角色 else update_common_motion end end |
#-------------------------------------------------------------------------- # ● 共用motion #-------------------------------------------------------------------------- def update_common_motion # 存活且在場而且不是受傷中的情況下 if @battler_visible && @damage_count == 0 # 目標motion plan_id = 0 # 開始行動的場合 if @battler.phase > 3 and @battler.phase != 6 # 行動種類分歧 case @battler.current_action.kind when 0 # 基本 # 不變 when 1..2 # 技能和道具(1技能、2道具) if @battler.current_action.kind == 1 # 確認技能使用對象 scope = $data_skills[@battler.current_action.skill_id].scope else # 確認道具使用對象 scope = $data_items[@battler.current_action.item_id].scope end # 攻撃的場合 if scope < 3 plan_id = (@battler.current_action.kind == 1 ? 4 : 1) # 回復的場合 else plan_id = (@battler.current_action.kind == 1 ? 1 : 1) end # if scope < 3 end # case end # if @battler.phase > 3 # 防禦 if @battler.guarding? plan_id = 2 end # 戰鬥勝利 if $scene.phase == 5 && @battler.is_a?(Game_Actor) plan_id = 6 end # 重傷 if @battler.hp < @battler.maxhp/4 && (@battler.phase < 3 || @battler.phase > 5) && !@battler.guarding? if @battler.is_a?(Game_Actor) plan_id = 7 end end #無法行動的狀態 if @battler.restriction == 4 && $scene.phase != 5 && @battler.hp != 0 plan_id = 7 end # 如果需要變更motion if @motion_id != plan_id case plan_id when 6 # 勝利 change_motion(plan_id, 8, false) else change_motion(plan_id) end return end end # 受傷時間計時 @damage_count -= 1 if @damage_count > 0 # frame計時 @frame_count -= 1 if @frame_count >= 0 # 需要更新 frame 時 if @frame_count == 0 && @now_frame < @frame_max @frame_count = @frame_wait # 到達最大 frame 時 if @now_frame + 1 == @frame_max # 需要循環 @now_frame = 0 if @motion_loop else @now_frame += 1 end # 刷新目前圖像 refresh_sprite_sheet end end |
if @battler_visible && @damage_count == 0 |
if @motion_id != plan_id |
module RPG class Sprite < ::Sprite #-------------------------------------------------------------------------- # ● 常數 #-------------------------------------------------------------------------- CHANGE_HUE_ANIMATION = [105, 106] # 要跟隨使用者色相的戰鬥動畫ID #-------------------------------------------------------------------------- # ● 播放戰鬥動畫 #-------------------------------------------------------------------------- def animation(animation, hit, hue = 0) dispose_animation @_animation = animation return if @_animation == nil @_animation_hit = hit @_animation_duration = @_animation.frame_max animation_name = @_animation.animation_name animation_hue = @_animation.animation_hue if CHANGE_HUE_ANIMATION.include?(animation.id) hue = animation_hue + hue hue -= 360 if hue > 360 bitmap = RPG::Cache.animation(animation_name, hue) else bitmap = RPG::Cache.animation(animation_name, animation_hue) end if @@_reference_count.include?(bitmap) @@_reference_count[bitmap] += 1 else @@_reference_count[bitmap] = 1 end @_animation_sprites = [] if @_animation.position != 3 or not @@_animations.include?(animation) for i in 0..15 sprite = ::Sprite.new(self.viewport) sprite.bitmap = bitmap sprite.visible = false @_animation_sprites.push(sprite) end unless @@_animations.include?(animation) @@_animations.push(animation) end end update_animation end end end |
# 動畫 if @battler.animation_id != 0 animation = $data_animations[@battler.animation_id] hue = ($scene.active_battler ? $scene.active_battler.battler_hue : 0) animation(animation, @battler.animation_hit, hue) @battler.animation_id = 0 end |