赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 395 |
最后登录 | 2012-3-11 |
在线时间 | 2 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 2 小时
- 注册时间
- 2011-9-25
- 帖子
- 5
|
就是在地图上显示伤害,没什么特别。
事实上有些偷懒,伤害的相关部分完全是从XP拷贝的。
教学正文:
在事件里输入脚本:
get_character(事件编号).damage = 伤害数值
get_character(事件编号).critical = true
get_character(事件编号).damage_pop = true
事件编号就是地图上的事件编号,0为本事件,-1为角色,其他则为编号。
伤害数值为负数就是恢复的效果,伤害数值也可以为字符,不一定是数字。
如果不需要CRITICAL的伤害,彩色那行脚本不用写。
class Game_Character
attr_accessor :damage
attr_accessor :damage_pop
attr_accessor :critical
alias new_initialize initialize
def initialize
new_initialize
@damage = 0
@damage_pop = false
@critical = false
end
end
class Sprite_Character < Sprite_Base
def initialize(viewport, character = nil)
super(viewport)
@character = character
@balloon_duration = 0
@_damage_duration = 0
@damage_x = 0
@damage_y = 0
update
end
alias new_update update
def update
new_update
update_damage
if @character.damage_pop == true
start_damage(@character.damage,@character.critical)
@character.damage_pop = false
@character.critical = false
end
end
def start_damage(value, critical)
dispose_damage
if value.is_a?(Numeric)
damage_string = value.abs.to_s
else
damage_string = value.to_s
end
bitmap = Bitmap.new(160, 48)
bitmap.font.name = "Arial Black"
bitmap.font.size = 28
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
bitmap.font.color.set(176, 255, 144)
else
bitmap.font.color.set(255, 255, 255)
end
bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
if critical
bitmap.font.size = 20
bitmap.font.color.set(0, 0, 0)
bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
bitmap.font.color.set(255, 255, 255)
bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
end
@_damage_sprite = ::Sprite.new(self.viewport)
@_damage_sprite.bitmap = bitmap
@_damage_sprite.ox = 80
@_damage_sprite.oy = 20
@_damage_sprite.x = self.x
@_damage_sprite.y = self.y - self.oy
@_damage_sprite.z = 3000
@_damage_duration = 40
@damage_x = @character.screen_x
@damage_y = @character.screen_y
update_damage
end
def update_damage
if @_damage_duration > 0
@damage_sprite.x += (@character.screen_x - @damage_x)
@damage_sprite.y += (@character.screen_y - @damage_y)
@damage_x = @character.screen_x
@damage_y = @character.screen_y
@_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
end
def dispose_damage
if @_damage_sprite != nil
@_damage_sprite.bitmap.dispose
@_damage_sprite.dispose
@_damage_sprite = nil
@_damage_duration = 0
end
end
end
可能有些人认为XP默认的不好看,想要用图片显示,所以这里也做了准备。
图片素材(注:图片请放入picture的文件夹底下):
class Game_Character
attr_accessor :damage
attr_accessor :damage_pop
attr_accessor :critical
alias new_initialize initialize
def initialize
new_initialize
@damage = 0
@damage_pop = false
@critical = false
end
end
class Sprite_Character < Sprite_Base
def initialize(viewport, character = nil)
super(viewport)
@character = character
@balloon_duration = 0
@_damage_duration = 0
@damage_x = 0
@damage_y = 0
update
end
alias new_update update
def update
new_update
update_damage
if @character.damage_pop == true
start_damage(@character.damage,@character.critical)
@character.damage_pop = false
@character.critical = false
end
end
def start_damage(value, critical)
dispose_damage
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 = "Arial Black"
bitmap.font.size = 28
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, Cache.picture("Damage"),
Rect.new(number * 18, rect_y, 18, 32))
damage_x += 18
end
else
unless value == "Miss"
bitmap.font.color.set(0, 0, 0)
bitmap.draw_text(-1, 27, 162, 36, damage_string, 1)
bitmap.draw_text(+1, 27, 162, 36, damage_string, 1)
bitmap.draw_text(-1, 29, 162, 36, damage_string, 1)
bitmap.draw_text(+1, 29, 162, 36, damage_string, 1)
bitmap.font.color.set(255, 255, 255)
bitmap.draw_text(0, 28, 162, 36, damage_string, 1)
else
bitmap.blt(36, 28, Cache.picture("Damage"), Rect.new(90, 64, 90, 32))
end
end
if critical
bitmap.blt(36, 0, 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 * 3 / 2
@_damage_sprite.z = 3000
@_damage_duration = 40
@damage_x = @character.screen_x
@damage_y = @character.screen_y
update_damage
end
def update_damage
if @_damage_duration > 0
@damage_sprite.x += (@character.screen_x - @damage_x)
@damage_sprite.y += (@character.screen_y - @damage_y)
@damage_x = @character.screen_x
@damage_y = @character.screen_y
@_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
end
def dispose_damage
if @_damage_sprite != nil
@_damage_sprite.bitmap.dispose
@_damage_sprite.dispose
@_damage_sprite = nil
@_damage_duration = 0
end
end
end
|
|