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

Project1

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

[已经解决] 如何显示敌人的HP和SP(置顶贴链接已坏)

 关闭 [复制链接]

Lv1.梦旅人

梦石
0
星屑
359
在线时间
5 小时
注册时间
2011-7-12
帖子
4
跳转到指定楼层
1
发表于 2011-7-12 00:43:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
求链接……

Lv3.寻梦者

梦石
0
星屑
951
在线时间
1685 小时
注册时间
2009-7-25
帖子
534

开拓者

2
发表于 2011-7-12 09:37:51 | 只看该作者
有一个血条脚本
  1. #==============================================================================
  2. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  3. #==============================================================================
  4. # ■ エネミーHP&SP(ver 0.98)

  5. # □ カスタマイズポイント
  6. #==============================================================================
  7. module PLAN_HPSP_DRAW
  8. FONT_NAME         = ["黑体", "楷体", "宋体"]    # フォント
  9. FONT_SIZE         =  14                               # フォントサイズ
  10. FONT_BOLD         = true                              # 太字
  11. FONT_ITALIC       = true                              # 斜体

  12. DRAW_NAME         = false                             # 名前の描画
  13. DRAW_HP           = true                              # HP の描画
  14. DRAW_SP           = true                              # SP の描画

  15. DRAW_WIDTH        =  80                               # 描画幅
  16. DRAW_HEIGHT       = 3 * 32                            # 描画高さ
  17. DRAW_SPACE        =   0                               # 行間
  18. DRAW_Y            =  36                               # Y 座標修正値
  19. end


  20. #==============================================================================
  21. # ■ Sprite_Battler
  22. #==============================================================================

  23. class Sprite_Battler < RPG::Sprite
  24. #--------------------------------------------------------------------------
  25. # ● オブジェクト初期化
  26. #--------------------------------------------------------------------------
  27. alias plan_enemy_hpsp_draw_initialize initialize
  28. def initialize(viewport, battler = nil)
  29.   # 元のメソッドに戻す
  30.   plan_enemy_hpsp_draw_initialize(viewport, battler)
  31.   # エネミーの場合
  32.   if @battler.is_a?(Game_Enemy)
  33.     width = PLAN_HPSP_DRAW::DRAW_WIDTH + 32
  34.     height = PLAN_HPSP_DRAW::DRAW_HEIGHT + 32
  35.     x = @battler.screen_x - width / 2
  36.     y = @battler.screen_y - height + 32 + PLAN_HPSP_DRAW::DRAW_Y
  37.     @enemy_hpsp_window = Window_Base.new(x, y, width, height)
  38.     @enemy_hpsp_window.contents = Bitmap.new(width - 32, height - 32)
  39.     @enemy_hpsp_window.contents.font.name = PLAN_HPSP_DRAW::FONT_NAME
  40.     @enemy_hpsp_window.contents.font.size = PLAN_HPSP_DRAW::FONT_SIZE
  41.     @enemy_hpsp_window.contents.font.bold = PLAN_HPSP_DRAW::FONT_BOLD
  42.     @enemy_hpsp_window.contents.font.italic = PLAN_HPSP_DRAW::FONT_ITALIC
  43.     y = 0
  44.     @old_enemy_hpsp = []
  45.     one_line = ((PLAN_HPSP_DRAW::FONT_SIZE * 100 / 28) * 32) / 100
  46.     if PLAN_HPSP_DRAW::DRAW_NAME
  47.       @enemy_hpsp_window.draw_actor_name(@battler, 0, y, width - 32)
  48.       y += one_line + PLAN_HPSP_DRAW::DRAW_SPACE
  49.       @old_enemy_hpsp.push(@battler.name)
  50.     end
  51.     if PLAN_HPSP_DRAW::DRAW_HP
  52.       @enemy_hpsp_window.draw_actor_hp2222(@battler, 0, y, width - 32)
  53.       y += one_line + PLAN_HPSP_DRAW::DRAW_SPACE
  54.       @old_enemy_hpsp.push(@battler.hp)
  55.     end
  56.     if PLAN_HPSP_DRAW::DRAW_SP
  57.       @enemy_hpsp_window.draw_actor_sp2222(@battler, 0, y, width - 32)
  58.       @old_enemy_hpsp.push(@battler.sp)
  59.     end
  60.     @enemy_hpsp_window.opacity = 0
  61.     @enemy_hpsp_window.contents_opacity = 0
  62.     @enemy_hpsp_window.z = -2
  63.   end
  64. end
  65. #--------------------------------------------------------------------------
  66. # ● 解放
  67. #--------------------------------------------------------------------------
  68. alias plan_enemy_hpsp_draw_dispose dispose
  69. def dispose
  70.   # エネミーの場合
  71.   if @battler.is_a?(Game_Enemy)
  72.     @enemy_hpsp_window.dispose
  73.   end
  74.   # 元のメソッドに戻す
  75.   plan_enemy_hpsp_draw_dispose
  76. end
  77. #--------------------------------------------------------------------------
  78. # ● フレーム更新
  79. #--------------------------------------------------------------------------
  80. alias plan_enemy_hpsp_draw_update update
  81. def update
  82.   # 元のメソッドに戻す
  83.   plan_enemy_hpsp_draw_update
  84.   # エネミーの場合
  85.   if @battler.is_a?(Game_Enemy)
  86.     @enemy_hpsp_window.visible = @battler_visible
  87.   # スプライトの座標を設定
  88.     width = PLAN_HPSP_DRAW::DRAW_WIDTH + 32
  89.     @enemy_hpsp_window.x = self.x - width / 2
  90.     @now_enemy_hpsp = []
  91.     if PLAN_HPSP_DRAW::DRAW_NAME
  92.       @now_enemy_hpsp.push(@battler.name)
  93.     end
  94.     if PLAN_HPSP_DRAW::DRAW_HP
  95.       @now_enemy_hpsp.push(@battler.hp)
  96.     end
  97.     if PLAN_HPSP_DRAW::DRAW_SP
  98.       @now_enemy_hpsp.push(@battler.sp)
  99.     end
  100.     if @old_enemy_hpsp != @now_enemy_hpsp and $game_temp.enemy_hpsp_refresh
  101.       @old_enemy_hpsp = @now_enemy_hpsp
  102.       @enemy_hpsp_window.contents.clear
  103.       y = 0
  104.       width = PLAN_HPSP_DRAW::DRAW_WIDTH + 32
  105.       one_line = ((PLAN_HPSP_DRAW::FONT_SIZE * 100 / 28) * 32) / 100
  106.       if PLAN_HPSP_DRAW::DRAW_NAME
  107.         @enemy_hpsp_window.draw_actor_name(@battler, 0, y, width - 32)
  108.         y += one_line + PLAN_HPSP_DRAW::DRAW_SPACE
  109.       end
  110.       if PLAN_HPSP_DRAW::DRAW_HP
  111.         @enemy_hpsp_window.draw_actor_hp2222(@battler, 0, y, width - 32)
  112.         y += one_line + PLAN_HPSP_DRAW::DRAW_SPACE
  113.       end
  114.       if PLAN_HPSP_DRAW::DRAW_SP
  115.         @enemy_hpsp_window.draw_actor_sp2222(@battler, 0, y, width - 32)
  116.       end
  117.       Graphics.frame_reset
  118.     end
  119.   end
  120. end
  121. #--------------------------------------------------------------------------
  122. # ● visible の設定
  123. #--------------------------------------------------------------------------
  124. if !method_defined?("plan_enemy_hpsp_draw_visible=")
  125.   alias plan_enemy_hpsp_draw_visible= visible=
  126. end
  127. def visible=(bool)
  128.   # エネミーの場合
  129.   if @battler.is_a?(Game_Enemy)
  130.     @enemy_hpsp_window.visible = bool
  131.   end
  132.   # 元のメソッドに戻す
  133.   self.plan_enemy_hpsp_draw_visible=(bool)
  134. end
  135. #--------------------------------------------------------------------------
  136. # ● 不透明度の設定
  137. #--------------------------------------------------------------------------
  138. if !method_defined?("plan_enemy_hpsp_draw_opacity=")
  139.   alias plan_enemy_hpsp_draw_opacity= opacity=
  140. end
  141. def opacity=(n)
  142.   # 元のメソッドに戻す
  143.   self.plan_enemy_hpsp_draw_opacity=(n)
  144.   # エネミーの場合
  145.   if @battler.is_a?(Game_Enemy)
  146.     @enemy_hpsp_window.contents_opacity = n
  147.   end
  148. end

  149. end





  150. #==============================================================================
  151. # ■ Game_Temp
  152. #==============================================================================

  153. class Game_Temp
  154. #--------------------------------------------------------------------------
  155. # ● 公開インスタンス変数
  156. #--------------------------------------------------------------------------
  157. attr_accessor :enemy_hpsp_refresh
  158. #--------------------------------------------------------------------------
  159. # ● オブジェクト初期化
  160. #--------------------------------------------------------------------------
  161. alias plan_enemy_hpsp_draw_initialize initialize
  162. def initialize
  163.   # 元のメソッドに戻す
  164.   plan_enemy_hpsp_draw_initialize
  165.   @enemy_hpsp_refresh = false
  166. end
  167. end

  168. #==============================================================================
  169. # ■ Scene_Battle
  170. #==============================================================================

  171. class Scene_Battle
  172. #--------------------------------------------------------------------------
  173. # ● プレバトルフェーズ開始 (エネミー名+アルファベット用)
  174. #--------------------------------------------------------------------------
  175. alias plan_enemy_hpsp_draw_start_phase1 start_phase1
  176. def start_phase1
  177.   $game_temp.enemy_hpsp_refresh = true
  178.   # 元のメソッドに戻す
  179.   plan_enemy_hpsp_draw_start_phase1
  180. end
  181. #--------------------------------------------------------------------------
  182. # ● パーティコマンドフェーズ開始 (エネミー名+アルファベット用)
  183. #--------------------------------------------------------------------------
  184. alias plan_enemy_hpsp_draw_start_phase2 start_phase2
  185. def start_phase2
  186.   $game_temp.enemy_hpsp_refresh = false
  187.   # 元のメソッドに戻す
  188.   plan_enemy_hpsp_draw_start_phase2
  189. end
  190. #--------------------------------------------------------------------------
  191. # ● フレーム更新 (メインフェーズ ステップ 5 : ダメージ表示)
  192. #--------------------------------------------------------------------------
  193. alias plan_enemy_hpsp_draw_update_phase4_step5 update_phase4_step5
  194. def update_phase4_step5
  195.   # 元のメソッドに戻す
  196.   plan_enemy_hpsp_draw_update_phase4_step5
  197.   $game_temp.enemy_hpsp_refresh = true
  198. end
  199. #--------------------------------------------------------------------------
  200. # ● フレーム更新 (メインフェーズ ステップ 6 : リフレッシュ)
  201. #--------------------------------------------------------------------------
  202. alias plan_enemy_hpsp_draw_update_phase4_step6 update_phase4_step6
  203. def update_phase4_step6
  204.   # 元のメソッドに戻す
  205.   plan_enemy_hpsp_draw_update_phase4_step6
  206.   $game_temp.enemy_hpsp_refresh = false
  207. end
  208. end


  209. #==============================================================================
  210. # ■ Window_Base
  211. #==============================================================================

  212. class Window_Base < Window
  213. #--------------------------------------------------------------------------
  214. # ● 名前の描画
  215. #--------------------------------------------------------------------------
  216. def draw_actor_name(actor, x, y, width = 120, align = 0)
  217.   self.contents.font.color = normal_color
  218.   align = 1 if $scene.is_a?(Scene_Battle)
  219.   self.contents.draw_text(x, y, width, 32, actor.name, align)
  220. end
  221. #--------------------------------------------------------------------------
  222. # ● ステートの描画
  223. #--------------------------------------------------------------------------
  224. def draw_actor_state(actor, x, y, width = 120)
  225.   # 元のメソッドに戻す
  226.   text = make_battler_state_text(actor, width, true)
  227.   self.contents.draw_text(x, y, width, 32, text, 1)
  228. end
  229. end


  230. #==============================================================================
  231. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  232. #==============================================================================

  233. class Window_Base < Window
  234. def draw_actor_hp2222(actor, x, y, width = 100, height=8)
  235.    y+=3
  236.    olx = x
  237.    oly = y
  238.    w = width * actor.hp / [actor.maxhp,1].max
  239.    hp_color_1 = Color.new(255, 0, 0, 192)
  240.    hp_color_2 = Color.new(255, 255, 0, 192)
  241.    self.contents.fill_rect(x+8, y+4, width, (height/4).floor, Color.new(0, 0, 0, 128))
  242.    draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  243.    x -= 1
  244.    y += (height/4).floor
  245.    self.contents.fill_rect(x+8, y+4, width, (height/4).ceil , Color.new(0, 0, 0, 128))
  246.    draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  247.    x -= 1
  248.    y += (height/4).ceil
  249.    self.contents.fill_rect(x+8, y+4, width, (height/4).ceil , Color.new(0, 0, 0, 128))
  250.    draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  251.    x -= 1
  252.    y += (height/4).ceil
  253.    self.contents.fill_rect(x+8, y+4, width, (height/4).floor, Color.new(0, 0, 0, 128))
  254.    draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  255.    x = olx
  256.    y = oly-14   
  257.    # 描绘字符串 "HP"
  258.    self.contents.font.color = system_color
  259.    self.contents.draw_text(x, y, 32, 32, $data_system.words.hp)
  260.    # 计算描绘 MaxHP 所需的空间
  261.    if width - 32 >= 108
  262.      hp_x = x + width - 108
  263.      flag = true
  264.    elsif width - 32 >= 48
  265.      hp_x = x + width - 48
  266.      flag = false
  267.    end
  268.    # 描绘 HP
  269.    self.contents.font.color = actor.hp == 0 ? knockout_color :
  270.      actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
  271.    self.contents.draw_text(hp_x, y, 48, 32, actor.hp.to_s, 2)
  272.    # 描绘 MaxHP
  273.    if flag
  274.      self.contents.font.color = normal_color
  275.      self.contents.draw_text(hp_x + 48, y, 12, 32, "/", 1)
  276.      self.contents.draw_text(hp_x + 60, y, 48, 32, actor.maxhp.to_s)
  277.    end   
  278. end
  279. def draw_actor_sp2222(actor, x, y, width = 100, height = 8)
  280.    y+=3
  281.    olx = x
  282.    oly = y
  283.    w = width * actor.sp / [actor.maxsp,1].max
  284.    hp_color_1 = Color.new( 0, 0, 255, 192)
  285.    hp_color_2 = Color.new( 0, 255, 255, 192)
  286.    self.contents.fill_rect(x+8, y+4, width, (height/4).floor, Color.new(0, 0, 0, 128))
  287.    draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  288.    x -= 1
  289.    y += (height/4).floor
  290.    self.contents.fill_rect(x+8, y+4, width, (height/4).ceil , Color.new(0, 0, 0, 128))
  291.    draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  292.    x -= 1
  293.    y += (height/4).ceil
  294.    self.contents.fill_rect(x+8, y+4, width, (height/4).ceil , Color.new(0, 0, 0, 128))
  295.    draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  296.    x -= 1
  297.    y += (height/4).ceil
  298.    self.contents.fill_rect(x+8, y+4, width, (height/4).floor, Color.new(0, 0, 0, 128))
  299.    draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  300.    x = olx
  301.    y = oly-14
  302.    # 描绘字符串 "SP"
  303.    self.contents.font.color = system_color
  304.    self.contents.draw_text(x, y, 32, 32, $data_system.words.sp)
  305.    # 计算描绘 MaxSP 所需的空间
  306.    if width - 32 >= 108
  307.      sp_x = x + width - 108
  308.      flag = true
  309.    elsif width - 32 >= 48
  310.      sp_x = x + width - 48
  311.      flag = false
  312.    end
  313.    # 描绘 SP
  314.    self.contents.font.color = actor.sp == 0 ? knockout_color :
  315.      actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
  316.    self.contents.draw_text(sp_x, y, 48, 32, actor.sp.to_s, 2)
  317.    # 描绘 MaxSP
  318.    if flag
  319.      self.contents.font.color = normal_color
  320.      self.contents.draw_text(sp_x + 48, y, 12, 32, "/", 1)
  321.      self.contents.draw_text(sp_x + 60, y, 48, 32, actor.maxsp.to_s)
  322.    end   
  323. end
  324. #--------------------------------------------------------------------------
  325. # ● ライン描画 by 桜雅 在土
  326. #--------------------------------------------------------------------------
  327. def draw_line(start_x, start_y, end_x, end_y, start_color, width = 1, end_color = start_color)
  328.    # 描写距離の計算。大きめに直角時の長さ。
  329.    distance = (start_x - end_x).abs + (start_y - end_y).abs
  330.    # 描写開始
  331.    if end_color == start_color
  332.      for i in 1..distance
  333.        x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
  334.        y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
  335.        if width == 1
  336.          self.contents.set_pixel(x, y, start_color)
  337.        else
  338.          self.contents.fill_rect(x, y, width, width, start_color)
  339.        end
  340.      end
  341.    else
  342.      for i in 1..distance
  343.        x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
  344.        y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
  345.        r = start_color.red * (distance-i)/distance + end_color.red * i/distance
  346.        g = start_color.green * (distance-i)/distance + end_color.green * i/distance
  347.        b = start_color.blue * (distance-i)/distance + end_color.blue * i/distance
  348.        a = start_color.alpha * (distance-i)/distance + end_color.alpha * i/distance
  349.        if width == 1
  350.          self.contents.set_pixel(x, y, Color.new(r, g, b, a))
  351.        else
  352.          self.contents.fill_rect(x, y, width, width, Color.new(r, g, b, a))
  353.        end
  354.      end
  355.    end
  356. end
  357. end
  358. #==============================================================================
  359. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  360. #==============================================================================
复制代码
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
103 小时
注册时间
2011-2-16
帖子
285
3
发表于 2011-7-12 14:57:32 | 只看该作者
#==============================================================================
# 本脚本来自http://www.66rpg.com/,转载请保留此信息
#==============================================================================
#==============================================================================
# ■ Window_Help
#------------------------------------------------------------------------------
# 可以显示敌人的HP\MP百分比
#==============================================================================
class Window_Help < Window_Base
  def set_enemy(actor)
    self.contents.clear
    draw_actor_name(actor, 4, 0)
    draw_actor_state(actor, 140, 0)
    carol3_draw_hp_bar(actor, 284, 0)
    carol3_draw_sp_bar(actor, 460, 0)
    @text = nil
    self.visible = true
  end
  def carol3_draw_hp_bar(actor, x, y, width = 128) #宽度可调
    self.contents.font.color = system_color
    self.contents.fill_rect(x-1, y+17, width+2,6, Color.new(0, 0, 0, 255))
    w = width * actor.hp / actor.maxhp
    self.contents.fill_rect(x, y+18, w,1, Color.new(255, 96, 96, 255))
    self.contents.fill_rect(x, y+19, w,1, Color.new(255, 0, 0, 255))
    self.contents.fill_rect(x, y+20, w,1, Color.new(128, 0, 0, 255))
    self.contents.fill_rect(x, y+21, w,1, Color.new(0, 0, 0, 255))
    self.contents.draw_text(x,y,128,32,$data_system.words.hp,1)
    self.contents.font.color = normal_color
  end
  def carol3_draw_sp_bar(actor, x, y, width = 128)
    self.contents.font.color = system_color
    self.contents.fill_rect(x-1, y+17, width+2,6, Color.new(0, 0, 0, 255))
    w = width * actor.sp / actor.maxsp
    self.contents.fill_rect(x, y+18, w,1, Color.new(128, 255, 255, 255))
    self.contents.fill_rect(x, y+19, w,1, Color.new(0, 255, 255, 255))
    self.contents.fill_rect(x, y+20, w,1, Color.new(0, 192, 192, 255))
    self.contents.fill_rect(x, y+21, w,1, Color.new(0, 128, 128, 255))
    self.contents.draw_text(x,y,128,32,$data_system.words.sp,1)
    self.contents.font.color = normal_color
  end
end

我这个只是按百分比显示
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-11-26 12:48

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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