Project1

标题: 这个脚本怎么在血条上显示HP/SP数值? [打印本页]

作者: 露璐    时间: 2011-4-9 14:05
标题: 这个脚本怎么在血条上显示HP/SP数值?
#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================

#==============================================================================
# ■ Window_Help
#------------------------------------------------------------------------------
# 重新定义的内容,可以显示敌人的HP\MP百分比
# 你可以改脚本的开头部分定义生命、精神描述词。只和敌人描述有关,可随意修改
#==============================================================================

class Window_Help < Window_Base
  def set_enemy(actor)  
    #--------------------------------------------------------------------
    # 在这里修改描述文字,比如@生命描述词="敌人生命"
    #--------------------------------------------------------------------
   
    @生命描述词 = $data_system.words.hp
    @精神描述词 = $data_system.words.sp
   
    #--------------------------------------------------------------------
    #--------------------------------------------------------------------
    self.contents.clear
    draw_actor_name(actor, 4, 0)
    draw_actor_state(actor, 140, 0)
    carol3_draw_hp_bar(actor, 284, 12)
    carol3_draw_sp_bar(actor, 460, 12)
    @text = nil
    self.visible = true
  end
  def carol3_draw_hp_bar(actor, x, y, width = 128, height = 14) #宽度可调
    w = width * actor.hp / [actor.maxhp,1].max
    hp_color_1 = Color.new(255, 0, 0, 192)
    hp_color_2 = Color.new(255, 255, 0, 192)
    self.contents.fill_rect(x+8, y+4, width, (height/4).floor, Color.new(0, 0, 0, 128))
    draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
    x -= 1
    y += (height/4).floor
    self.contents.fill_rect(x+8, y+4, width, (height/4).ceil , Color.new(0, 0, 0, 128))
    draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
    x -= 1
    y += (height/4).ceil
    self.contents.fill_rect(x+8, y+4, width, (height/4).ceil , Color.new(0, 0, 0, 128))
    draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
    x -= 1
    y += (height/4).ceil
    self.contents.fill_rect(x+8, y+4, width, (height/4).floor, Color.new(0, 0, 0, 128))
    draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
    self.contents.font.color = Color.new(0,0,0,255)
    self.contents.draw_text(x+2,-3,128,32,@生命描述词,1)
    self.contents.font.color = Color.new(255,255,255,255)
    self.contents.draw_text(x,-4,128,32,@生命描述词,1)
  end
  def carol3_draw_sp_bar(actor, x, y, width = 128, height=14)
    w = width * actor.sp / [actor.maxsp,1].max
    hp_color_1 = Color.new( 0, 0, 255, 192)
    hp_color_2 = Color.new( 0, 255, 255, 192)
    self.contents.fill_rect(x+8, y+4, width, (height/4).floor, Color.new(0, 0, 0, 128))
    draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
    x -= 1
    y += (height/4).floor
    self.contents.fill_rect(x+8, y+4, width, (height/4).ceil , Color.new(0, 0, 0, 128))
    draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
    x -= 1
    y += (height/4).ceil
    self.contents.fill_rect(x+8, y+4, width, (height/4).ceil , Color.new(0, 0, 0, 128))
    draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
    x -= 1
    y += (height/4).ceil
    self.contents.fill_rect(x+8, y+4, width, (height/4).floor, Color.new(0, 0, 0, 128))
    draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
    self.contents.font.color = Color.new(0,0,0,255)
    self.contents.draw_text(x+2,-3,128,32,@精神描述词,1)
    self.contents.font.color = Color.new(255,255,255,255)
    self.contents.draw_text(x,-4,128,32,@精神描述词,1)
  end
  #--------------------------------------------------------------------------
  # ● ライン描画 by 桜雅 在土
  #--------------------------------------------------------------------------
  def draw_line(start_x, start_y, end_x, end_y, start_color, width = 1, end_color = start_color)
    # 描写距離の計算。大きめに直角時の長さ。
    distance = (start_x - end_x).abs + (start_y - end_y).abs
    # 描写開始
    if end_color == start_color
      for i in 1..distance
        x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
        y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
        if width == 1
          self.contents.set_pixel(x, y, start_color)
        else
          self.contents.fill_rect(x, y, width, width, start_color)
        end
      end
    else
      for i in 1..distance
        x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
        y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
        r = start_color.red * (distance-i)/distance + end_color.red * i/distance
        g = start_color.green * (distance-i)/distance + end_color.green * i/distance
        b = start_color.blue * (distance-i)/distance + end_color.blue * i/distance
        a = start_color.alpha * (distance-i)/distance + end_color.alpha * i/distance
        if width == 1
          self.contents.set_pixel(x, y, Color.new(r, g, b, a))
        else
          self.contents.fill_rect(x, y, width, width, Color.new(r, g, b, a))
        end
      end
    end
  end
end

#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================
可能我说的不太清楚,总之就是显示条的同时也显示数值


作者: 烁灵    时间: 2011-4-9 14:18
本帖最后由 烁灵 于 2011-4-9 14:18 编辑

回复 露璐 的帖子
  1. carol3_draw_hp_bar(actor, 284, 12)
  2.     carol3_draw_sp_bar(actor, 460, 12)
复制代码
添上两句变成
  1.   carol3_draw_hp_bar(actor, 284, 12)
  2.   draw_actor_hp(actor, 284, 10)
  3.   carol3_draw_sp_bar(actor, 460, 12)  
  4.   draw_actor_sp(actor, 460, 10)
复制代码
就好。里边坐标可能要改一下
作者: 露璐    时间: 2011-4-9 19:40
回复 烁灵 的帖子

报错……


作者: 烁灵    时间: 2011-4-9 21:02
回复 露璐 的帖子

draw_actor_hp\sp分别改成
draw_actor_hp_withoutName
draw_actor_sp_withoutName

然后在end前加上这个
  1.   #--------------------------------------------------------------------------
  2.   # ● 描绘 HP
  3.   #     actor : 角色
  4.   #     x     : 描画目标 X 坐标
  5.   #     y     : 描画目标 Y 坐标
  6.   #     width : 描画目标的宽
  7.   #--------------------------------------------------------------------------
  8.   def draw_actor_hp_withoutName(actor, x, y, width = 144)
  9.     # 计算描绘 MaxHP 所需的空间
  10.     if width - 32 >= 108
  11.       hp_x = x + width - 108
  12.       flag = true
  13.     elsif width - 32 >= 48
  14.       hp_x = x + width - 48
  15.       flag = false
  16.     end
  17.     # 描绘 HP
  18.     self.contents.font.color = actor.hp == 0 ? knockout_color :
  19.       actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
  20.     self.contents.draw_text(hp_x, y, 48, 32, actor.hp.to_s, 2)
  21.     # 描绘 MaxHP
  22.     if flag
  23.       self.contents.font.color = normal_color
  24.       self.contents.draw_text(hp_x + 48, y, 12, 32, "/", 1)
  25.       self.contents.draw_text(hp_x + 60, y, 48, 32, actor.maxhp.to_s)
  26.     end
  27.   end
  28.   #--------------------------------------------------------------------------
  29.   # ● 描绘 SP
  30.   #     actor : 角色
  31.   #     x     : 描画目标 X 坐标
  32.   #     y     : 描画目标 Y 坐标
  33.   #     width : 描画目标的宽
  34.   #--------------------------------------------------------------------------
  35.   def draw_actor_sp_withoutName(actor, x, y, width = 144)
  36.     # 计算描绘 MaxSP 所需的空间
  37.     if width - 32 >= 108
  38.       sp_x = x + width - 108
  39.       flag = true
  40.     elsif width - 32 >= 48
  41.       sp_x = x + width - 48
  42.       flag = false
  43.     end
  44.     # 描绘 SP
  45.     self.contents.font.color = actor.sp == 0 ? knockout_color :
  46.       actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
  47.     self.contents.draw_text(sp_x, y, 48, 32, actor.sp.to_s, 2)
  48.     # 描绘 MaxSP
  49.     if flag
  50.       self.contents.font.color = normal_color
  51.       self.contents.draw_text(sp_x + 48, y, 12, 32, "/", 1)
  52.       self.contents.draw_text(sp_x + 60, y, 48, 32, actor.maxsp.to_s)
  53.     end
  54.   end
复制代码
咱只是简单的去掉了"hp"\"sp"的描绘,应该看的懂吧




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