赞 | 0 |
VIP | 6 |
好人卡 | 6 |
积分 | 0 |
经验 | 12076 |
最后登录 | 2017-1-29 |
在线时间 | 83 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 49
- 在线时间
- 83 小时
- 注册时间
- 2008-4-19
- 帖子
- 420
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
这是第二次DEBUG了...
修正了一些问题
适用人群:ARPG制作者
- #--------------------------------------------------
- # 此脚本来自www.66RPG.com,使用请保留此信息
- #--------------------------------------------------
- module RPG
- class Sprite < ::Sprite
- @@_animations = []
- @@_reference_count = {}
- def initialize(viewport = nil)
- super(viewport)
- @_whiten_duration = 0
- @_appear_duration = 0
- @_escape_duration = 0
- @_collapse_duration = 0
- @_damage_duration = 0
- @_damage = []
- @_animation_duration = 0
- @_blink = false
- @_animation = []
- #========================
- @battler_damage = nil
- @battler_critical = nil
- @all_quanzhong = 1
- @p_dam = 0
- @hits = 0
- #========================
- end
-
- def damage(value, critical)
- #dispose_hit
- if value.is_a?(Numeric)
- 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
- bitmap.font.color.set(0, 0, 0)
- #bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
- #bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
- #bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
- #bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
- if value.is_a?(Numeric) #and value < 0
- 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.system("Damage"),
- Rect.new(number * 18, rect_y, 18, 32))
- # 后移一位
- damage_x += 18
- end
- else
- if value != "miss"
- # 系统默认描画字符串
- bitmap.font.color.set(0, 0, 0)
- bitmap.draw_text(-1-30, 27, 162, 36, damage_string, 1)
- # Miss 的情况下
- else
- # 显示未击中图画
- bitmap.blt(36, 28, RPG::Cache.system("Damage"), Rect.new(90, 64, 90, 32))
- end
- end
- if critical
- bitmap.blt(36, 0, RPG::Cache.system("Damage"), Rect.new(0, 64, 90, 32))
- end
- @_damage_duration = 40
- num = @_damage.size
- @_damage.push([::Sprite.new,40,0, rand(50) - 15, rand(30)])
- @_damage[num][0].bitmap = bitmap
- @_damage[num][0].ox = 80 + self.viewport.ox
- @_damage[num][0].oy = 20 + self.viewport.oy
- if self.character.is_a?(Game_Actor)
- @_damage[num][0].x = self.x
- @_damage[num][0].y = self.y - self.oy / 2
- else
- @_damage[num][0].x = self.x + self.viewport.rect.x -
- self.ox + self.src_rect.width / 2
- @_damage[num][0].y = self.y - self.oy * self.zoom_y / 2 +
- self.viewport.rect.y
- @_damage[num][0].zoom_x = self.zoom_x
- @_damage[num][0].zoom_y = self.zoom_y
- @_damage[num][0].z = 3000
- end
- if value.is_a?(Numeric) and value > 0 and self.character.is_a?(Game_Event)
- dispose_hit
- @hits += 1
- hit
- $game_system.hits += 1
- end
- end
- #=======================================
- # 修改:HIT数字计算
- #=======================================
- def hit
- #dispose_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
- # 循环伤害值字符串
- for char in hits_array
- number = char.to_i
- # 显示伤害数字
- bitmap.blt(hits_x, 0, RPG::Cache.system("Number"),
- Rect.new(number * 36.2, rect_y, 36.2, 50))
- # 后移一位
- hits_x += 36.2
- end
- bitmap.blt(hits_x, 0, RPG::Cache.system("HITS"), Rect.new(0, -21, 90, 50))
- # 伤害值定位
- @_hits_sprite = ::Sprite.new(self.viewport)
- @_hits_sprite.bitmap = bitmap
- @_hits_sprite.ox = 81
- @_hits_sprite.oy = 20
- @_hits_sprite.x = 450
- @_hits_sprite.y = 200
- @_hits_sprite.z = 3000
- @_hits_duration = 40
- end
-
- def animation(animation, hit, battler_damage="", battler_critical=false)
- return if animation == nil
- #=======================================
- # 修改:记录伤害和critical,以及防止拖死..
- #=======================================
- dispose_animation(false)
- num = @_animation.size
- @_animation.push([animation, hit, animation.frame_max, []])
- @battler_damage = battler_damage
- @battler_critical = battler_critical
- #return if @_animation == []
- bitmap = RPG::Cache.animation(animation.animation_name, animation.animation_hue)
- anime = @_animation.index([animation, hit, animation.frame_max, []])
- #=======================================
- # 修改:计算总闪光权限值
- #=======================================
- for timing in @_animation[anime][0].timings
- quanzhong = animation_process_timing(timing, @_animation[num][1], 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
- 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(clearing = true)
- #=======================================
- # 修改:清除记录的伤害,清除权重记录
- #=======================================
- @battler_damage = ""
- @battler_critical = nil
- @all_quanzhong = 1
- @_last_frame = -1
- #=======================================
- if clearing
- 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
- end
-
- #=======================================
- # 清除hit数
- #=======================================
- def dispose_hit(tz = false)
- @hits = 0 if tz
- if @_hits_sprite != nil
- @_hits_sprite.bitmap.dispose
- @_hits_sprite.dispose
- @_hits_sprite = 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
- for damage in @_damage
- if damage[1] > 0
- damage[1] -= 1
- damage[4] -= 3
- damage[2] -= damage[4]
- if self.character.is_a?(Game_Actor)
- damage[0].x = self.x + self.viewport.rect.x
- damage[0].y -= 3
- else
- damage[0].x = self.x + self.viewport.rect.x
- damage[0].y -= 3
- damage[0].zoom_x = self.zoom_x
- damage[0].zoom_y = self.zoom_y
- end
- damage[0].z = 2960 + damage[1]
- damage[0].opacity = 256 - (12 - damage[1]) * 32
- end
- if damage[1] == 0
- damage[0].bitmap.dispose
- damage[0].dispose
- @_damage.delete(damage)
- end
- end
- if @_damage == [] and Graphics.frame_count % 40 == 0
- dispose_hit(true)
- 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
- #=======================================
- # 修改:弹出伤害,权重计算
- #=======================================
- t = 1.0 * animation_process_timing(timing, anime[1],true)
- #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
- # 闪光为最后一次的情况下,改变这次伤害的计算方法
- if frame_index == @_last_frame
- t = @battler_damage - @p_dam
- end
- # 最后一次闪光的话,伤害修正, 已经发生的伤害归0, 连击次数归0★
- if frame_index == @_last_frame
- @p_dam = 0
- #@hits = 0
- end
- damage(t,@battler_critical)
- elsif !@battler_damage.is_a?(Numeric) and timing.flash_scope != 0
- damage(@battler_damage,@battler_critical)
- end
- 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_process_timing(timing, hit, rt = false)
- if (timing.condition == 0) or
- (timing.condition == 1 and hit == true) or
- (timing.condition == 2 and hit == false)
- if timing.se.name != ""
- se = timing.se
- Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
- end
- case timing.flash_scope
- when 1
- self.flash(timing.flash_color, timing.flash_duration * 2)
- @flash_shake_switch = true
- @flash_shake = 10
- return timing.flash_color.alpha * timing.flash_duration if rt
- when 2
- if self.viewport != nil
- self.viewport.flash(timing.flash_color, timing.flash_duration * 2)
- return timing.flash_color.alpha * timing.flash_duration if rt
- end
- when 3
- self.flash(nil, timing.flash_duration * 2)
- return timing.flash_color.alpha * timing.flash_duration if rt
- end
- end
- return 0
- 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_system.arpg_ing and self.character.is_a?(Game_Event)
- 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.character.is_a?(Game_Event)
- 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
复制代码 |
|