赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 14508 |
最后登录 | 2013-2-18 |
在线时间 | 4 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 4 小时
- 注册时间
- 2008-8-20
- 帖子
- 159
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
- module RPG
- #--------------------------------------------------------------------------
- # ● 常量设定
- #--------------------------------------------------------------------------
- # 是否显示总伤害
- SHOW_TOTAL_DAMAGE = true
- # 角色受攻击时是否跳一下
- BATTLER_JUMP = false
- # 连续伤害的动画ID
- SLIP_DAMAGE_ANIMATION_ID = 0
-
- class Sprite < ::Sprite
- #==========================================
- # 修改说明:
- # @flash_shake用来制作挨打时候跳跃
- # @_damage 用来记录每次打击之后弹出数字
- # @_total_damage 记录总伤害
- # @_total_damage_duration 总伤害持续帧
- #==========================================
- def initialize(viewport = nil)
- #66RPG_rainbow_initialize(viewport)
- super(viewport)
- @_whiten_duration = 0
- @_appear_duration = 0
- @_escape_duration = 0
- @_collapse_duration = 0
- @_damage_duration = 0
- @_animation_duration = 0
- @_blink = false
- # 挨打时候跳跃
- @flash_shake = 0
- # 伤害记录数组
- @_damage = []
- # 总伤害数字
- @_total_damage = 0
- # 总伤害持续帧
- @_total_damage_duration = 0
- #记录已经发生的伤害的变量★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
- @p_dam=0
- @hits=0
- end
- #美化的伤害处理★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
- def damage(value, critical)
- #清除hit数
- dispose_hit
- if value.is_a?(Numeric)
- i=$dx+1
- if value!=0
- value=(value*i+rand(i)).to_i
- else
- value=value.to_i
- end
- damage_string = value.abs.to_s
- else
- # 转为字符串
- damage_string = value.to_s
- end
- # 初始化位图
- bitmap = Bitmap.new(162, 64)
- bitmap.font.name = ["黑体","华文行楷", "宋体"]
- bitmap.font.size = 32
- if value==0
- bitmap.blt(36, 28, RPG::Cache.picture("Damage"), Rect.new(90, 64, 90, 32))
- else
- if value.is_a?(Numeric)
- # 分割伤害值字符串
- damage_array = damage_string.scan(/./)
- damage_x = 81 - damage_string.size * 9
- # 伤害值为负的情况下
- if value < 0
- # 调用回复数字表
- rect_y = 32
- else
- # 调用伤害数字表
- rect_y = 0
- end
- # 循环伤害值字符串
- for char in damage_array
- number = char.to_i
- # 显示未击中图画
- bitmap.blt(damage_x, 32,RPG::Cache.picture("Damage") , Rect.new(number * 18, rect_y, 18, 32))
- # 后移一位
- damage_x += 18
- end
- end
- end
- # 会心一击标志打开的情况
- if critical
- # 显示会心一击图画
- bitmap.blt(36, 0, RPG::Cache.picture("Damage"), Rect.new(0, 64, 90, 32))
- end
- # 伤害值定位
- @_damage_sprite = ::Sprite.new(self.viewport)
- @_damage_sprite.bitmap = bitmap
- @_damage_sprite.ox = 81
- @_damage_sprite.oy = 20
- @_damage_sprite.x = self.x
- @_damage_sprite.y = self.y - self.oy / 2
- @_damage_sprite.z = 3000
- @_damage_duration = 40
- @_damage.push([@_damage_sprite,@_damage_duration-10,0, rand(30) - 15, rand(3)])
- make_total_damage(value)
- end
- # ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
- # hit数的美化描绘
- def hit
- # 如果伤害值是数值
- # 转为字符串
- value=@hits
- hits_string = value.to_s
- # 初始化位图
- bitmap = Bitmap.new(320, 64)
- bitmap.font.name = "Arial Black"
- bitmap.font.size = 32
- # 分割伤害值字符串
- hits_array = hits_string.scan(/./)
- hits_x = 81 - hits_string.size * 18.1
- rect_y = 0
- # 伤害值定位
- @_hits_sprite = ::Sprite.new(self.viewport)
- @_hits_sprite.bitmap = bitmap
- @_hits_sprite.ox = 81
- @_hits_sprite.oy = 20
- @_hits_sprite.x = 300
- @_hits_sprite.y = 20
- @_hits_sprite.z = 3000
- @_hits_duration = 40
- end
- #--------------------------------------------------------------------------
- # ● 总伤害处理
- #--------------------------------------------------------------------------
- def make_total_damage(value)
- if value.is_a?(Numeric) and SHOW_TOTAL_DAMAGE
- @_total_damage += value
- # 绝对值转为字符串
- damage_string = @_total_damage.abs.to_s
- else
- return
- end
- # 初始化位图
- bitmap = Bitmap.new(300, 150)
- bitmap.font.name = "Arial Black"
- bitmap.font.size = 32
- if @_total_damage_sprite.nil?
- @_total_damage_sprite = ::Sprite.new(self.viewport)
- @_total_damage_sprite.ox = 80
- @_total_damage_sprite.oy = 20
- @_total_damage_sprite.z = 3000
- end
- @_total_damage_sprite.bitmap = bitmap
- @_total_damage_sprite.zoom_x = 0.8
- @_total_damage_sprite.zoom_y = 0.8
- @_total_damage_sprite.x = self.x
- @_total_damage_sprite.y = self.y - self.oy / 2 - 64
- @_total_damage_sprite.z = 3001
- @_total_damage_duration = 80
- #hit数描绘
- @hits+=1
- if @_total_damage > 0
- hit
- end
- end
- def animation(animation, hit, battler_damage="", battler_critical=false)
- dispose_animation
- #=======================================
- # 修改:记录伤害和critical
- #=======================================
- @battler_damage = battler_damage
- @battler_critical = battler_critical
- @_animation = animation
- return if @_animation == nil
- @_animation_hit = hit
- @_animation_duration = @_animation.frame_max
- animation_name = @_animation.animation_name
- animation_hue = @_animation.animation_hue
- bitmap = RPG::Cache.animation(animation_name, animation_hue)
- #=======================================
- # 修改:计算总闪光权限值
- #=======================================
- for timing in @_animation.timings
- quanzhong = animation_process_timing(timing, @_animation_hit,true)
- @all_quanzhong += quanzhong
- # 记录最后一次闪光
- @_last_frame = timing.frame if quanzhong != 0
- end
- if @@_reference_count.include?(bitmap)
- @@_reference_count[bitmap] += 1
- else
- @@_reference_count[bitmap] = 1
- end
- @_animation_sprites = []
- if @_animation.position != 3 or not @@_animations.include?(animation)
- for i in 0..15
- sprite = ::Sprite.new(self.viewport)
- sprite.bitmap = bitmap
- sprite.visible = false
- @_animation_sprites.push(sprite)
- end
- unless @@_animations.include?(animation)
- @@_animations.push(animation)
- end
- end
- update_animation
- end
- #=======================================
- # 修改:更换清除伤害的算法,以防万一
- # 本内容在脚本中没有使用过
- #=======================================
- def dispose_damage
- for damage in @_damage.reverse
- damage[0].bitmap.dispose
- damage[0].dispose
- @_damage.delete(damage)
- end
- @_total_damage = 0
- @_last_frame = -1
- if @_total_damage_sprite != nil
- @_total_damage_duration = 0
- @_total_damage_sprite.bitmap.dispose
- @_total_damage_sprite.dispose
- @_total_damage_sprite = nil
- end
- end
- #=======================================
- # 清除hit数★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
- #=======================================
- def dispose_hit
- if @_hits_sprite != nil
- @_hits_sprite.bitmap.dispose
- @_hits_sprite.dispose
- @_hits_sprite = nil
- end
- end
- def dispose_animation
- #=======================================
- # 修改:清除记录的伤害,清除权重记录
- #=======================================
- @battler_damage = nil
- @battler_critical = nil
- @all_quanzhong = 1
- @_total_damage = 0
- @_last_frame = -1
- if @_animation_sprites != nil
- sprite = @_animation_sprites[0]
- if sprite != nil
- @@_reference_count[sprite.bitmap] -= 1
- if @@_reference_count[sprite.bitmap] == 0
- sprite.bitmap.dispose
- end
- end
- for sprite in @_animation_sprites
- sprite.dispose
- end
- @_animation_sprites = nil
- @_animation = nil
- end
- end
- def update
- super
- if @_whiten_duration > 0
- @_whiten_duration -= 1
- self.color.alpha = 128 - (16 - @_whiten_duration) * 10
- end
- if @_appear_duration > 0
- @_appear_duration -= 1
- self.opacity = (16 - @_appear_duration) * 16
- end
- if @_escape_duration > 0
- @_escape_duration -= 1
- self.opacity = 256 - (32 - @_escape_duration) * 10
- end
- if @_collapse_duration > 0
- @_collapse_duration -= 1
- self.opacity = 256 - (48 - @_collapse_duration) * 6
- end
- #=======================================
- # 修改:更新算法,更新弹出
- #=======================================
- if @_damage_duration > 0
- @_damage_duration -= 1
- for damage in @_damage
- damage[0].x = self.x
- damage[0].y -= 3
- damage[0].opacity = damage[1]*20
- damage[1] -= 1
- if damage[1]==0
- damage[0].bitmap.dispose
- damage[0].dispose
- @_damage.delete(damage)
- next
- end
- end
- end
- #=======================================
- # 添加:弹出总伤害
- #=======================================
- if @_total_damage_duration > 0
- @_total_damage_duration -= 1
- @_total_damage_sprite.y -= 1 if @_total_damage_duration % 2 == 0
- if @_total_damage_sprite.zoom_x > 1.0
- @_total_damage_sprite.zoom_x -= 0.05
- end
- if @_total_damage_sprite.zoom_y > 1.0
- @_total_damage_sprite.zoom_y -= 0.05
- end
- @_total_damage_sprite.opacity = 256 - (24 - @_total_damage_duration) * 16
- if @_total_damage_duration <= 0
- dispose_hit#★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
- @_total_damage = 0
- @_total_damage_duration = 0
- @_total_damage_sprite.bitmap.dispose
- @_total_damage_sprite.dispose
- @_total_damage_sprite = nil
- end
- end
- #=======================================
- if @_animation != nil and (Graphics.frame_count % 2 == 0)
- @_animation_duration -= 1
- update_animation
- end
- if @_loop_animation != nil and (Graphics.frame_count % 2 == 0)
- update_loop_animation
- @_loop_animation_index += 1
- @_loop_animation_index %= @_loop_animation.frame_max
- end
- if @_blink
- @_blink_count = (@_blink_count + 1) % 32
- if @_blink_count < 16
- alpha = (16 - @_blink_count) * 6
- else
- alpha = (@_blink_count - 16) * 6
- end
- self.color.set(255, 255, 255, alpha)
- end
- @@_animations.clear
- end
- def update_animation
- if @_animation_duration > 0
- frame_index = @_animation.frame_max - @_animation_duration
- cell_data = @_animation.frames[frame_index].cell_data
- position = @_animation.position
- animation_set_sprites(@_animation_sprites, cell_data, position)
- #=======================================
- # 修改:弹出伤害,权重计算
- #=======================================
- for timing in @_animation.timings
- if timing.frame == frame_index
- t = 1.0 * animation_process_timing(timing, @_animation_hit)
- if timing.se.name != ""
- se=timing.se
- Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
- end
- #p t,"当前权重", @all_quanzhong,"总权重"
- if @battler_damage.is_a?(Numeric) and t != 0
- t *= @battler_damage
- t /= @all_quanzhong
- t = t.to_i
- #在闪光不是最后一次的情况下,把这次伤害加入到已经发生的伤害中★★★★★★★★★★★★★★★★★★★★★★★★★★
- if frame_index != @_last_frame
- @p_dam+= t
- end
- #p @p_dam,"已发生伤害",@battler_damage,"总伤害"(调试用)★★★★★★★★★★★★★★★★★★★★★★★★★★
- #闪光为最后一次的情况下,改变这次伤害的计算方法(总伤害-已经发生伤害)★★★★★★★★★★★★★★★★★★★★★★★★★★
- if frame_index == @_last_frame
- t=@battler_damage-@p_dam
- end
- #p t,"当前伤害",@battler_damage,"总伤害"
- # 最后一次闪光的话,伤害修正
- if frame_index == @_last_frame
- @_total_damage = @battler_damage - t
- @p_dam=0 #已经发生的伤害归0★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
- end
- #p t,@battler_damage,@all_quanzhong
- damage(t,@battler_critical)
- #连击次数归0★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
- if frame_index == @_last_frame
- @hits=0
- end
- # 防止重复播放miss
- elsif !@battler_damage.is_a?(Numeric) and timing.flash_scope != 0
- damage(@battler_damage,@battler_critical)
- end
- end
- end
- else
- dispose_animation
- end
- end
- #=======================================
- # 修改:敌人跳跃的功能 + 添加返回数值
- #=======================================
- def animation_process_timing(timing, hit,dontflash=false)
- if (timing.condition == 0) or
- (timing.condition == 1 and hit == true) or
- (timing.condition == 2 and hit == false)
- case timing.flash_scope
- when 1
- unless dontflash
- self.flash(timing.flash_color, timing.flash_duration * 2)
- if @_total_damage >0
- @flash_shake_switch = true
- @flash_shake = 10
- end
- end
- return timing.flash_color.alpha * timing.flash_duration
- when 2
- unless dontflash
- if self.viewport != nil
- self.viewport.flash(timing.flash_color, timing.flash_duration * 2)
- end
- end
- return timing.flash_color.alpha * timing.flash_duration
- when 3
- unless dontflash
- self.flash(nil, timing.flash_duration * 2)
- end
- return timing.flash_color.alpha * timing.flash_duration
- end
- end
- return 0
- end
- end
- end
复制代码- #--------------------------------------------------
- # 此脚本来自www.66RPG.com,使用请保留此信息
- #--------------------------------------------------
- module RPG
- class Sprite < ::Sprite
- def initialize(viewport = nil)
- super(viewport)
- @_whiten_duration = 0
- @_appear_duration = 0
- @_escape_duration = 0
- @_collapse_duration = 0
- @_damage_duration = 0
- @_animation_duration = 0
- @_blink = false
- @_animation = []
- end
- def animation(animation, hit)
- return if animation == nil
- num = @_animation.size
- @_animation.push([animation, hit, animation.frame_max, []])
- bitmap = RPG::Cache.animation(animation.animation_name,
- animation.animation_hue)
- if @@_reference_count.include?(bitmap)
- @@_reference_count[bitmap] += 1
- else
- @@_reference_count[bitmap] = 1
- end
- if @_animation[num][0] != 3 or not @@_animations.include?(animation)
- for i in 0..15
- sprite = ::Sprite.new
- sprite.bitmap = bitmap
- sprite.visible = false
- @_animation[num][3].push(sprite)
- end
- unless @@_animations.include?(animation)
- @@_animations.push(animation)
- end
- end
- update_animation(@_animation[num])
- end
- def loop_animation(animation)
- return if animation == @_loop_animation
- dispose_loop_animation
- @_loop_animation = animation
- return if @_loop_animation == nil
- @_loop_animation_index = 0
- animation_name = @_loop_animation.animation_name
- animation_hue = @_loop_animation.animation_hue
- bitmap = RPG::Cache.animation(animation_name, animation_hue)
- if @@_reference_count.include?(bitmap)
- @@_reference_count[bitmap] += 1
- else
- @@_reference_count[bitmap] = 1
- end
- @_loop_animation_sprites = []
- for i in 0..15
- sprite = ::Sprite.new
- sprite.bitmap = bitmap
- sprite.visible = false
- @_loop_animation_sprites.push(sprite)
- end
- # update_loop_animation
- end
- def dispose_animation
- for anime in @_animation.reverse
- sprite = anime[3][0]
- if sprite != nil
- @@_reference_count[sprite.bitmap] -= 1
- if @@_reference_count[sprite.bitmap] == 0
- sprite.bitmap.dispose
- end
- end
- for sprite in anime[3]
- sprite.dispose
- end
- @_animation.delete(anime)
- end
- end
-
- def update
- super
- if @_whiten_duration > 0
- @_whiten_duration -= 1
- self.color.alpha = 128 - (16 - @_whiten_duration) * 10
- end
- if @_appear_duration > 0
- @_appear_duration -= 1
- self.opacity = (16 - @_appear_duration) * 16
- end
- if @_escape_duration > 0
- @_escape_duration -= 1
- self.opacity = 256 - (32 - @_escape_duration) * 10
- end
- if @_collapse_duration > 0
- @_collapse_duration -= 1
- self.opacity = 256 - (48 - @_collapse_duration) * 6
- end
- if @_damage_duration > 0
- @_damage_duration -= 1
- case @_damage_duration
- when 38..39
- @_damage_sprite.y -= 4
- when 36..37
- @_damage_sprite.y -= 2
- when 34..35
- @_damage_sprite.y += 2
- when 28..33
- @_damage_sprite.y += 4
- end
- @_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32
- if @_damage_duration == 0
- dispose_damage
- end
- end
- for anime in @_animation
- if (Graphics.frame_count % 2 == 0)
- anime[2] -= 1
- update_animation(anime)
- end
- end
- if @_loop_animation != nil and (Graphics.frame_count % 2 == 0)
- update_loop_animation
- @_loop_animation_index += 1
- @_loop_animation_index %= @_loop_animation.frame_max
- end
- if @_blink
- @_blink_count = (@_blink_count + 1) % 32
- if @_blink_count < 16
- alpha = (16 - @_blink_count) * 6
- else
- alpha = (@_blink_count - 16) * 6
- end
- self.color.set(255, 255, 255, alpha)
- end
- @@_animations.clear
- end
-
- def update_animation(anime)
- if anime[2] > 0
- frame_index = anime[0].frame_max - anime[2]
- cell_data = anime[0].frames[frame_index].cell_data
- position = anime[0].position
- animation_set_sprites(anime[3], cell_data, position)
- for timing in anime[0].timings
- if timing.frame == frame_index
- animation_process_timing(timing, anime[1])
- end
- end
- else
- @@_reference_count[anime[3][0].bitmap] -= 1
- if @@_reference_count[anime[3][0].bitmap] == 0
- anime[3][0].bitmap.dispose
- end
- for sprite in anime[3]
- sprite.dispose
- end
- @_animation.delete(anime)
- end
- end
- def animation_set_sprites(sprites, cell_data, position)
- for i in 0..15
- sprite = sprites[i]
- pattern = cell_data[i, 0]
- if sprite == nil or pattern == nil or pattern == -1
- sprite.visible = false if sprite != nil
- next
- end
- sprite.visible = true
- sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
- if position == 3
- if self.viewport != nil
- sprite.x = self.viewport.rect.width / 2
- if $game_temp.in_battle and self.battler.is_a?(Game_Enemy)
- sprite.y = self.viewport.rect.height - 320
- else
- sprite.y = self.viewport.rect.height - 160
- end
- else
- sprite.x = 320
- sprite.y = 240
- end
- else
- sprite.x = self.x + self.viewport.rect.x -
- self.ox + self.src_rect.width / 2
- if $game_temp.in_battle and self.battler.is_a?(Game_Enemy)
- sprite.y = self.y - self.oy * self.zoom_y / 2 +
- self.viewport.rect.y
- if position == 0
- sprite.y -= self.src_rect.height * self.zoom_y / 4
- elsif position == 2
- sprite.y += self.src_rect.height * self.zoom_y / 4
- end
- else
- sprite.y = self.y + self.viewport.rect.y -
- self.oy + self.src_rect.height / 2
- sprite.y -= self.src_rect.height / 4 if position == 0
- sprite.y += self.src_rect.height / 4 if position == 2
- end
- end
- sprite.x += cell_data[i, 1]
- sprite.y += cell_data[i, 2]
- sprite.z = 2000
- sprite.ox = 96
- sprite.oy = 96
- sprite.zoom_x = cell_data[i, 3] / 100.0
- sprite.zoom_y = cell_data[i, 3] / 100.0
- if position != 3
- sprite.zoom_x *= self.zoom_x
- sprite.zoom_y *= self.zoom_y
- end
- sprite.angle = cell_data[i, 4]
- sprite.mirror = (cell_data[i, 5] == 1)
- sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
- sprite.blend_type = cell_data[i, 7]
- end
- end
- end
- end
复制代码
帮下合并两段脚本
否则两个用在一起会冲突
多谢了{/cy} |
|