设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1585|回复: 1
打印 上一主题 下一主题

[rgss]XP用的全動畫

[复制链接]

酱油的

梦石
0
星屑
970
在线时间
2161 小时
注册时间
2007-12-22
帖子
3271

贵宾

跳转到指定楼层
1
发表于 2012-5-17 01:01:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x

RUBY 代码复制
  1. #==============================================================================
  2. # ■ 全动画战斗
  3. #------------------------------------------------------------------------------
  4. #  By 禾西 on 2010.09.11
  5. #   应用脚本 彩虹神剑 By 66
  6. #==============================================================================
  7. # 基本上和另一个全动画脚本的设置一样
  8. #
  9. #简要介绍 by whbm:
  10. #    本脚本实现了战斗的动态效果,其中包含了待机、攻击、防御、挨打、胜利、死亡。类似于超级横版、超级战斗。但是本系统特色在于所有效果的实现并不是靠庞大的战斗图,而是使用了数据库中的动画。这样不仅突破了不同人不同祯数量的限制,并且方便了单动画单祯的修改。
  11. #使用方法:
  12. #    个人觉得还是比较简单,但是大量的怪物还是会令人头痛。
  13. #    1.数据库的设置
  14. #      敌人必要的动画有待机、挨打、死亡三个必要的动画
  15. #      角色必要的动画有待机、挨打、防御、死亡动态、胜利动态、死亡静态、胜利静态
  16. #
  17. #      死亡静态与胜利静态:动画中只有1祯,为相应动态动画的最后一祯
  18. #      
  19. #      剩下的就是人物攻击的动画,和正常的动画是一样设置
  20. #      如图中的攻击等待动画只是为了在播放攻击动画的同时消除人物本身(素材原因,人物攻击的时候离开了原位,如果是在原位置放魔法是用不上的)
  21. #    2.战斗图的设置
  22. #      战斗图其实只是一个透明的图片,它只是用来描述一个敌人或者角色的大小,并与相应的战斗动画编号相衔接。
  23. #      战斗图的文件名格式如下:
  24. #          名字★待机★防御★挨打★死亡动态★死亡静态★胜利动态★胜利静态.png
  25. #          (其中“名字”一项与动画无关)
  26. #          例如:
  27. #          紫烟★140★141★148★149★150★144★145.png
  28. #      对于敌人无胜利动画或者防御动画,请保持该位置为空,例如:
  29. #          蓝若冰★124★★126★127★★★.png
  30. #    综上,设置就这么完成了。
  31. #注意事项:
  32. #    1.由于系统中待机由动画实现,所以无法使用状态附带动画的功能。
  33. #
  34. #==============================================================================
  35. #// p.ori
  36. #==============================================================================
  37. # ■ Scene_Battle
  38. #==============================================================================
  39. class Scene_Battle
  40.   #--------------------------------------------------------------------------
  41.   # ● 定义实例变量
  42.   #--------------------------------------------------------------------------
  43.   attr_reader   :animation1_id                    # 行动方动画ID
  44.   alias battle_start_phase3 start_phase3
  45.   alias battle_start_phase4 update_phase4_step3
  46.   alias battle_start_phase5 start_phase5
  47.   def start_phase3
  48.     @spriteset.to_wait
  49.     battle_start_phase3
  50.   end
  51.   def update_phase4_step3
  52.     battle_start_phase4
  53.     update_phase4_step4#//齊時動畫修改
  54.   end
  55.   def update_phase4_step5
  56.     @help_window.visible = false
  57.     @status_window.refresh
  58.     @phase4_step = 6
  59.   end
  60.   def start_phase5
  61.     @spriteset.win
  62.     battle_start_phase5
  63.   end
  64. end
  65. #==============================================================================
  66. # ■ Spriteset_Battle
  67. #==============================================================================
  68. class Spriteset_Battle
  69.   def to_wait
  70.     @actor_sprites.each do |sprite|
  71.       sprite.to_wait if sprite.anim_mode == :guard
  72.     end
  73.   end
  74.   def win
  75.     @actor_sprites.each do |sprite| sprite.win end
  76.   end
  77. end
  78. #==============================================================================
  79. # ■ Sprite_Battler
  80. #==============================================================================
  81. class Sprite_Battler < RPG::Sprite
  82.   #--------------------------------------------------------------------------
  83.   # ● 初始化对像
  84.   #    添加跳跃记录
  85.   #--------------------------------------------------------------------------
  86.   def initialize(viewport, battler = nil)
  87.     super(viewport)
  88.     @battler = battler
  89.     @battler_visible = false
  90.     @flash_shake_switch = true
  91.     @state_sprite = RPG::Sprite.new(viewport)
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # ● x 值
  95.   #--------------------------------------------------------------------------
  96.   def x=(int)
  97.     super
  98.     @state_sprite.x = int
  99.   end
  100.   #--------------------------------------------------------------------------
  101.   # ● y 值
  102.   #--------------------------------------------------------------------------
  103.   def y=(int)
  104.     super
  105.     @state_sprite.y = int
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # ● z 值
  109.   #--------------------------------------------------------------------------
  110.   def z=(int)
  111.     super
  112.     @state_sprite.z = int
  113.   end
  114.   #--------------------------------------------------------------------------
  115.   # ● 刷新画面
  116.   #--------------------------------------------------------------------------
  117.   def update
  118.     super
  119.     # 战斗者为 nil 的情况下,清空
  120.     if self.clear? == true
  121.       return false
  122.     end
  123.     # 文件名和色相与当前情况有差异的情况下
  124.     if @battler.battler_name != @battler_name or
  125.        @battler.battler_hue != @battler_hue
  126.       self.set_battler_pic
  127.       if @battler.is_a?(Game_Enemy) and( @battler.dead? or @battler.hidden )
  128.         self.opacity = 0
  129.       end
  130.     end
  131.     # 动画 ID 与当前的情况有差异的情况下
  132.     if @battler.damage == nil and
  133.        @battler.state_animation_id != @state_animation_id
  134.       @state_animation_id = @battler.state_animation_id
  135.       #@state_sprite.loop_animation($data_animations[@state_animation_id])
  136.     end
  137.     @state_sprite.update
  138.     # 应该被显示的角色的情况下
  139.     if @battler.is_a?(Game_Actor) and @battler_visible
  140.       # 不是主状态的时候稍稍降低点透明度
  141.       if $game_temp.battle_main_phase
  142.         self.opacity += 3 if self.opacity < 255
  143.       else
  144.         self.opacity -= 3 if self.opacity > 207
  145.       end
  146.     end
  147.     # 防御
  148.     if @battler.guarding? and @anim_mode != :guard
  149.       to_guard
  150.     end
  151.     # 明灭
  152.     if @battler.blink
  153.       blink_on
  154.     else
  155.       blink_off
  156.     end
  157.     # 不可见的情况下
  158.     unless @battler_visible
  159.       # 出现
  160.       if not @battler.hidden and not @battler.dead? and
  161.          (@battler.damage == nil or @battler.damage_pop)
  162.         @battler_visible = true
  163.       end
  164.     end
  165.     # 可见的情况下
  166.     if @battler_visible
  167.       # 逃跑
  168.       if @battler.hidden
  169.         $game_system.se_play($data_system.escape_se)
  170.         escape
  171.         @battler_visible = false
  172.       end
  173.       # 白色闪烁
  174.       if @battler.white_flash
  175.         whiten
  176.         @battler.white_flash = false
  177.       end
  178.       # 动画
  179.       if @battler.animation_id != 0
  180.         display_anim
  181.       end
  182.       # 伤害
  183.       if @battler.damage_pop
  184.         damage(@battler.damage, @battler.critical)
  185.         @battler.damage = nil
  186.         @battler.critical = false
  187.         @battler.damage_pop = false
  188.       end
  189.       # korapusu
  190.       if @battler.damage == nil and @battler.dead?
  191.         collapse
  192.       end
  193.     end
  194.     # 设置活动块的坐标
  195.     self.set_position
  196.     if @flash_shake != 0 and @battler.damage != nil and BATTLER_JUMP
  197.       case @flash_shake
  198.       when 9..10
  199.         self.x = @battler.screen_x
  200.         self.y -=4
  201.         self.z = @battler.screen_z
  202.       when 6..8
  203.         self.x = @battler.screen_x
  204.         self.y -=2
  205.         self.z = @battler.screen_z
  206.       when 3..5
  207.         self.x = @battler.screen_x
  208.         self.y +=2
  209.         self.z = @battler.screen_z
  210.       when 2
  211.         self.x = @battler.screen_x
  212.         self.y += 4
  213.         self.z = @battler.screen_z
  214.       when 1
  215.         self.x = @battler.screen_x
  216.         self.y = @battler.screen_y
  217.         self.z = @battler.screen_z
  218.       end
  219.       @flash_shake -= 1
  220.     end
  221.   end
  222.   #--------------------------------------------------------------------------
  223.   # 清除
  224.   #--------------------------------------------------------------------------
  225.   def clear?
  226.     if @battler.nil?
  227.       self.bitmap = nil
  228.       loop_animation(nil)
  229.       return true
  230.     end
  231.     return false
  232.   end
  233.   #--------------------------------------------------------------------------
  234.   # 重置人物
  235.   #--------------------------------------------------------------------------
  236.   def set_battler_pic
  237.     # 获取、设置位图
  238.     @battler_name = @battler.battler_name
  239.     @battler_hue = @battler.battler_hue
  240.     self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
  241.     @width = bitmap.width
  242.     @height = bitmap.height
  243.     self.ox = @width / 2
  244.     self.oy = @height
  245.     # 如果是战斗不能或者是隐藏状态就把透明度设置成 0
  246.     if @battler.dead? or @battler.hidden
  247.       self.opacity = 0
  248.     end
  249.     #.......................................................................
  250.     if not @battler.hidden and not @battler.dead?
  251.       to_wait
  252.     end
  253.     #.......................................................................
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # 设置活动块的坐标
  257.   #--------------------------------------------------------------------------
  258.   def set_position
  259.     self.x = @battler.screen_x
  260.     self.y = @battler.screen_y
  261.     self.z = @battler.screen_z
  262.   end
  263.   #--------------------------------------------------------------------------
  264.   # 播放動畫
  265.   #--------------------------------------------------------------------------
  266.   def display_anim
  267.     if $scene.animation1_id == @battler.animation_id
  268.       to_attack
  269.     else
  270.       to_damage
  271.     end
  272.     @battler.animation_id = 0
  273.   end
  274.   #--------------------------------------------------------------------------
  275.   # 出現
  276.   #--------------------------------------------------------------------------
  277.   alias battle_appear appear
  278.   def appear
  279.     battle_appear
  280.     #......................................................................
  281.     #//轉為待機
  282.     to_wait
  283.     #......................................................................
  284.   end
  285.   #--------------------------------------------------------------------------
  286.   # 消失
  287.   #--------------------------------------------------------------------------
  288.   alias battle_collapse collapse
  289.   def collapse
  290.     if @battler.is_a?(Game_Enemy)
  291.       $game_system.se_play($data_system.enemy_collapse_se)
  292.  
  293.     else
  294.       $game_system.se_play($data_system.actor_collapse_se)
  295.     end
  296.     #......................................................................
  297.     if @anim_mode != :collapse
  298.       to_collapse
  299.       if @battler.is_a?(Game_Enemy)
  300.         battle_collapse
  301.       end
  302.     end
  303.     #......................................................................
  304.   end
  305.   #--------------------------------------------------------------------------
  306.   # 勝利
  307.   #--------------------------------------------------------------------------
  308.   def win
  309.     if not @battler.nil? and @battler.exist?
  310.       to_win
  311.     end
  312.   end
  313. end
  314. #// p.ex
  315. #==============================================================================
  316. # ■ Sprite_Battler < RPG::Sprite
  317. #------------------------------------------------------------------------------
  318. #  全動畫戰鬪 meet with 鏡頭移動
  319. #==============================================================================
  320. class Sprite_Battler < RPG::Sprite
  321.   attr_accessor :anim_mode
  322.   #//接入update
  323.   alias battle_update update
  324.   def update
  325.     update_battle_anim
  326.     battle_update
  327.   end
  328.   def effect?
  329.     @_whiten_duration > 0 or @_appear_duration > 0 or
  330.     @_escape_duration > 0 or @_collapse_duration > 0 or
  331.     @_damage_duration > 0 or @_animation_duration > 0 or
  332.     @effect_duration != nil
  333.   end
  334.   #//刷新動畫效果
  335.   def update_battle_anim
  336.     return if @effect_duration.nil?
  337.     if @effect_duration > 0
  338.       #//effecting
  339.       @effect_duration -= 1
  340.       if @anim_mode == 1 and @effect_duration == 1
  341.         to_wait if @battler.exist?
  342.       end
  343.     end
  344.     return if @effect_duration != 0
  345.     case @anim_mode
  346.     when 1
  347.       #//to wait
  348.     when 2
  349.       #//to wait
  350.       if @battler.exist?
  351.         to_wait
  352.         @stop_ = false
  353.       else
  354.         collapse
  355.         @stop_ = false
  356.         return
  357.       end
  358.     when :collapse
  359.       #//to dead
  360.       id = self.gain_anim(:dead)
  361.       loop_animation( $data_animations[id] )
  362.     when :win
  363.       #//to won
  364.       id = self.gain_anim(:won)
  365.       loop_animation( $data_animations[id] )
  366.     end
  367.     @effect_duration = nil
  368.   end
  369. #//受傷動畫
  370. #----------------------------------------------------------------------
  371.   def show_damage(hit)
  372.     return if @battler.guarding? or @_animation.nil?
  373.     if @battler_damage.is_a?(Numeric)
  374.       return if @battler_damage < 0
  375.     end
  376.     if @stop_ != true
  377.       if hit
  378.         id = self.gain_anim(:damage)
  379.       else
  380.         id = self.gain_anim(:damage)
  381.       end
  382.       @_loop_animation_index = 0
  383.       loop_animation( $data_animations[id] )
  384.       @damaging ||= @_animation.timings.size - 2
  385.       @damaging -= 1
  386.     end
  387.   end
  388.   def terminate_damage
  389.     if @damaging != nil and @_loop_animation_index == 0
  390.       if @damaging <= 0
  391.         id = self.gain_anim(:wait)
  392.         loop_animation( $data_animations[id] )
  393.         @stop_ = true
  394.         @damaging = nil
  395.       end
  396.     end
  397.   end
  398. #----------------------------------------------------------------------
  399.   def setup_loop_anim(sym)
  400.     id = self.gain_anim(sym)
  401.     loop_animation( $data_animations[id] )
  402.     @anim_mode = sym
  403.   end
  404.   #//轉為待機
  405.   def to_wait
  406.     setup_loop_anim(:wait)
  407.     return true
  408.   end
  409.   #//轉為防御
  410.   def to_guard
  411.     setup_loop_anim(:guard)
  412.     return true
  413.   end
  414. #----------------------------------------------------------------------
  415.   #//轉為攻擊
  416.   def to_attack
  417.     id = self.gain_anim(8)
  418.     loop_animation( $data_animations[id])
  419.     @effect_duration = @_loop_animation.frame_max*2
  420.     @anim_mode = 1
  421.     return true
  422.   end
  423. #----------------------------------------------------------------------
  424.   #//轉為挨打
  425.   def to_damage
  426.     id = self.gain_anim(8)
  427.     @anim_mode = 2
  428.     animation( $data_animations[id], @battler.animation_hit,
  429.                @battler.damage, @battler.critical)
  430.     @effect_duration = @_animation.frame_max*2
  431.     return true
  432.   end
  433. #----------------------------------------------------------------------
  434.   #//轉為死亡
  435.   def to_collapse
  436.     @_loop_animation_index = 0
  437.     setup_loop_anim(:collapse)
  438.     @effect_duration = @_loop_animation.frame_max*2
  439.     return true
  440.   end
  441.   #//轉為勝利
  442.   def to_win
  443.     @_loop_animation_index = 1
  444.     setup_loop_anim(:win)
  445.     #//勝利畫面的播放次數
  446.     t = 1
  447.     @effect_duration = @_loop_animation.frame_max*t*2
  448.     return true
  449.   end
  450. #----------------------------------------------------------------------
  451.   #//讀取動畫
  452.   def gain_anim(int)
  453.     ary = @battler.battler_name.split(/★/)
  454.     case int
  455.     when :wait;
  456.       return ary[1].to_i
  457.     when :guard;
  458.       return ary[2].to_i
  459.     when :damage;
  460.       return ary[3].to_i
  461.     when :collapse;
  462.       return ary[4].to_i
  463.     when :dead;
  464.       return ary[5].to_i
  465.     when :win;
  466.       return ary[6].to_i
  467.     when :won;
  468.       return ary[7].to_i
  469.     when (8);
  470.       return @battler.animation_id
  471.     end
  472.   end
  473. #----------------------------------------------------------------------
  474. end
  475. =begin
  476. ==============================================================================
  477. 彩虹神剑(伤害分段显示)显示总伤害版 v1.0f
  478. ==============================================================================
  479. 彩虹神剑 -柳柳
  480. 6-20-2006 v1.0 -叶子
  481. 在彩虹神剑的基础上增加了显示总伤害的功能,而且总伤害的数字是弹出伤害时逐渐增加的
  482. v1.0a -叶子
  483. 修正了显示伤害和实际伤害有差别的问题
  484. 修正了miss的情况下显示miss混乱的问题
  485. 修正了对己方技能重复显示伤害的问题
  486. 未修正播放目标动画第一帧时目标有时无端跳动的BUG
  487. v1.0b -叶子
  488. 修改了总伤害数字的位置和z坐标
  489. 未修正播放目标动画第一帧时目标有时无端跳动的BUG
  490. v1.0c -柳柳
  491. ? ? ?
  492. v1.0d -柳柳
  493. 1.0d最终解决了那个闪光问题,还有最末帧伤害多次的算法
  494. 7-24-2006 v1.0e -叶子
  495. 修正全屏幕闪烁弹出伤害错误的问题
  496. 修正连续伤害不会弹出伤害的问题
  497. 仍然未修正播放目标动画第一帧时目标有时无端跳动的BUG
  498. 2-20-2009 v1.0f -禾西
  499. 修正一次画面闪烁出现天文数字伤害的错误
  500. ==============================================================================
  501. =end
  502. # 核心的说明:
  503. # damage_pop 不再附带damage()的功能,这个放到animation里面去了
  504. module RPG
  505.  
  506.   class Sprite < ::Sprite
  507.     #--------------------------------------------------------------------------
  508.     # ● 常量设定
  509.     #--------------------------------------------------------------------------
  510.     # 是否显示总伤害
  511.     SHOW_TOTAL_DAMAGE = true
  512.     # 角色受攻击时是否跳一下
  513.     BATTLER_JUMP = true
  514.     #==========================================
  515.     # 修改说明:
  516.     # @flash_shake用来制作挨打时候跳跃
  517.     # @_damage    用来记录每次打击之后弹出数字
  518.     # @_total_damage 记录总伤害
  519.     # @_total_damage_duration 总伤害持续帧
  520.     #==========================================
  521. #--------------------------------------------------------------------------
  522. #initialize
  523. #==========================================================================
  524.     alias rainbow_initialize  initialize
  525.     def initialize(viewport = nil)
  526.       rainbow_initialize(viewport)
  527.  
  528.       @flash_shake = 0
  529.       @_damages = []
  530.       @_total_damage = 0
  531.       @_total_damage_duration = 0
  532.       #.........................................................................
  533.       @hits = 0
  534.       #.........................................................................
  535.     end
  536. #--------------------------------------------------------------------------
  537.     def update
  538.       super
  539.       if @_whiten_duration > 0
  540.         @_whiten_duration -= 1
  541.         self.color.alpha = 128 - (16 - @_whiten_duration) * 10
  542.       end
  543.       if @_appear_duration > 0
  544.         @_appear_duration -= 1
  545.         self.opacity = (16 - @_appear_duration) * 16
  546.       end
  547.       if @_escape_duration > 0
  548.         @_escape_duration -= 1
  549.         self.opacity = 256 - (32 - @_escape_duration) * 10
  550.       end
  551.       if @_collapse_duration > 0
  552.         @_collapse_duration -= 1
  553.         self.opacity = 256 - (48 - @_collapse_duration) * 6
  554.       end
  555. #--------------------------------------------------------------------------
  556. #//
  557.       #//修改:更新算法,更新弹出
  558.       if @_damage_duration > 0
  559.         @_damage_duration -= 1
  560.         for damage in @_damages
  561.           damage[0].x = self.x + self.viewport.rect.x -
  562.                         self.ox + self.src_rect.width / 2 +
  563.                         (40 - damage[1]) * damage[3] / 10
  564.           damage[0].y -= damage[4]+damage[1]/10
  565.           damage[0].opacity = damage[1]*20
  566.           damage[1] -= 1
  567.           if damage[1]==0
  568.             damage[0].bitmap.dispose
  569.             damage[0].dispose
  570.             @_damages.delete(damage)
  571.             next
  572.           end
  573.         end
  574.       end
  575.  
  576.       #//修改:弹出总伤害
  577.       if @_total_damage_duration > 0
  578.         @_total_damage_duration -= 1
  579.         @_total_damage_sprite.y -= 1 if @_total_damage_duration % 2 == 0
  580.         if @_total_damage_sprite.zoom_x > 1.0
  581.           @_total_damage_sprite.zoom_x -= 0.05
  582.         end
  583.         if @_total_damage_sprite.zoom_y > 1.0
  584.           @_total_damage_sprite.zoom_y -= 0.05
  585.         end
  586.         @_total_damage_sprite.opacity = @_total_damage_duration * 16 - 128
  587.         if @_total_damage_duration <= 0
  588.           dispose_hit
  589.           @_total_damage = 0
  590.           @_total_damage_duration = 0
  591.           @_total_damage_sprite.bitmap.dispose
  592.           @_total_damage_sprite.dispose
  593.           @_total_damage_sprite = nil
  594.         elsif @_total_damage_duration <= 7
  595.           @_hits_sprite.opacity -= 32
  596.           @_hits_sprite.x += 1
  597.         end
  598.       end
  599. #//
  600. #==========================================================================
  601.       if @_animation != nil and (Graphics.frame_count % 2 == 0)
  602.         @_animation_duration -= 1
  603.         update_animation
  604.       end
  605.       if @_loop_animation != nil and (Graphics.frame_count % 2 == 0)
  606.  
  607.         update_loop_animation
  608.         @_loop_animation_index += 1
  609.         @_loop_animation_index %= @_loop_animation.frame_max
  610.         terminate_damage
  611.       end
  612.       if @_blink
  613.         @_blink_count = (@_blink_count + 1) % 32
  614.         if @_blink_count < 16
  615.           alpha = (16 - @_blink_count) * 6
  616.         else
  617.           alpha = (@_blink_count - 16) * 6
  618.         end
  619.         self.color.set(255, 255, 255, alpha)
  620.       end
  621.       @@_animations.clear
  622.     end
  623. #p/2 dispose
  624. #--------------------------------------------------------------------------
  625.     #=======================================
  626.     # 修改:更换清除伤害的算法,以防万一
  627.     #       本内容在脚本中没有使用过
  628.     #=======================================
  629.     def dispose_damage
  630.       for damage in @_damages.reverse
  631.         damage[0].bitmap.dispose
  632.         damage[0].dispose
  633.         @_damages.delete(damage)
  634.       end
  635.       @_total_damage = 0
  636.       @_last_frame = -1
  637.       if @_total_damage_sprite != nil
  638.         @_total_damage_duration = 0
  639.         @_total_damage_sprite.bitmap.dispose
  640.         @_total_damage_sprite.dispose
  641.         @_total_damage_sprite = nil
  642.       end
  643.     end
  644.     #...........................................................................
  645.     def dispose_animation
  646.       #=======================================
  647.       # 修改:清除记录的伤害,清除权重记录
  648.       #=======================================
  649.       @battler_damage = nil
  650.       @battler_critical = nil
  651.       @all_weight = 1
  652.       @_total_damage = 0
  653.       @_last_frame = -1
  654.       #.........................................................................
  655.       @hits = 0
  656.       #.........................................................................
  657.       if @_animation_sprites != nil
  658.         sprite = @_animation_sprites[0]
  659.         if sprite != nil
  660.           key = @_animation.animation_name + @_animation.animation_hue.to_s
  661.           @@_reference_count[key] -= 1
  662.           if @@_reference_count[key] == 0
  663.             sprite.bitmap.dispose
  664.           end
  665.         end
  666.         for sprite in @_animation_sprites
  667.           sprite.dispose
  668.         end
  669.         @_animation_sprites = nil
  670.         @_animation = nil
  671.       end
  672.     end
  673. #--------------------------------------------------------------------------
  674. #--------------------------------------------------------------------------
  675. #.damage(str/int, bool)
  676.     def damage(value, critical)
  677.       #.........................................................................
  678.       #//dispose_damage #//清空 => p/2 dispose
  679.       #清除hit数
  680.       dispose_hit
  681.       #.........................................................................
  682.       if value.is_a?(Numeric)
  683.         damage_string = value.abs.to_s
  684.       else
  685.         damage_string = value.to_s
  686.       end
  687.       #// 生成底圖
  688.       bitmap = Bitmap.new(160, 48)
  689.       #// 字體
  690.       bitmap.font.name = "Comic Sans MS","Arial Black"
  691.       #// layer 1
  692.       bitmap.font.size = 32
  693.       bitmap.font.color.set(0, 0, 0)
  694.       bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
  695.       bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
  696.       bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
  697.       bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
  698.       #// layer 2
  699.       #=======================================
  700.       # 修改:颜色
  701.       #=======================================
  702.       if value.is_a?(Numeric) and value < 0
  703.         bitmap.font.color.set(176, 255, 144)
  704.       else
  705.         bitmap.font.color.set(255, 55, 55)
  706.       end
  707.       bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
  708.       #// layer 3
  709.       if critical
  710.         bitmap.font.size = 20
  711.         bitmap.font.color.set(0, 0, 0)
  712.         bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
  713.         bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
  714.         bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
  715.         bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
  716.         bitmap.font.color.set(255, 255, 255)
  717.         bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
  718.       end
  719.       @_damage_sprite = ::Sprite.new#(self.viewport)
  720.       @_damage_sprite.bitmap = bitmap
  721.       @_damage_sprite.ox = 80
  722.       @_damage_sprite.oy = 20
  723.       @_damage_sprite.x = self.x
  724.       @_damage_sprite.y = self.y - self.oy / 2
  725.       @_damage_sprite.z = 3000
  726.       @_damage_duration = 40
  727.       #=======================================
  728.       # 修改:推入新的伤害
  729.       #=======================================
  730.       @_damages.push([@_damage_sprite,@_damage_duration-10,0, rand(30) - 15, rand(3)])
  731.       # 总伤害处理
  732.       make_total_damage(value)
  733.    end
  734.    #..........................................................................
  735.    #--------------------------------------------------------------------------
  736.    # ● 总伤害处理
  737.    #--------------------------------------------------------------------------
  738.    def make_total_damage(value)
  739.       return unless (value.is_a?(Numeric) and SHOW_TOTAL_DAMAGE)
  740.       @_total_damage += value
  741.       #// 生成底圖
  742.       bitmap = Bitmap.new(300, 150)
  743.       #// 字體
  744.       bitmap.font.name = "Comic Sans MS","Arial Black"
  745.       #// layer 4
  746.       bitmap.font.size = 48
  747.       bitmap.font.color.set(0, 0, 0)
  748.       bitmap.draw_text(+2, 12+2, 160, 36, @_total_damage.abs.to_s, 1)
  749.       #// layer 5
  750.       if @_total_damage < 0
  751.         bitmap.font.color.set(80, 255, 00)
  752.       else
  753.         bitmap.font.color.set(255, 140, 0)
  754.       end
  755.       bitmap.draw_text(0, 12, 160, 36, @_total_damage.abs.to_s, 1)
  756.       if @_total_damage_sprite.nil?
  757.         @_total_damage_sprite = ::Sprite.new#(self.viewport)
  758.         @_total_damage_sprite.ox = 80
  759.         @_total_damage_sprite.oy = 20
  760.         @_total_damage_sprite.z = 3000
  761.       end
  762.       @_total_damage_sprite.bitmap = bitmap
  763.       @_total_damage_sprite.zoom_x = 1.5
  764.       @_total_damage_sprite.zoom_y = 1.5
  765.       @_total_damage_sprite.x = self.x
  766.       @_total_damage_sprite.y = self.y  - self.oy / 2 - 64
  767.       @_total_damage_sprite.z = 3001
  768.       @_total_damage_duration = 40
  769.       @hits += 1
  770.       hit
  771.       #.........................................................................
  772.     end
  773.     #--------------------------------------------------------------------------
  774.     # ● hit数的美化描绘
  775.     #--------------------------------------------------------------------------
  776.     #..........................................................................
  777.     def hit
  778.       # 如果伤害值是数值
  779.       # 转为字符串
  780.       value=@hits
  781.       hits_string = value.to_s
  782.       # 初始化位图
  783.       bitmap = Bitmap.new(320, 64)
  784.       bitmap.font.name = "Comic Sans MS","Arial Black"
  785.       bitmap.font.size = 32
  786.       # 分割伤害值字符串
  787.       hits_array = hits_string.scan(/./)
  788.       hits_x = - 36.2
  789.       rect_y = 0
  790.       # 循环伤害值字符串
  791.       for char in hits_array
  792.         # 后移一位
  793.         hits_x += 36.2
  794.         number = char.to_i
  795.         # 显示伤害数字
  796.         bitmap.blt(hits_x, 0, RPG::Cache.picture("Number"),
  797.         Rect.new(number * 36.2, rect_y, 36.2, 50))
  798.       end
  799.       hits_x += 18.1
  800.       bitmap.blt(hits_x, 0, RPG::Cache.picture("HITS"),
  801.                  Rect.new(0, -21, 90, 50))
  802.       # 伤害值定位
  803.       @_hits_sprite = ::Sprite.new#(self.viewport)
  804.       @_hits_sprite.bitmap = bitmap
  805.       @_hits_sprite.x = 560 - hits_string.size * 36.2
  806.       @_hits_sprite.y = 70
  807.       @_hits_sprite.z = 3000
  808.       @_hits_duration = 40
  809.     end
  810.     #=======================================
  811.     # 清除hit数
  812.     #=======================================
  813.     #...........................................................................
  814.     def dispose_hit
  815.       if @_hits_sprite != nil
  816.         @_hits_sprite.bitmap.dispose
  817.         @_hits_sprite.dispose
  818.         @_hits_sprite = nil
  819.       end
  820.     end
  821.     #--------------------------------------------------------------------------
  822.     # ● 返回 @hits
  823.     #--------------------------------------------------------------------------
  824.     def get_hit
  825.       return @hits
  826.     end
  827. #--------------------------------------------------------------------------
  828.  
  829.  
  830.  
  831.     def animation(animation, hit, battler_damage="", battler_critical=false)
  832.        dispose_animation      
  833.        #=======================================
  834.        # 修改:记录伤害和critical
  835.        #=======================================
  836.        @battler_damage = battler_damage
  837.        @battler_critical = battler_critical
  838.        @_animation = animation
  839.        return if @_animation == nil
  840.        @_animation_hit = hit
  841.        @_animation_duration = @_animation.frame_max
  842.  
  843.        name = @_animation.animation_name
  844.        hue = @_animation.animation_hue
  845.        bitmap = RPG::Cache.animation(name, hue)
  846.  
  847.        #=======================================
  848.        # 修改:计算总闪光权限值
  849.        #=======================================
  850.        for timing in @_animation.timings
  851.          weight = animation_process_timing(timing, hit, true)
  852.          @all_weight += weight
  853.  
  854.          #//记录最后一次闪光
  855.          @_last_frame = timing.frame if weight != 0
  856.        end
  857.        key = name + hue.to_s
  858.        if @@_reference_count.include?(key)
  859.          @@_reference_count[key] += 1
  860.        else
  861.          @@_reference_count[key] = 1
  862.        end
  863.        #=======================================
  864.        # 修改:行动方动画不显示伤害
  865.        #=======================================
  866.        if $scene.is_a?(Scene_Battle)
  867.          if $scene.animation1_id == @battler.animation_id
  868.            @battler_damage = ""
  869.          end
  870.        end
  871.        @_animation_sprites = []
  872.        if @_animation.position != 3 or not @@_animations.include?(animation)
  873.          for i in 0..15
  874.            sprite = ::Sprite.new(self.viewport)
  875.            sprite.bitmap = bitmap
  876.            sprite.visible = false
  877.            @_animation_sprites.push(sprite)
  878.          end
  879.          unless @@_animations.include?(animation)
  880.            @@_animations.push(animation)
  881.          end
  882.        end
  883.        update_animation
  884.      end
  885.      #..........................................................................
  886.      def update_animation
  887.        if @_animation_duration > 0
  888.          frame_index = @_animation.frame_max - @_animation_duration
  889.          @frame_index = frame_index
  890.          cell_data = @_animation.frames[frame_index].cell_data
  891.          position = @_animation.position
  892.          animation_set_sprites(@_animation_sprites, cell_data, position)
  893.          #=======================================
  894.          # 修改:弹出伤害,权重计算
  895.          #=======================================
  896.          for timing in @_animation.timings
  897.             next unless timing.frame == frame_index
  898.             t = 1.0 * animation_process_timing(timing, @_animation_hit)
  899.             #p t,"当前权重", @all_weight,"总权重"
  900.             if @battler_damage.is_a?(Numeric) and t != 0
  901.               t *= @battler_damage
  902.               t /= @all_weight
  903.               t = t.to_i
  904.               # 最后一次闪光的话,伤害修正
  905.               if frame_index == @_last_frame
  906.                 @_total_damage = @battler_damage - t
  907.               end
  908.               damage(t, @battler_critical)
  909.             # 防止重复播放miss
  910.             elsif !@battler_damage.is_a?(Numeric) and timing.flash_scope != 0
  911.               damage(@battler_damage, @battler_critical)
  912.             end
  913.          end
  914.        else
  915.          dispose_animation
  916.        end
  917.      end
  918.  
  919.  
  920.      #=======================================
  921.      # 修改:敌人跳跃的功能 + 添加返回数值
  922.      #=======================================
  923.      def update_loop_animation
  924.        frame_index = @_loop_animation_index
  925.        cell_data = @_loop_animation.frames[frame_index].cell_data
  926.        position = @_loop_animation.position
  927.        #·改·
  928.        if @wait_count.to_i <= 0
  929.          @wait_count = 0
  930.          animation_set_sprites_loop(@_loop_animation_sprites, cell_data, position)
  931.        else
  932.          @wait_count -= 1
  933.        end
  934.        if @wait_flash.to_i <= 0
  935.          @wait_flash = 0
  936.        else
  937.          @wait_flash -= 1
  938.          for sprite in @_loop_animation_sprites
  939.            sprite.blend_type = 1
  940.          end
  941.        end
  942.        #·改·
  943.        for timing in @_loop_animation.timings
  944.          if timing.frame == frame_index
  945.            animation_process_timing(timing, true)
  946.          end
  947.        end
  948.      end
  949.     def dispose_loop_animation
  950.       if @_loop_animation_sprites != nil
  951.         sprite = @_loop_animation_sprites[0]
  952.         if sprite != nil
  953.           name = @_loop_animation.animation_name
  954.           key = name + @_loop_animation.animation_hue.to_s
  955.           @@_reference_count[key] -= 1
  956.           if @@_reference_count[key] == 0
  957.             sprite.bitmap.dispose
  958.           end
  959.         end
  960.         for sprite in @_loop_animation_sprites
  961.           sprite.dispose
  962.         end
  963.         @_loop_animation_sprites = nil
  964.         @_loop_animation = nil
  965.       end
  966.     end
  967.      #=======================================
  968.      # 修改:敌人跳跃的功能 + 添加返回数值
  969.      #=======================================
  970.      def loop_animation(animation)
  971.        return if animation == @_loop_animation
  972.        dispose_loop_animation
  973.        @_loop_animation = animation
  974.        return if @_loop_animation == nil
  975.        @_loop_animation_index = 0
  976.        name = @_loop_animation.animation_name
  977.        hue = @_loop_animation.animation_hue
  978.        bitmap = RPG::Cache.animation(name, hue)
  979.        key = name + hue.to_s
  980.        if @@_reference_count.include?(key)
  981.          @@_reference_count[key] += 1
  982.        else
  983.          @@_reference_count[key] = 1
  984.        end
  985.        @_loop_animation_sprites = []
  986.        for i in 0..16
  987.          sprite = ::Sprite.new(self.viewport)
  988.          sprite.bitmap = bitmap
  989.          sprite.visible = false
  990.          @_loop_animation_sprites.push(sprite)
  991.        end
  992.        update_loop_animation
  993.      end
  994.  
  995.  
  996.  
  997.  
  998.      def animation_set_sprites(sprites, cell_data, position)
  999.         for i in 0..15
  1000.           sprite = sprites[i]
  1001.           pattern = cell_data[i, 0]
  1002.           if sprite == nil or pattern == nil or pattern == -1
  1003.             sprite.visible = false if sprite != nil
  1004.             next
  1005.           end
  1006.           sprite.visible = true
  1007.           sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
  1008.           if position == 3
  1009.             if self.viewport != nil
  1010.               sprite.x = self.viewport.rect.width / 2
  1011.               sprite.y = self.viewport.rect.height - 160
  1012.             else
  1013.               sprite.x = 320
  1014.               sprite.y = 240
  1015.             end
  1016.           else
  1017.             sprite.x = self.x - self.ox + self.src_rect.width / 2
  1018.             sprite.y = self.y - self.oy + self.src_rect.height / 2
  1019.             sprite.y -= self.src_rect.height / 4 if position == 0
  1020.             sprite.y += self.src_rect.height / 4 if position == 2
  1021.           end
  1022.           sprite.x += cell_data[i, 1]
  1023.           sprite.y += cell_data[i, 2]
  1024.           sprite.z = self.z + 1
  1025.           sprite.ox = 96
  1026.           sprite.oy = 96
  1027.           sprite.zoom_x = cell_data[i, 3] / 100.0
  1028.           sprite.zoom_y = cell_data[i, 3] / 100.0
  1029.           sprite.angle = cell_data[i, 4]
  1030.           sprite.mirror = (cell_data[i, 5] == 1)
  1031.           sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
  1032.           sprite.blend_type = cell_data[i, 7]
  1033.         end
  1034.       end
  1035.  
  1036.  
  1037.  
  1038.  
  1039.        def animation_set_sprites_loop(sprites, cell_data, position)
  1040.         for i in 0..15
  1041.           sprite = sprites[i]
  1042.           pattern = cell_data[i, 0]
  1043.           if sprite == nil or pattern == nil or pattern == -1
  1044.             sprite.visible = false if sprite != nil
  1045.             next
  1046.           end
  1047.           sprite.visible = true
  1048.           sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
  1049.           if position == 3
  1050.             if self.viewport != nil
  1051.               sprite.x = self.viewport.rect.width / 2
  1052.               sprite.y = self.viewport.rect.height - 160
  1053.             else
  1054.               sprite.x = 320
  1055.               sprite.y = 240
  1056.             end
  1057.           else
  1058.             sprite.x = self.x - self.ox + self.src_rect.width / 2
  1059.             sprite.y = self.y - self.oy + self.src_rect.height / 2
  1060.             sprite.y -= self.src_rect.height / 4 if position == 0
  1061.             sprite.y += self.src_rect.height / 4 if position == 2
  1062.           end
  1063.           sprite.x += cell_data[i, 1]
  1064.           sprite.y += cell_data[i, 2]
  1065.           sprite.z = self.z
  1066.           sprite.ox = 96
  1067.           sprite.oy = 96
  1068.           sprite.zoom_x = cell_data[i, 3] / 100.0
  1069.           sprite.zoom_y = cell_data[i, 3] / 100.0
  1070.           sprite.angle = cell_data[i, 4]
  1071.           sprite.mirror = (cell_data[i, 5] == 1)
  1072.           sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
  1073.           sprite.blend_type = cell_data[i, 7]
  1074.         end
  1075.      end
  1076.      #=======================================
  1077.      # 修改:敌人跳跃的功能 + 添加返回数值
  1078.      #=======================================
  1079.      def animation_process_timing(timing, hit,dontflash=false)
  1080.        if (timing.condition == 0) or
  1081.           (timing.condition == 1 and hit == true) or
  1082.           (timing.condition == 2 and hit == false)
  1083.         unless dontflash
  1084.           if timing.se.name != ""
  1085.             se = timing.se
  1086.             Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
  1087.           end
  1088.         end
  1089.         case timing.flash_scope
  1090.         when 1
  1091.           unless dontflash
  1092.             unless $scene.animation1_id == @battler.animation_id
  1093.               show_damage(hit)
  1094.             end
  1095.             self.flash(timing.flash_color, timing.flash_duration * 2)
  1096.             #....................................................................
  1097.             @wait_flash = timing.flash_duration
  1098.             #....................................................................
  1099.             if @_total_damage >0
  1100.               @flash_shake_switch = true
  1101.               @flash_shake = 10
  1102.             end
  1103.           end
  1104.           return timing.flash_color.alpha * timing.flash_duration
  1105.         when 2
  1106.           unless dontflash and self.viewport != nil
  1107.             unless $scene.animation1_id == @battler.animation_id
  1108.               show_damage(hit)
  1109.             end
  1110.             self.viewport.flash(timing.flash_color, timing.flash_duration * 2)
  1111.           end
  1112.           return timing.flash_color.alpha * timing.flash_duration
  1113.         when 3
  1114.           unless dontflash
  1115.             unless $scene.animation1_id == @battler.animation_id
  1116.               show_damage(hit)
  1117.             end
  1118.             self.flash(nil, timing.flash_duration * 2)
  1119.           end
  1120.           return timing.flash_color.alpha * timing.flash_duration
  1121.         end
  1122.       end
  1123.       return 0
  1124.     end
  1125.     #//虛函數
  1126.     def show_damage(hit)
  1127.     end
  1128.     def terminate_damage
  1129.     end
  1130.   end
  1131. end


  • 更新完成啦

梦石
0
星屑
759
在线时间
6267 小时
注册时间
2006-6-7
帖子
8462
2
发表于 2012-7-31 17:51:48 | 只看该作者
=V=||话说这个脚本我就只能改改显示伤害权重这里了,
total_damage_duration 一改就出错,
回复 支持 反对

使用道具 举报

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-26 06:45

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表