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

Project1

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

[已经解决] 角色攻击时如何让敌人后退?

[复制链接]

Lv1.梦旅人

虱子

梦石
0
星屑
121
在线时间
1782 小时
注册时间
2010-6-19
帖子
3597
1
发表于 2012-7-31 23:46:39 | 显示全部楼层
据说彩虹神剑有这功能
  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 = false
  28. # 角色受攻击时是否跳一下
  29. BATTLER_JUMP = true

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

http://rpg.blue/thread-175056-1-2.html
PVZ型塔防物一个
http://rpg.blue/thread-155199-1-2.html
RMXP技术讨论区手动认可帖,得到答案请认可
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-21 10:46

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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