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

Project1

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

[已经解决] 求一个战斗图往复运动的效果

 关闭 [复制链接]

Lv4.逐梦者

梦石
3
星屑
6420
在线时间
1131 小时
注册时间
2007-12-26
帖子
2402
跳转到指定楼层
1
发表于 2011-10-11 13:48:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
想用来模仿中招后的身体抖动:当敌人或角色中招,在播放攻击动画的时候,战斗图快速左右左右左右移动,攻击动画播放结束,战斗图回复原位
囡囚囨囚囨図囨囧

Lv1.梦旅人

梦石
0
星屑
50
在线时间
22 小时
注册时间
2011-10-11
帖子
72
2
发表于 2011-10-11 15:20:36 | 只看该作者

  1. # 核心的说明:
  2. # damage_pop 不再附带damage()的功能,这个放到animation里面去了

  3. module RPG
  4. #--------------------------------------------------------------------------
  5. # ● 常量设定
  6. #--------------------------------------------------------------------------
  7. # 是否显示总伤害
  8. SHOW_TOTAL_DAMAGE = true
  9. # 角色受攻击时是否跳一下
  10. BATTLER_JUMP = true

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

  511. #==============================================================================
  512. # ■ Scene_Battle
  513. #------------------------------------------------------------------------------
  514. #  处理战斗画面的类。
  515. #==============================================================================

  516. class Scene_Battle
  517. #--------------------------------------------------------------------------
  518. # ● 定义实例变量
  519. #--------------------------------------------------------------------------
  520. attr_reader   :animation1_id                    # 行动方动画ID
  521. end
复制代码
用彩虹神剑可以实现战斗图来回蹦跳效果
回复

使用道具 举报

Lv4.逐梦者

梦石
3
星屑
6420
在线时间
1131 小时
注册时间
2007-12-26
帖子
2402
3
 楼主| 发表于 2011-10-11 15:32:49 | 只看该作者
本帖最后由 幻耶 于 2011-10-11 15:46 编辑
赵灵儿 发表于 2011-10-11 15:20
用彩虹神剑可以实现战斗图来回蹦跳效果


用这个战斗图在攻击之前就抖动了,能不能让战斗图在播放攻击动画的同时抖动?

我改成了这个样子:
  1.     case @flash_shake
  2.     when 15..16
  3.       self.x -= 10
  4.       self.y = @battler.screen_y
  5.       self.z = @battler.screen_z
  6.     when 13..14
  7.       self.x += 20
  8.       self.y = @battler.screen_y
  9.       self.z = @battler.screen_z
  10.     when 11..12
  11.       self.x -= 20
  12.       self.y = @battler.screen_y
  13.       self.z = @battler.screen_z
  14.     when 9..10
  15.       self.x += 20
  16.       self.y = @battler.screen_y
  17.       self.z = @battler.screen_z
  18.     when 7..8
  19.       self.x -= 20
  20.       self.y = @battler.screen_y
  21.       self.z = @battler.screen_z
  22.     when 5..6
  23.       self.x += 20
  24.       self.y = @battler.screen_y
  25.       self.z = @battler.screen_z
  26.     when 3..4
  27.       self.x -= 20
  28.       self.y = @battler.screen_y
  29.       self.z = @battler.screen_z
  30.     when 1..2
  31.       self.x = @battler.screen_x
  32.       self.y = @battler.screen_y
  33.       self.z = @battler.screen_z
  34.     end
复制代码
囡囚囨囚囨図囨囧
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
22 小时
注册时间
2011-10-11
帖子
72
4
发表于 2011-10-11 16:32:13 | 只看该作者
那么就修改1..2,9..10之类的数。这些数代表帧,比如说9..10代表9帧与10帧。
回复

使用道具 举报

Lv4.逐梦者

梦石
3
星屑
6420
在线时间
1131 小时
注册时间
2007-12-26
帖子
2402
5
 楼主| 发表于 2011-10-12 08:36:56 | 只看该作者
赵灵儿 发表于 2011-10-11 16:32
那么就修改1..2,9..10之类的数。这些数代表帧,比如说9..10代表9帧与10帧。

我改了,但是战斗图总是在攻击动画之前就抖动了啊
囡囚囨囚囨図囨囧
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
22 小时
注册时间
2011-10-11
帖子
72
6
发表于 2011-10-12 10:59:49 | 只看该作者
。。。。。。那我就没办法了,去求柳柳和叶子这两位彩虹的原作者吧或许有一丝希望
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2025-7-21 02:55

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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