Project1

标题: 懂脚本的高手来看看 [打印本页]

作者: 005020671    时间: 2010-6-20 16:56
标题: 懂脚本的高手来看看
本帖最后由 005020671 于 2010-6-20 16:58 编辑

高手看看这个脚本主要是关于什么的,我只要他的大概意思就行,难道是有关战斗伤害???
  1. module RPG
  2.   class Sprite < ::Sprite
  3.     @@_animations = []
  4.     @@_reference_count = {}
  5.     def initialize(viewport = nil)
  6.       super(viewport)
  7.       @_whiten_duration = 0
  8.       @_appear_duration = 0
  9.       @_escape_duration = 0
  10.       @_collapse_duration = 0
  11.       @_damage_duration = 0
  12.       @_animation_duration = 0
  13.       @_blink = false
  14.     end
  15.     def dispose
  16.       dispose_damage
  17.       dispose_animation
  18.       dispose_loop_animation
  19.       super
  20.     end
  21.     def whiten
  22.       self.blend_type = 0
  23.       self.color.set(255, 255, 255, 128)
  24.       self.opacity = 255
  25.       @_whiten_duration = 16
  26.       @_appear_duration = 0
  27.       @_escape_duration = 0
  28.       @_collapse_duration = 0
  29.     end
  30.     def appear
  31.       self.blend_type = 0
  32.       self.color.set(0, 0, 0, 0)
  33.       self.opacity = 0
  34.       @_appear_duration = 16
  35.       @_whiten_duration = 0
  36.       @_escape_duration = 0
  37.       @_collapse_duration = 0
  38.     end
  39.     def escape
  40.       self.blend_type = 0
  41.       self.color.set(0, 0, 0, 0)
  42.       self.opacity = 255
  43.       @_escape_duration = 32
  44.       @_whiten_duration = 0
  45.       @_appear_duration = 0
  46.       @_collapse_duration = 0
  47.     end
  48.     def collapse
  49.       self.blend_type = 1
  50.       self.color.set(255, 64, 64, 255)
  51.       self.opacity = 255
  52.       @_collapse_duration = 48
  53.       @_whiten_duration = 0
  54.       @_appear_duration = 0
  55.       @_escape_duration = 0
  56.     end
  57.     def damage(value, critical)
  58.       dispose_damage
  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(160, 48)
  65.       #bitmap.font.name = "经典圆体繁"
  66.       bitmap.font.name = "华文新魏,黑体"
  67.       bitmap.font.size = 24
  68.       bitmap.font.color.set(0, 0, 0)
  69.       bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
  70.       bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
  71.       bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
  72.       bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
  73.       if value.is_a?(Numeric) and value < 0
  74.         bitmap.font.color.set(176, 255, 144)
  75.       else
  76.         bitmap.font.color.set(255, 255, 255)
  77.       end
  78.       bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
  79.       if critical
  80.         bitmap.font.size = 20
  81.         bitmap.font.color.set(0, 0, 0)
  82.         bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
  83.         bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
  84.         bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
  85.         bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
  86.         bitmap.font.color.set(255, 255, 255)
  87.         bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
  88.       end
  89.       @_damage_sprite = ::Sprite.new(self.viewport)
  90.       @_damage_sprite.bitmap = bitmap
  91.       @_damage_sprite.ox = 80
  92.       @_damage_sprite.oy = 20
  93.       @_damage_sprite.x = self.x
  94.       @_damage_sprite.x -= self.bitmap.width/16
  95.       @_damage_sprite.y = self.y - self.oy / 2
  96.       @_damage_sprite.y  -= self.bitmap.height/4 + 24
  97.       @_damage_sprite.z = 3000
  98.       @_damage_duration = 40
  99.     end
  100.     def animation(animation, hit)
  101.       dispose_animation
  102.       @_animation = animation
  103.       return if @_animation == nil
  104.       @_animation_hit = hit
  105.       @_animation_duration = @_animation.frame_max
  106.       animation_name = @_animation.animation_name
  107.       animation_hue = @_animation.animation_hue
  108.       bitmap = RPG::Cache.animation(animation_name, animation_hue)
  109.       if @@_reference_count.include?(bitmap)
  110.         @@_reference_count[bitmap] += 1
  111.       else
  112.         @@_reference_count[bitmap] = 1
  113.       end
  114.       @_animation_sprites = []
  115.       if @_animation.position != 3 or not @@_animations.include?(animation)
  116.         for i in 0..15
  117.           sprite = ::Sprite.new(self.viewport)
  118.           sprite.bitmap = bitmap
  119.           sprite.visible = false
  120.           @_animation_sprites.push(sprite)
  121.         end
  122.         unless @@_animations.include?(animation)
  123.           @@_animations.push(animation)
  124.         end
  125.       end
  126.       update_animation
  127.     end
  128.     def loop_animation(animation)
  129.       return if animation == @_loop_animation
  130.       dispose_loop_animation
  131.       @_loop_animation = animation
  132.       return if @_loop_animation == nil
  133.       @_loop_animation_index = 0
  134.       animation_name = @_loop_animation.animation_name
  135.       animation_hue = @_loop_animation.animation_hue
  136.       bitmap = RPG::Cache.animation(animation_name, animation_hue)
  137.       if @@_reference_count.include?(bitmap)
  138.         @@_reference_count[bitmap] += 1
  139.       else
  140.         @@_reference_count[bitmap] = 1
  141.       end
  142.       @_loop_animation_sprites = []
  143.       for i in 0..15
  144.         sprite = ::Sprite.new(self.viewport)
  145.         sprite.bitmap = bitmap
  146.         sprite.visible = false
  147.         @_loop_animation_sprites.push(sprite)
  148.       end
  149.       update_loop_animation
  150.     end
  151.     def dispose_damage
  152.       if @_damage_sprite != nil
  153.         @_damage_sprite.bitmap.dispose
  154.         @_damage_sprite.dispose
  155.         @_damage_sprite = nil
  156.         @_damage_duration = 0
  157.       end
  158.     end
  159.     def dispose_animation
  160.       if @_animation_sprites != nil
  161.         sprite = @_animation_sprites[0]
  162.         if sprite != nil
  163.           @@_reference_count[sprite.bitmap] -= 1
  164.           if @@_reference_count[sprite.bitmap] == 0
  165.             sprite.bitmap.dispose
  166.           end
  167.         end
  168.         for sprite in @_animation_sprites
  169.           sprite.dispose
  170.         end
  171.         @_animation_sprites = nil
  172.         @_animation = nil
  173.       end
  174.     end
  175.     def dispose_loop_animation
  176.       if @_loop_animation_sprites != nil
  177.         sprite = @_loop_animation_sprites[0]
  178.         if sprite != nil
  179.           @@_reference_count[sprite.bitmap] -= 1
  180.           if @@_reference_count[sprite.bitmap] == 0
  181.             sprite.bitmap.dispose
  182.           end
  183.         end
  184.         for sprite in @_loop_animation_sprites
  185.           sprite.dispose
  186.         end
  187.         @_loop_animation_sprites = nil
  188.         @_loop_animation = nil
  189.       end
  190.     end
  191.     def blink_on
  192.       unless @_blink
  193.         @_blink = true
  194.         @_blink_count = 0
  195.       end
  196.     end
  197.     def blink_off
  198.       if @_blink
  199.         @_blink = false
  200.         self.color.set(0, 0, 0, 0)
  201.       end
  202.     end
  203.     def blink?
  204.       @_blink
  205.     end
  206.     def effect?
  207.       @_whiten_duration > 0 or
  208.       @_appear_duration > 0 or
  209.       @_escape_duration > 0 or
  210.       @_collapse_duration > 0 or
  211.       @_damage_duration > 0 or
  212.       @_animation_duration > 0
  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.       if @_damage_duration > 0
  233.         @_damage_duration -= 1
  234.         case @_damage_duration
  235.         when 38..39
  236.           @_damage_sprite.y -= 4
  237.         when 36..37
  238.           @_damage_sprite.y -= 2
  239.         when 34..35
  240.           @_damage_sprite.y += 2
  241.         when 28..33
  242.           @_damage_sprite.y += 4
  243.         end
  244.         @_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32
  245.         if @_damage_duration == 0
  246.           dispose_damage
  247.         end
  248.       end
  249.       if @_animation != nil and (Graphics.frame_count % 2 == 0)
  250.         @_animation_duration -= 1
  251.         update_animation
  252.       end
  253.       if @_loop_animation != nil and (Graphics.frame_count % 2 == 0)
  254.         update_loop_animation
  255.         @_loop_animation_index += 1
  256.         @_loop_animation_index %= @_loop_animation.frame_max
  257.       end
  258.       if @_blink
  259.         @_blink_count = (@_blink_count + 1) % 32
  260.         if @_blink_count < 16
  261.           alpha = (16 - @_blink_count) * 6
  262.         else
  263.           alpha = (@_blink_count - 16) * 6
  264.         end
  265.         self.color.set(255, 255, 255, alpha)
  266.       end
  267.       @@_animations.clear
  268.     end
  269.     def update_animation
  270.       if @_animation_duration > 0
  271.         frame_index = @_animation.frame_max - @_animation_duration
  272.         cell_data = @_animation.frames[frame_index].cell_data
  273.         position = @_animation.position
  274.         animation_set_sprites(@_animation_sprites, cell_data, position)
  275.         for timing in @_animation.timings
  276.           if timing.frame == frame_index
  277.             animation_process_timing(timing, @_animation_hit)
  278.           end
  279.         end
  280.       else
  281.         dispose_animation
  282.       end
  283.     end
  284.     def update_loop_animation
  285.       frame_index = @_loop_animation_index
  286.       cell_data = @_loop_animation.frames[frame_index].cell_data
  287.       position = @_loop_animation.position
  288.       animation_set_sprites(@_loop_animation_sprites, cell_data, position)
  289.       for timing in @_loop_animation.timings
  290.         if timing.frame == frame_index
  291.           animation_process_timing(timing, true)
  292.         end
  293.       end
  294.     end
  295.     def animation_set_sprites(sprites, cell_data, position)
  296.       for i in 0..15
  297.         sprite = sprites[i]
  298.         pattern = cell_data[i, 0]
  299.         if sprite == nil or pattern == nil or pattern == -1
  300.           sprite.visible = false if sprite != nil
  301.           next
  302.         end
  303.         sprite.visible = true
  304.         sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
  305.         if position == 3
  306.           if self.viewport != nil
  307.             sprite.x = self.viewport.rect.width / 2
  308.             sprite.y = self.viewport.rect.height - 160
  309.           else
  310.             sprite.x = 320
  311.             sprite.y = 240
  312.           end
  313.         else
  314.           sprite.x = self.x - self.ox + self.src_rect.width / 2
  315.           sprite.y = self.y - self.oy + self.src_rect.height / 2
  316.           sprite.y -= self.src_rect.height / 4 if position == 0
  317.           sprite.y += self.src_rect.height / 4 if position == 2
  318.         end
  319.         sprite.x += cell_data[i, 1]
  320.         sprite.y += cell_data[i, 2]
  321.         sprite.z = 2000
  322.         sprite.ox = 96
  323.         sprite.oy = 96
  324.         sprite.zoom_x = cell_data[i, 3] / 100.0
  325.         sprite.zoom_y = cell_data[i, 3] / 100.0
  326.         sprite.angle = cell_data[i, 4]
  327.         sprite.mirror = (cell_data[i, 5] == 1)
  328.         sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
  329.         sprite.blend_type = cell_data[i, 7]
  330.       end
  331.     end
  332.     def animation_process_timing(timing, hit)
  333.       if (timing.condition == 0) or
  334.          (timing.condition == 1 and hit == true) or
  335.          (timing.condition == 2 and hit == false)
  336.         if timing.se.name != ""
  337.           se = timing.se
  338.           Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
  339.         end
  340.         case timing.flash_scope
  341.         when 1
  342.           self.flash(timing.flash_color, timing.flash_duration * 2)
  343.         when 2
  344.           if self.viewport != nil
  345.             self.viewport.flash(timing.flash_color, timing.flash_duration * 2)
  346.           end
  347.         when 3
  348.           self.flash(nil, timing.flash_duration * 2)
  349.         end
  350.       end
  351.     end
  352.     def x=(x)
  353.       sx = x - self.x
  354.       if sx != 0
  355.         if @_animation_sprites != nil
  356.           for i in 0..15
  357.             @_animation_sprites[i].x += sx
  358.           end
  359.         end
  360.         if @_loop_animation_sprites != nil
  361.           for i in 0..15
  362.             @_loop_animation_sprites[i].x += sx
  363.           end
  364.         end
  365.       end
  366.       super
  367.     end
  368.     def y=(y)
  369.       sy = y - self.y
  370.       if sy != 0
  371.         if @_animation_sprites != nil
  372.           for i in 0..15
  373.             @_animation_sprites[i].y += sy
  374.           end
  375.         end
  376.         if @_loop_animation_sprites != nil
  377.           for i in 0..15
  378.             @_loop_animation_sprites[i].y += sy
  379.           end
  380.         end
  381.       end
  382.       super
  383.     end
  384.   end
  385. end
复制代码

作者: 小角色    时间: 2010-6-20 17:29
应该是伤害美化的脚本
作者: 005020671    时间: 2010-6-20 18:17
回复 小角色 的帖子


    恩恩,谢啦,运行看了一下,确实是伤害美化,由于先前有另一个脚本居于其下,没看出来。




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1