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

Project1

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

关于RM的战斗系统

 关闭 [复制链接]
头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
0 小时
注册时间
2007-6-8
帖子
96
跳转到指定楼层
1
发表于 2007-7-15 19:28:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
0 小时
注册时间
2007-6-8
帖子
96
2
 楼主| 发表于 2007-7-15 19:28:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽

Lv2.观梦者

梦石
0
星屑
431
在线时间
125 小时
注册时间
2006-11-2
帖子
1200
3
发表于 2007-7-15 20:25:31 | 只看该作者
  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.      
  32.       self.blend_type = 0
  33.       self.color.set(0, 0, 0, 0)
  34.       self.opacity = 0
  35.       @_appear_duration = 21
  36.       @_whiten_duration = 0
  37.       @_escape_duration = 0
  38.       @_collapse_duration = 0
  39.     end
  40.     def escape
  41.       self.blend_type = 0
  42.       self.color.set(0, 0, 0, 0)
  43.       self.opacity = 255
  44.       @_escape_duration = 32
  45.       @_whiten_duration = 0
  46.       @_appear_duration = 0
  47.       @_collapse_duration = 0
  48.     end
  49.     def collapse

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


如果 你不介意音效播放 的要快一些的话
和记忆一起封存着的ID...
回复 支持 反对

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
0 小时
注册时间
2007-6-8
帖子
96
4
 楼主| 发表于 2007-7-15 20:44:18 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
0 小时
注册时间
2007-6-8
帖子
96
5
 楼主| 发表于 2007-7-15 20:49:15 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2025-9-22 07:44

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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