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

Project1

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

[已经过期] 关于经典的彩虹神剑,为何敌人不挨打跳跃?

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
28 小时
注册时间
2008-12-23
帖子
35
跳转到指定楼层
1
发表于 2015-5-16 15:50:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
我想做成一个战斗角色挨打后后退的脚本,就打算参考彩虹神剑。
一切开始都很正常,我稍稍做了一点修改,取消了分段伤害的设定,留下了总伤害和挨打跳跃设定,可是在测试时出了问题:敌人在挨打时不会跳跃,我方挨打却会。
这个情况真的十分奇怪,因为我在整个脚本中都找不到“判断对象是否为敌人”的字眼,而事实的确是敌人不跳跃而我方跳跃。
求大神解决。
以下是脚本:
RUBY 代码复制
  1. =begin
  2. ==============================================================================
  3.  
  4. 彩虹神剑(伤害分段显示)显示总伤害版 v1.0b
  5.  
  6. ==============================================================================
  7.  
  8. 彩虹神剑 by 柳柳
  9. 显示总伤害修改 by 叶子
  10.  
  11. ==============================================================================
  12.  
  13. 6-20-2006 v1.0
  14. 在彩虹神剑的基础上增加了显示总伤害的功能,而且总伤害的数字是弹出伤害时逐渐增加的
  15.  
  16. v1.0a
  17. 修正了显示伤害和实际伤害有差别的问题
  18. 修正了miss的情况下显示miss混乱的问题
  19. 修正了对己方技能重复显示伤害的问题
  20. 未修正播放目标动画第一帧时目标有时无端跳动的BUG
  21.  
  22. v1.0b
  23. 修改了总伤害数字的位置和z坐标
  24. 未修正播放目标动画第一帧时目标有时无端跳动的BUG
  25.  
  26. ==============================================================================
  27. =end
  28. # 核心的说明:
  29. # damage_pop 不再附带damage()的功能,这个放到animation里面去了
  30.  
  31. module RPG
  32. #--------------------------------------------------------------------------
  33. # ● 常量设定
  34. #--------------------------------------------------------------------------
  35. # 是否显示总伤害
  36. SHOW_TOTAL_DAMAGE = true
  37. # 角色受攻击时是否跳一下
  38. BATTLER_JUMP = true
  39.  
  40. class Sprite < ::Sprite
  41.    #==========================================
  42.    # 修改说明:
  43.    # @flash_shake用来制作挨打时候跳跃
  44.    # @_damage    用来记录每次打击之后弹出数字
  45.    # @_total_damage 记录总伤害
  46.    # @_total_damage_duration 总伤害持续帧
  47.    #==========================================
  48.    #alias 66RPG_rainbow_initialize : initialize
  49.    def initialize(viewport = nil)
  50.      #66RPG_rainbow_initialize(viewport)
  51.      super(viewport)
  52.      @_whiten_duration = 0
  53.      @_appear_duration = 0
  54.      @_escape_duration = 0
  55.      @_collapse_duration = 0
  56.      @_damage_duration = 0
  57.      @_animation_duration = 0
  58.      @_blink = false
  59.      # 挨打时候跳跃
  60.      @flash_shake = 0
  61.      # 伤害记录数组
  62.      @_damage = []
  63.      # 总伤害数字
  64.      @_total_damage = 0
  65.      # 总伤害持续帧
  66.      @_total_damage_duration = 0
  67.    end
  68.   def effect?
  69.       @_whiten_duration > 0 or
  70.       @_appear_duration > 0 or
  71.       @_escape_duration > 0 or
  72.       @_collapse_duration > 0 or
  73.       @_animation_duration > 0
  74.     end
  75.    def damage(value, critical)
  76.      if value.is_a?(Numeric)
  77.        damage_string = value.abs.to_s
  78.      else
  79.        damage_string = value.to_s
  80.      end
  81.      bitmap = Bitmap.new(160, 48)
  82.      bitmap.font.name = "Adobe Arabic "#"Arial Black"
  83.      bitmap.font.size = 32
  84.      bitmap.font.color.set(0, 0, 0)
  85. #     bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
  86. #     bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
  87. #     bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
  88. #     bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
  89.      #=======================================
  90.      # 修改:颜色
  91.      #=======================================
  92.      if value.is_a?(Numeric) and value < 0
  93.        bitmap.font.color.set(176, 255, 144)
  94.      else
  95.        bitmap.font.color.set(255, 55, 55)
  96.      end
  97.      bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
  98.      if critical
  99.        bitmap.font.size = 20
  100.        bitmap.font.color.set(0, 0, 0)
  101.        bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
  102.        bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
  103.        bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
  104.        bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
  105.        bitmap.font.color.set(255, 255, 255)
  106.        bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
  107.      end
  108.      @_damage_sprite = ::Sprite.new(self.viewport)
  109.      @_damage_sprite.bitmap = bitmap
  110.      @_damage_sprite.ox = 80
  111.      @_damage_sprite.oy = 20
  112.      @_damage_sprite.x = self.x
  113.      @_damage_sprite.y = self.y - self.oy / 2
  114.      @_damage_sprite.z = 3000
  115.      @_damage_duration = 40
  116.      #=======================================
  117.      # 修改:推入新的伤害
  118.      #=======================================
  119.      @_damage.push([@_damage_sprite,@_damage_duration-10,0, rand(30) - 15, rand(3)])
  120.      # 总伤害处理
  121.      make_total_damage(value)
  122.    end
  123.    #--------------------------------------------------------------------------
  124.    # ● 总伤害处理
  125.    #--------------------------------------------------------------------------
  126.    def make_total_damage(value)
  127.      if value.is_a?(Numeric) and SHOW_TOTAL_DAMAGE
  128.        @_total_damage += value
  129.      else
  130.        return
  131.      end
  132.      bitmap = Bitmap.new(300, 150)
  133.      bitmap.font.name = "Adobe Arabic"#"Arial Black"
  134.      bitmap.font.size = 36
  135.      bitmap.font.color.set(0, 0, 0)
  136.      bitmap.draw_text(+2, 12+2, 160, 36, @_total_damage.abs.to_s, 1)
  137.      if @_total_damage < 0
  138.        bitmap.font.color.set(80, 255, 00)
  139.      else
  140.        bitmap.font.color.set(255, 140, 0)
  141.      end
  142.      bitmap.draw_text(0, 12, 160, 36, @_total_damage.abs.to_s, 1)
  143.      if @_total_damage_sprite.nil?
  144.        @_total_damage_sprite = ::Sprite.new(self.viewport)
  145.        @_total_damage_sprite.ox = 80
  146.        @_total_damage_sprite.oy = 20
  147.        @_total_damage_sprite.z = 3000
  148.      end
  149.      @_total_damage_sprite.bitmap = bitmap
  150.      @_total_damage_sprite.zoom_x = 1.2
  151.      @_total_damage_sprite.zoom_y = 1
  152.      @_total_damage_sprite.x = self.x
  153.      @_total_damage_sprite.y = self.y  - self.oy / 2 - 32
  154.      @_total_damage_sprite.z = 3001
  155.      @_total_damage_duration = 80
  156.    end
  157.    def animation(animation, hit, battler_damage="", battler_critical=false)
  158.      dispose_animation      
  159.      #=======================================
  160.      # 修改:记录伤害和critical
  161.      #=======================================
  162.      @battler_damage = battler_damage
  163.      @battler_critical = battler_critical
  164.      @_animation = animation
  165.      return if @_animation == nil
  166.      @_animation_hit = hit
  167.      @_animation_duration = @_animation.frame_max
  168.      animation_name = @_animation.animation_name
  169.      animation_hue = @_animation.animation_hue
  170.      bitmap = RPG::Cache.animation(animation_name, animation_hue)
  171.      #=======================================
  172.      # 修改:计算总闪光权限值
  173.      #=======================================
  174.      for timing in @_animation.timings
  175.        quanzhong = animation_process_timing(timing, @_animation_hit,true)
  176.        @all_quanzhong += quanzhong
  177.        # 记录最后一次闪光
  178.        @_last_frame = timing.frame if quanzhong != 0
  179.      end      
  180.      if @@_reference_count.include?(bitmap)
  181.        @@_reference_count[bitmap] += 1
  182.      else
  183.        @@_reference_count[bitmap] = 1
  184.      end
  185.      #=======================================
  186.      # 修改:行动方动画不显示伤害
  187.      #=======================================
  188.      if $scene.is_a?(Scene_Battle)
  189.        if $scene.animation1_id == @battler.animation_id
  190.          @battler_damage = ""
  191.        end
  192.      end
  193.      @_animation_sprites = []
  194.      if @_animation.position != 3 or not @@_animations.include?(animation)
  195.        for i in 0..15
  196.          sprite = ::Sprite.new(self.viewport)
  197.          sprite.bitmap = bitmap
  198.          sprite.visible = false
  199.          sprite.z = self.z-1
  200.          @_animation_sprites.push(sprite)
  201.        end
  202.        unless @@_animations.include?(animation)
  203.          @@_animations.push(animation)
  204.        end
  205.      end
  206.      update_animation
  207.    end
  208.    #=======================================
  209.    # 修改:更换清除伤害的算法,以防万一
  210.    #       本内容在脚本中没有使用过
  211.    #=======================================
  212.    def dispose_damage
  213.      for damage in @_damage.reverse
  214.        damage[0].bitmap.dispose
  215.        damage[0].dispose
  216.        @_damage.delete(damage)
  217.      end
  218.      @_total_damage = 0
  219.      @_last_frame = -1
  220.      if @_total_damage_sprite != nil
  221.        @_total_damage_duration = 0
  222.        @_total_damage_sprite.bitmap.dispose
  223.        @_total_damage_sprite.dispose
  224.        @_total_damage_sprite = nil
  225.      end
  226.    end
  227.    def dispose_animation
  228.      #=======================================
  229.      # 修改:清除记录的伤害,清除权重记录
  230.      #=======================================
  231.      @battler_damage = nil
  232.      @battler_critical = nil
  233.      @all_quanzhong = 1
  234.      @_total_damage = 0
  235.      @_last_frame = -1
  236.      if @_animation_sprites != nil
  237.        sprite = @_animation_sprites[0]
  238.        if sprite != nil
  239.          @@_reference_count[sprite.bitmap] -= 1
  240.          if @@_reference_count[sprite.bitmap] == 0
  241.            sprite.bitmap.dispose
  242.          end
  243.        end
  244.        for sprite in @_animation_sprites
  245.          sprite.dispose
  246.        end
  247.        @_animation_sprites = nil
  248.        @_animation = nil
  249.      end
  250.    end
  251.    def update
  252.      super
  253.      if @_whiten_duration > 0
  254.        @_whiten_duration -= 1
  255.        self.color.alpha = 128 - (16 - @_whiten_duration) * 10
  256.      end
  257.      if @_appear_duration > 0
  258.        @_appear_duration -= 1
  259.        self.opacity = (16 - @_appear_duration) * 16
  260.      end
  261.      if @_escape_duration > 0
  262.        @_escape_duration -= 1
  263.        self.opacity = 256 - (32 - @_escape_duration) * 10
  264.      end
  265.      if @_collapse_duration > 0
  266.        @_collapse_duration -= 1
  267.        self.opacity = 256 - (48 - @_collapse_duration) * 6
  268.      end
  269.      #=======================================
  270.      # 修改:更新算法,更新弹出
  271.      #=======================================
  272.      if @_damage_duration > 0
  273.        @_damage_duration -= 1
  274.        for damage in @_damage
  275.          damage[0].x = self.x + self.viewport.rect.x -
  276.                        self.ox + self.src_rect.width / 2 +
  277.                        (40 - damage[1]) * damage[3] / 10
  278.          damage[0].y -= damage[4]+damage[1]/10
  279.          damage[0].opacity = damage[1]*20
  280.          damage[1] -= 1
  281.          if damage[1]==0
  282.            damage[0].bitmap.dispose
  283.            damage[0].dispose
  284.            @_damage.delete(damage)
  285.            next
  286.          end
  287.        end
  288.      end
  289.      #=======================================
  290.      # 添加:弹出总伤害
  291.      #=======================================
  292.      if @_total_damage_duration > 0
  293.        @_total_damage_duration -= 1
  294.        @_total_damage_sprite.y -= 1 if @_total_damage_duration % 2 == 0
  295.        if @_total_damage_sprite.zoom_x > 1.0
  296.          @_total_damage_sprite.zoom_x -= 0.05
  297.        end
  298.        if @_total_damage_sprite.zoom_y > 1.0
  299.          @_total_damage_sprite.zoom_y -= 0.05
  300.        end
  301.        @_total_damage_sprite.opacity = 256 - (24 - @_total_damage_duration) * 16
  302.        if @_total_damage_duration <= 0
  303.          @_total_damage = 0
  304.          @_total_damage_duration = 0
  305.          @_total_damage_sprite.bitmap.dispose
  306.          @_total_damage_sprite.dispose
  307.          @_total_damage_sprite = nil
  308.        end
  309.      end
  310.      #=======================================
  311.      if @_animation != nil and (Graphics.frame_count % 2 == 0)
  312.        @_animation_duration -= 1
  313.        update_animation
  314.      end
  315.      if @_loop_animation != nil and (Graphics.frame_count % 2 == 0)
  316.        update_loop_animation
  317.        @_loop_animation_index += 1
  318.        @_loop_animation_index %= @_loop_animation.frame_max
  319.      end
  320.      if @_blink
  321.        @_blink_count = (@_blink_count + 1) % 32
  322.        if @_blink_count < 16
  323.          alpha = (16 - @_blink_count) * 6
  324.        else
  325.          alpha = (@_blink_count - 16) * 6
  326.        end
  327.        self.color.set(255, 255, 255, alpha)
  328.      end
  329.      @@_animations.clear
  330.    end
  331.    def update_animation
  332.      if @_animation_duration > 0
  333.        frame_index = @_animation.frame_max - @_animation_duration
  334.        cell_data = @_animation.frames[frame_index].cell_data
  335.        position = @_animation.position
  336.        animation_set_sprites(@_animation_sprites, cell_data, position)
  337.        #=======================================
  338.        # 修改:弹出伤害,权重计算
  339.        #=======================================
  340.        for timing in @_animation.timings
  341.          if timing.frame == frame_index
  342.            t = 1.0 * animation_process_timing(timing, @_animation_hit)            
  343.            #p t,"当前权重", @all_quanzhong,"总权重"
  344.            if @battler_damage.is_a?(Numeric) and t != 0
  345.              t *= @battler_damage
  346.              t /= @all_quanzhong
  347.              #p t,"当前伤害",@battler_damage,"总伤害"
  348.              t = t.to_i
  349.              # 最后一次闪光的话,伤害修正
  350.              if frame_index == @_last_frame
  351.                @_total_damage = @battler_damage - t
  352.              end
  353.              #p t,@battler_damage,@all_quanzhong
  354.              damage(t,@battler_critical)
  355.            # 防止重复播放miss
  356.            elsif !@battler_damage.is_a?(Numeric) and timing.flash_scope != 0
  357.              damage(@battler_damage,@battler_critical)
  358.            end
  359.          end
  360.        end
  361.      else
  362.        dispose_animation
  363.      end
  364.    end
  365.    #=======================================
  366.    # 修改:敌人跳跃的功能 + 添加返回数值
  367.    #=======================================
  368.     def animation_process_timing(timing, hit,dontflash=false)
  369.       if (timing.condition == 0) or
  370.          (timing.condition == 1 and hit == true) or
  371.          (timing.condition == 2 and hit == false)
  372.         unless dontflash
  373.           if timing.se.name != ""
  374.             se = timing.se
  375.             Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
  376.           end
  377.         end
  378.         case timing.flash_scope
  379.         when 1
  380.           unless dontflash
  381.             self.flash(timing.flash_color, timing.flash_duration * 2)
  382.             if @_total_damage >0
  383.               @flash_shake_switch = true
  384.               @flash_shake = 10
  385.             end
  386.           end
  387.           return timing.flash_color.alpha * timing.flash_duration
  388.         when 2
  389.           unless dontflash
  390.             if self.viewport != nil
  391.               self.viewport.flash(timing.flash_color, timing.flash_duration * 2)
  392.               return timing.flash_color.alpha * timing.flash_duration
  393.             end
  394.           end
  395.         when 3
  396.           unless dontflash
  397.             self.flash(nil, timing.flash_duration * 2)
  398.           end
  399.           return timing.flash_color.alpha * timing.flash_duration
  400.         end
  401.       end      
  402.       return 0
  403.     end   
  404. end
  405. end
  406. #==============================================================================
  407. # ■ Sprite_Battler
  408. #==============================================================================
  409. class Sprite_Battler < RPG::Sprite
  410. #--------------------------------------------------------------------------
  411. # ● 初始化对像
  412. #    添加跳跃记录
  413. #--------------------------------------------------------------------------
  414. def initialize(viewport, battler = nil)
  415.   super(viewport)
  416.   @battler = battler
  417.   @battler_visible = false
  418.   @flash_shake_switch = true
  419. end
  420. #--------------------------------------------------------------------------
  421. # ● 刷新画面
  422. #    增添跳跃功能
  423. #--------------------------------------------------------------------------
  424. def update
  425.   super
  426.   # 战斗者为 nil 的情况下
  427.   if @battler == nil
  428.     self.bitmap = nil
  429.     loop_animation(nil)
  430.     return
  431.   end
  432.   # 文件名和色相与当前情况有差异的情况下
  433.   if @battler.battler_name != @battler_name or
  434.      @battler.battler_hue != @battler_hue
  435.     # 获取、设置位图
  436.      @battler_name = @battler.battler_name
  437.      @battler_hue = @battler.battler_hue
  438.      self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
  439.      @width = bitmap.width / 3
  440.      @height = bitmap.height / 4
  441.      if @battler.is_a?(Game_Actor)
  442.        y=96
  443.      else
  444.        y=0
  445.      end
  446.      self.src_rect.set(0, y, 32, 32)
  447.      self.ox = @width / 2
  448.      self.oy = @height / 2
  449.     # 如果是战斗不能或者是隐藏状态就把透明度设置成 0
  450.     if @battler.dead? or @battler.hidden
  451.       self.opacity = 0
  452.     end
  453.   end
  454.   # 动画 ID 与当前的情况有差异的情况下
  455.   if @battler.damage == nil and
  456.      @battler.state_animation_id != @state_animation_id
  457.     @state_animation_id = @battler.state_animation_id
  458.     loop_animation($data_animations[@state_animation_id])
  459.   end
  460.   # 应该被显示的角色的情况下
  461.   if @battler.is_a?(Game_Actor) and @battler_visible
  462.     # 不是主状态的时候稍稍降低点透明度
  463.     if $game_temp.battle_main_phase
  464.       self.opacity += 3 if self.opacity < 255
  465.     else
  466.       self.opacity -= 3 if self.opacity > 207
  467.     end
  468.   end
  469.   # 明灭
  470.   if @battler.blink
  471.     blink_on
  472.   else
  473.     blink_off
  474.   end
  475.   # 不可见的情况下
  476.   unless @battler_visible
  477.     # 出现
  478.     if not @battler.hidden and not @battler.dead? and
  479.        (@battler.damage == nil or @battler.damage_pop)
  480.       appear
  481.       @battler_visible = true
  482.     end
  483.   end
  484.   # 可见的情况下
  485.   if @battler_visible
  486.     # 逃跑
  487.     if @battler.hidden
  488.       $game_system.se_play($data_system.escape_se)
  489.       escape
  490.       @battler_visible = false
  491.     end
  492.     # 白色闪烁
  493.     if @battler.white_flash
  494.       whiten
  495.       @battler.white_flash = false
  496.     end
  497.     # 动画
  498.     if @battler.animation_id != 0
  499.       animation = $data_animations[@battler.animation_id]
  500.       animation(animation, @battler.animation_hit,@battler.damage, @battler.critical)
  501.       @battler.animation_id = 0
  502.     end
  503.     # 伤害
  504.     if @battler.damage_pop
  505.       @battler.damage = nil
  506.       @battler.critical = false
  507.       @battler.damage_pop = false
  508.     end
  509.     # korapusu
  510.     if @battler.damage == nil and @battler.dead?
  511.       if @battler.is_a?(Game_Enemy)
  512.         $game_system.se_play($data_system.enemy_collapse_se)
  513.       else
  514.         $game_system.se_play($data_system.actor_collapse_se)
  515.       end
  516.       collapse
  517.       @battler_visible = false
  518.     end
  519.   end
  520.   # 设置活动块的坐标
  521.   if @flash_shake_switch == true
  522.     self.x = @battler.screen_x
  523.     self.y = @battler.screen_y
  524.     self.z = @battler.screen_z
  525.     @flash_shake_switch = false
  526.   end
  527.   if @flash_shake != 0 and @battler.damage != nil and RPG::BATTLER_JUMP
  528.     case @flash_shake
  529.     when 9..10
  530.       self.x = @battler.screen_x
  531.       self.y -=4
  532.       self.z = @battler.screen_z
  533.     when 6..8
  534.       self.x = @battler.screen_x
  535.       self.y -=2
  536.       self.z = @battler.screen_z
  537.     when 3..5
  538.       self.x = @battler.screen_x
  539.       self.y +=2
  540.       self.z = @battler.screen_z
  541.     when 2
  542.       self.x = @battler.screen_x
  543.       self.y += 4
  544.       self.z = @battler.screen_z
  545.     when 1
  546.       self.x = @battler.screen_x
  547.       self.y = @battler.screen_y
  548.       self.z = @battler.screen_z
  549.     end
  550.     @flash_shake -= 1
  551.   end
  552. end
  553. end
  554.  
  555. class Scene_Battle
  556. attr_reader :animation1_id
  557. end
我的游戏我自己做
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2024-9-22 23:33

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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