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

Project1

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

[已经过期] 彩虹神剑

 关闭 [复制链接]

Lv3.寻梦者

梦石
0
星屑
3526
在线时间
1887 小时
注册时间
2010-6-19
帖子
1210
跳转到指定楼层
1
发表于 2011-5-7 18:21:54 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
如何让彩虹神剑支持 战斗图为 self.bitmap.width/4


像这样的战斗图...


脚本:
  1. =begin
  2. ==============================================================================

  3. 彩虹神剑(伤害分段显示)显示总伤害版 v1.0b

  4. ==============================================================================

  5. 彩虹神剑 by 柳柳
  6. 显示总伤害修改 by 叶子

  7. ==============================================================================

  8. 6-20-2006 v1.0
  9. 在彩虹神剑的基础上增加了显示总伤害的功能,而且总伤害的数字是弹出伤害时逐渐增加的

  10. v1.0a
  11. 修正了显示伤害和实际伤害有差别的问题
  12. 修正了miss的情况下显示miss混乱的问题
  13. 修正了对己方技能重复显示伤害的问题
  14. 未修正播放目标动画第一帧时目标有时无端跳动的BUG

  15. v1.0b
  16. 修改了总伤害数字的位置和z坐标
  17. 未修正播放目标动画第一帧时目标有时无端跳动的BUG

  18. ==============================================================================
  19. =end
  20. # 核心的说明:
  21. # damage_pop 不再附带damage()的功能,这个放到animation里面去了

  22. module RPG
  23. #--------------------------------------------------------------------------
  24. # ● 常量设定
  25. #--------------------------------------------------------------------------
  26. # 是否显示总伤害
  27. SHOW_TOTAL_DAMAGE = true
  28. # 角色受攻击时是否跳一下
  29. BATTLER_JUMP = false

  30. class Sprite < ::Sprite
  31.    #==========================================
  32.    # 修改说明:
  33.    # @flash_shake用来制作挨打时候跳跃
  34.    # @_damage    用来记录每次打击之后弹出数字
  35.    # @_total_damage 记录总伤害
  36.    # @_total_damage_duration 总伤害持续帧
  37.    #==========================================
  38.    #alias 66RPG_rainbow_initialize : initialize
  39.    def initialize(viewport = nil)
  40.      #66RPG_rainbow_initialize(viewport)
  41.      super(viewport)
  42.      @_whiten_duration = 0
  43.      @_appear_duration = 0
  44.      @_escape_duration = 0
  45.      @_collapse_duration = 0
  46.      @_damage_duration = 0
  47.      @_animation_duration = 0
  48.      @_blink = false
  49.      # 挨打时候跳跃
  50.      @flash_shake = 0
  51.      # 伤害记录数组
  52.      @_damage = []
  53.      # 总伤害数字
  54.      @_total_damage = 0
  55.      # 总伤害持续帧
  56.      @_total_damage_duration = 0
  57.    end
  58.    def damage(value, critical, sp_damage = false)
  59.      if value.is_a?(Numeric)
  60.        damage_string = value.abs.to_s
  61.      else
  62.        damage_string = value.to_s
  63.      end
  64.      bitmap = Bitmap.new(200, 80)
  65.      bitmap.font.name = "Arial Black"
  66.      bitmap.font.size = 32
  67.       # 伤害值是数值的情况下
  68.       if value.is_a?(Numeric)
  69.         # 分割伤害值字符串
  70.         damage_array = damage_string.scan(/./)
  71.         damage_x = 81 - damage_string.size * 9
  72.         # 伤害值为负的情况下
  73.         if value < 0
  74.           # 调用回复数字表
  75.           rect_y = 32
  76.         else
  77.           # 调用伤害数字表
  78.           rect_y = 0
  79.         end
  80.         # 循环伤害值字符串

  81.        for char in damage_array
  82.          number = char.to_i
  83.           # 显示伤害数字
  84.          if sp_damage
  85.            bitmap.blt(damage_x, 32, RPG::Cache.picture("Damagesp"),
  86.            Rect.new(number * 18, rect_y, 18, 32))
  87.            damage_x += 18
  88.          else
  89.            bitmap.blt(damage_x, 32, RPG::Cache.picture("Damage"),
  90.            Rect.new(number * 18, rect_y, 18, 32))
  91.            damage_x += 18
  92.          end# 伤害值不是数值的情况
  93.         end
  94.       else
  95.         # 如果伤害值不是 Miss
  96.         unless value == "Miss"
  97.           # 系统默认描画字符串
  98.           bitmap.font.color.set(0, 0, 0)
  99.           bitmap.draw_text(-1, 27, 162, 36, damage_string, 1)
  100.           bitmap.draw_text(+1, 27, 162, 36, damage_string, 1)
  101.           bitmap.draw_text(-1, 29, 162, 36, damage_string, 1)
  102.           bitmap.draw_text(+1, 29, 162, 36, damage_string, 1)
  103.           bitmap.font.color.set(255, 255, 255)
  104.           bitmap.draw_text(0, 28, 162, 36, damage_string, 1)
  105.         # Miss 的情况下
  106.         else
  107.           # 显示未击中图画
  108.           bitmap.blt(36, 28, RPG::Cache.picture("Damage"), Rect.new(90, 64, 90, 32))
  109.         end
  110.       end
  111.       # 会心一击标志打开的情况
  112.       if critical
  113.         # 显示会心一击图画
  114.         bitmap.blt(36, 0, RPG::Cache.picture("Damage"), Rect.new(0, 64, 90, 32))
  115.       end
  116.      @_damage_sprite = ::Sprite.new(self.viewport)
  117.      @_damage_sprite.bitmap = bitmap
  118.      @_damage_sprite.ox = 80
  119.      @_damage_sprite.oy = 20
  120.      @_damage_sprite.x = self.x
  121.      @_damage_sprite.y = self.y - self.oy / 2
  122.      @_damage_sprite.z = 3000
  123.      @_damage_duration = 40
  124.      #=======================================
  125.      # 修改:推入新的伤害
  126.      #=======================================
  127.      @_damage.push([@_damage_sprite,@_damage_duration-10,0, rand(30) - 15, rand(3)])
  128.      # 总伤害处理
  129.      make_total_damage(value)
  130.    end
  131.    #--------------------------------------------------------------------------
  132.    # ● 总伤害处理
  133.    #--------------------------------------------------------------------------
  134.    def make_total_damage(value)
  135.      if value.is_a?(Numeric) and SHOW_TOTAL_DAMAGE and (@_animation.flame == 1)
  136.        @_total_damage += value
  137.      else
  138.        return
  139.      end
  140.      bitmap = Bitmap.new(300, 150)
  141.      bitmap.font.name = "Arial Black"
  142.      bitmap.font.size = 48
  143.      bitmap.font.color.set(0, 0, 0)
  144.      bitmap.draw_text(+2, 12+2, 160, 36, @_total_damage.abs.to_s, 1)
  145.      if @_total_damage < 0
  146.        bitmap.font.color.set(80, 255, 00)
  147.      else
  148.        bitmap.font.color.set(255, 140, 0)
  149.      end
  150.      bitmap.draw_text(0, 12, 160, 36, @_total_damage.abs.to_s, 1)
  151.      if @_total_damage_sprite.nil?
  152.        @_total_damage_sprite = ::Sprite.new(self.viewport)
  153.        @_total_damage_sprite.ox = 80
  154.        @_total_damage_sprite.oy = 20
  155.        @_total_damage_sprite.z = 3000
  156.      end
  157.      @_total_damage_sprite.bitmap = bitmap
  158.      @_total_damage_sprite.zoom_x = 1.5
  159.      @_total_damage_sprite.zoom_y = 1.5
  160.      @_total_damage_sprite.x = self.x
  161.      @_total_damage_sprite.y = self.y  - self.oy / 2 - 64
  162.      @_total_damage_sprite.z = 3001
  163.      @_total_damage_duration = 80
  164.    end
  165.    def animation(animation, hit, battler_damage="", battler_critical=false)
  166.      dispose_animation      
  167.      #=======================================
  168.      # 修改:记录伤害和critical
  169.      #=======================================
  170.      @battler_damage = battler_damage
  171.      @battler_critical = battler_critical
  172.      @_animation = animation
  173.      return if @_animation == nil
  174.      @_animation_hit = hit
  175.      @_animation_duration = @_animation.frame_max
  176.      animation_name = @_animation.animation_name
  177.      animation_hue = @_animation.animation_hue
  178.      bitmap = RPG::Cache.animation(animation_name, animation_hue)
  179.      #=======================================
  180.      # 修改:计算总闪光权限值
  181.      #=======================================
  182.      for timing in @_animation.timings
  183.        quanzhong = animation_process_timing(timing, @_animation_hit,true)
  184.        @all_quanzhong += quanzhong
  185.        # 记录最后一次闪光
  186.        @_last_frame = timing.frame if quanzhong != 0
  187.      end      
  188.      if @@_reference_count.include?(bitmap)
  189.        @@_reference_count[bitmap] += 1
  190.      else
  191.        @@_reference_count[bitmap] = 1
  192.      end
  193.      #=======================================
  194.      # 修改:行动方动画不显示伤害
  195.      #=======================================
  196.      if $scene.is_a?(Scene_Battle)
  197.        if $scene.animation1_id == @battler.animation_id
  198.          @battler_damage = ""
  199.        end
  200.      end
  201.      @_animation_sprites = []
  202.      if @_animation.position != 3 or not @@_animations.include?(animation)
  203.        for i in 0..15
  204.          sprite = ::Sprite.new(self.viewport)
  205.          sprite.bitmap = bitmap
  206.          sprite.visible = false
  207.          @_animation_sprites.push(sprite)
  208.        end
  209.        unless @@_animations.include?(animation)
  210.          @@_animations.push(animation)
  211.        end
  212.      end
  213.      update_animation
  214.    end
  215.    #=======================================
  216.    # 修改:更换清除伤害的算法,以防万一
  217.    #       本内容在脚本中没有使用过
  218.    #=======================================
  219.    def dispose_damage
  220.      for damage in @_damage.reverse
  221.        damage[0].bitmap.dispose
  222.        damage[0].dispose
  223.        @_damage.delete(damage)
  224.      end
  225.      @_total_damage = 0
  226.      @_last_frame = -1
  227.      if @_total_damage_sprite != nil
  228.        @_total_damage_duration = 0
  229.        @_total_damage_sprite.bitmap.dispose
  230.        @_total_damage_sprite.dispose
  231.        @_total_damage_sprite = nil
  232.      end
  233.    end
  234.    def dispose_animation
  235.      #=======================================
  236.      # 修改:清除记录的伤害,清除权重记录
  237.      #=======================================
  238.      @battler_damage = nil
  239.      @battler_critical = nil
  240.      @all_quanzhong = 1
  241.      @_total_damage = 0
  242.      @_last_frame = -1
  243.      if @_animation_sprites != nil
  244.        sprite = @_animation_sprites[0]
  245.        if sprite != nil
  246.          @@_reference_count[sprite.bitmap] -= 1
  247.          if @@_reference_count[sprite.bitmap] == 0
  248.            sprite.bitmap.dispose
  249.          end
  250.        end
  251.        for sprite in @_animation_sprites
  252.          sprite.dispose
  253.        end
  254.        @_animation_sprites = nil
  255.        @_animation = nil
  256.      end
  257.    end
  258.    def update
  259.      super
  260.      if @_whiten_duration > 0
  261.        @_whiten_duration -= 1
  262.        self.color.alpha = 128 - (16 - @_whiten_duration) * 10
  263.      end
  264.      if @_appear_duration > 0
  265.        @_appear_duration -= 1
  266.        self.opacity = (16 - @_appear_duration) * 16
  267.      end
  268.      if @_escape_duration > 0
  269.        @_escape_duration -= 1
  270.        self.opacity = 256 - (32 - @_escape_duration) * 10
  271.      end
  272.      if @_collapse_duration > 0
  273.        @_collapse_duration -= 1
  274.        self.opacity = 256 - (48 - @_collapse_duration) * 6
  275.      end
  276.      #=======================================
  277.      # 修改:更新算法,更新弹出
  278.      #=======================================
  279.      if @_damage_duration > 0
  280.        @_damage_duration -= 1
  281.        for damage in @_damage
  282.          damage[0].x = self.x + self.viewport.rect.x -
  283.                        self.ox + self.src_rect.width / 2 +
  284.                        (40 - damage[1]) * damage[3] / 10
  285.          damage[0].y -= damage[4]+damage[1]/10
  286.          damage[0].opacity = damage[1]*20
  287.          damage[1] -= 1
  288.          if damage[1]==0
  289.            damage[0].bitmap.dispose
  290.            damage[0].dispose
  291.            @_damage.delete(damage)
  292.            next
  293.          end
  294.        end
  295.      end
  296.      #=======================================
  297.      # 添加:弹出总伤害
  298.      #=======================================
  299.      if @_total_damage_duration > 0
  300.        @_total_damage_duration -= 1
  301.        @_total_damage_sprite.y -= 1 if @_total_damage_duration % 2 == 0
  302.        if @_total_damage_sprite.zoom_x > 1.0
  303.          @_total_damage_sprite.zoom_x -= 0.05
  304.        end
  305.        if @_total_damage_sprite.zoom_y > 1.0
  306.          @_total_damage_sprite.zoom_y -= 0.05
  307.        end
  308.        @_total_damage_sprite.opacity = 256 - (24 - @_total_damage_duration) * 16
  309.        if @_total_damage_duration <= 0
  310.          @_total_damage = 0
  311.          @_total_damage_duration = 0
  312.          @_total_damage_sprite.bitmap.dispose
  313.          @_total_damage_sprite.dispose
  314.          @_total_damage_sprite = nil
  315.        end
  316.      end
  317.      #=======================================
  318.      if @_animation != nil and (Graphics.frame_count % 2 == 0)
  319.        @_animation_duration -= 1
  320.        update_animation
  321.      end
  322.      if @_loop_animation != nil and (Graphics.frame_count % 2 == 0)
  323.        update_loop_animation
  324.        @_loop_animation_index += 1
  325.        @_loop_animation_index %= @_loop_animation.frame_max
  326.      end
  327.      if @_blink
  328.        @_blink_count = (@_blink_count + 1) % 32
  329.        if @_blink_count < 16
  330.          alpha = (16 - @_blink_count) * 6
  331.        else
  332.          alpha = (@_blink_count - 16) * 6
  333.        end
  334.        self.color.set(255, 255, 255, alpha)
  335.      end
  336.      @@_animations.clear
  337.    end
  338.    def update_animation
  339.      if @_animation_duration > 0
  340.        frame_index = @_animation.frame_max - @_animation_duration
  341.        cell_data = @_animation.frames[frame_index].cell_data
  342.        position = @_animation.position
  343.        animation_set_sprites(@_animation_sprites, cell_data, position)
  344.        #=======================================
  345.        # 修改:弹出伤害,权重计算
  346.        #=======================================
  347.        for timing in @_animation.timings
  348.          if timing.frame == frame_index
  349.            t = 1.0 * animation_process_timing(timing, @_animation_hit)            
  350.            #p t,"当前权重", @all_quanzhong,"总权重"
  351.            if @battler_damage.is_a?(Numeric) and t != 0
  352.              t *= @battler_damage
  353.              t /= @all_quanzhong
  354.              #p t,"当前伤害",@battler_damage,"总伤害"
  355.              t = t.to_i
  356.              # 最后一次闪光的话,伤害修正
  357.              if frame_index == @_last_frame
  358.                @_total_damage = @battler_damage - t
  359.              end
  360.              #p t,@battler_damage,@all_quanzhong
  361.              damage(t,@battler_critical)
  362.            # 防止重复播放miss
  363.            elsif !@battler_damage.is_a?(Numeric) and timing.flash_scope != 0
  364.              damage(@battler_damage,@battler_critical)
  365.            end
  366.          end
  367.        end
  368.      else
  369.        dispose_animation
  370.      end
  371.    end
  372.    #=======================================
  373.    # 修改:敌人跳跃的功能 + 添加返回数值
  374.    #=======================================
  375.     def animation_process_timing(timing, hit,dontflash=false)
  376.       if (timing.condition == 0) or
  377.          (timing.condition == 1 and hit == true) or
  378.          (timing.condition == 2 and hit == false)
  379.         unless dontflash
  380.           if timing.se.name != ""
  381.             se = timing.se
  382.             Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
  383.           end
  384.         end
  385.         case timing.flash_scope
  386.         when 1
  387.           unless dontflash
  388.             self.flash(timing.flash_color, timing.flash_duration * 2)
  389.             if @_total_damage >0
  390.               @flash_shake_switch = true
  391.               @flash_shake = 10
  392.             end
  393.           end
  394.           return timing.flash_color.alpha * timing.flash_duration
  395.         when 2
  396.           unless dontflash
  397.             if self.viewport != nil
  398.               self.viewport.flash(timing.flash_color, timing.flash_duration * 2)
  399.               return timing.flash_color.alpha * timing.flash_duration
  400.             end
  401.           end
  402.         when 3
  403.           unless dontflash
  404.             self.flash(nil, timing.flash_duration * 2)
  405.           end
  406.           return timing.flash_color.alpha * timing.flash_duration
  407.         end
  408.       end      
  409.       return 0
  410.     end   
  411. end
  412. end
  413. #==============================================================================
  414. # ■ Sprite_Battler
  415. #==============================================================================
  416. class Sprite_Battler < RPG::Sprite
  417. #--------------------------------------------------------------------------
  418. # ● 初始化对像
  419. #    添加跳跃记录
  420. #--------------------------------------------------------------------------
  421. def initialize(viewport, battler = nil)
  422.   super(viewport)
  423.   @battler = battler
  424.   @battler_visible = false
  425.   @flash_shake_switch = true
  426. end

  427. end

  428. #==============================================================================
  429. # ■ Scene_Battle
  430. #------------------------------------------------------------------------------
  431. #  处理战斗画面的类。
  432. #==============================================================================

  433. class Scene_Battle
  434. #--------------------------------------------------------------------------
  435. # ● 定义实例变量
  436. #--------------------------------------------------------------------------
  437. attr_reader   :animation1_id                    # 行动方动画ID
  438. end

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

本版积分规则

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

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

GMT+8, 2024-9-21 13:20

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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