切換
舊版
前往
大廳
主題

【選單腳本】漸變血條 v1.00

先行者 | 2012-08-11 14:53:31 | 巴幣 156 | 人氣 720

○畫面:

○檢視:
#==============================================================================
#----------------------------------------------------------------------------
# ○  OSD - 腳本討論社
#     Originality RGSS Discuss
#     └http://guild.gamer.com.tw/guild.php?sn=4707
#----------------------------------------------------------------------------
#==============================================================================
#--------------------------------------------------------------------------
# ● 腳本名稱:漸變血條
#--------------------------------------------------------------------------
# ● 腳本效果:
#     改變血條的更新方法,
#     改成一點一點扣除,使用上可能影響效率
#--------------------------------------------------------------------------
# ● 腳本版本:1.00 版
#--------------------------------------------------------------------------
# ● 腳本更新區塊:
#     目前並無更新
#--------------------------------------------------------------------------
#==============================================================================
#----------------------------------------------------------------------------
# ○  OSD - 腳本討論社
#     Originality RGSS Discuss
#     └http://guild.gamer.com.tw/guild.php?sn=4707
#----------------------------------------------------------------------------
#==============================================================================

○使用方法:
※※※※※※※※※※※※※※※※※※※※
HP_Speed
控制 HP 漸減的速度。數字越大漸減越慢數字越小漸減越快
※※※※※※※※※※※※※※※※※※※※
SP_Speed
控制 SP 漸減的速度。數字越大漸減越慢數字越小漸減越快
※※※※※※※※※※※※※※※※※※※※

○腳本檢視:
#==============================================================================
#----------------------------------------------------------------------------
# ○  OSD - 腳本討論社
#     Originality RGSS Discuss
#     └http://guild.gamer.com.tw/guild.php?sn=4707
#----------------------------------------------------------------------------
#==============================================================================
#--------------------------------------------------------------------------
# ● 腳本名稱:漸變血條
#--------------------------------------------------------------------------
# ● 腳本效果:
#     改變血條的更新方法,
#     改成一點一點扣除,使用上可能影響效率
#--------------------------------------------------------------------------
# ● 腳本版本:1.00 版
#--------------------------------------------------------------------------
# ● 腳本更新區塊:
#     目前並無更新
#--------------------------------------------------------------------------
#==============================================================================
#----------------------------------------------------------------------------
# ○  OSD - 腳本討論社
#     Originality RGSS Discuss
#     └http://guild.gamer.com.tw/guild.php?sn=4707
#----------------------------------------------------------------------------
#==============================================================================
#--------------------------------------------------------------------------
# ● 漸變血條自定義區
#--------------------------------------------------------------------------
module Diminution_Bar
  # 控制 HP 的快慢
  HP_Speed = 10
  # 控制 SP 的快慢
  SP_Speed = 10
end
#==============================================================================
# ■ Window_Base
#------------------------------------------------------------------------------
# 遊戲中全部視窗的超級類別。
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # ● 描繪 HP
  #     actor : 角色
  #     x     : 描畫目標 X 座標
  #     y     : 描畫目標 Y 座標
  #     width : 描畫目標的寬度
  #--------------------------------------------------------------------------
  alias draw_actor_hp_osd draw_actor_hp
  def draw_actor_hp(actor, x, y, width = 144)
    # 如果在沒有戰鬥中的情況下
    if !$game_temp.in_battle
      # 描繪 HP 條
      draw_actor_hp_bar(actor, x, y + 10, width, 12)
    end
    draw_actor_hp_osd(actor, x, y, width)
  end
  #--------------------------------------------------------------------------
  # ● 描繪 HP 框
  #--------------------------------------------------------------------------
  def draw_actor_hp_bar(actor, x, y, width, height)
    # 描繪第一外框
    self.contents.fill_rect(x, y, width, height, Color.new(50, 0, 0, 255))
    # 描繪第二外框
    self.contents.fill_rect(x + 1, y + 1, width - 2, height - 2, Color.new(200, 200, 200, 255))
    # 描繪第三外框
    self.contents.fill_rect(x + 2, y + 2, width - 4, height - 4, Color.new(50, 0, 0, 255))
    # 獲取描繪程度
    hp_width = actor.hp_real * (width - 4) / actor.maxhp
    # 描繪內框
    (0...hp_width).each {|i|
      self.contents.fill_rect(x + i + 2, y + 2, 1, height - 4, Color.new(220, i, i / 2, 255))
    }
  end
  #--------------------------------------------------------------------------
  # ● 描繪 SP
  #     actor : 角色
  #     x     : 描畫目標 X 座標
  #     y     : 描畫目標 Y 座標
  #     width : 描畫目標的寬度
  #--------------------------------------------------------------------------
  alias draw_actor_sp_osd draw_actor_sp
  def draw_actor_sp(actor, x, y, width = 144)
    # 如果在沒有戰鬥中的情況下
    if !$game_temp.in_battle
      # 描繪 SP 條
      draw_actor_sp_bar(actor, x, y + 10, width, 12)
    end
    draw_actor_sp_osd(actor, x, y, width)
  end
  #--------------------------------------------------------------------------
  # ● 描繪 SP 框
  #--------------------------------------------------------------------------
  def draw_actor_sp_bar(actor, x, y, width, height)
    # 描繪第一外框
    self.contents.fill_rect(x, y, width, height, Color.new(0, 0, 50, 255))
    # 描繪第二外框
    self.contents.fill_rect(x + 1, y + 1, width - 2, height - 2, Color.new(200, 200, 200, 255))
    # 描繪第三外框
    self.contents.fill_rect(x + 2, y + 2, width - 4, height - 4, Color.new(0, 0, 50, 255))
    # 獲取描繪程度
    sp_width = actor.sp_real * (width - 4) / actor.maxsp
    # 描繪內框
    (0...sp_width).each {|i|
      self.contents.fill_rect(x + i + 2, y + 2, 1, height - 4, Color.new(i,  i, 220, 255))
    }
  end
end
#==============================================================================
# ■ Game_Battler (第一部份)
#------------------------------------------------------------------------------
# 處理戰鬥者的類別。這個類別作為 Game_Actor 類別與 Game_Enemy 類別總綱來使用。
#==============================================================================

class Game_Battler
  #--------------------------------------------------------------------------
  # ● 定義實例變量
  #--------------------------------------------------------------------------
  attr_writer :hp_space                   # HP儲存空間
  attr_accessor :hp_real                  # HP儲存空間
  attr_writer :sp_space                   # SP儲存空間
  attr_accessor :sp_real                  # SP儲存空間
  #--------------------------------------------------------------------------
  # ● 初始化目標
  #--------------------------------------------------------------------------
  alias initialize_osd initialize
  def initialize
    initialize_osd
    @hp_space = 0
    @hp_real = @hp
    @sp_space = 0
    @sp_real = @sp
  end
  #--------------------------------------------------------------------------
  # ● 獲取目前 HP 儲存空間
  #--------------------------------------------------------------------------
  def hp_space
    if @hp_real != @hp
      @hp_space = @hp_real - @hp
    else
      return @hp_space
    end
  end
  #--------------------------------------------------------------------------
  # ● 獲取目前 SP 儲存空間
  #--------------------------------------------------------------------------
  def sp_space
    if @sp_real != @sp
      @sp_space = @sp_real - @sp
    else
      return @sp_space
    end
  end
end
#==============================================================================
# ■ Window_Battle_HP
#------------------------------------------------------------------------------
# 顯示戰鬥畫面同伴狀態的視窗。
#==============================================================================

class Window_Battle_HP < Window_Base
  #--------------------------------------------------------------------------
  # ● 初始化目標
  #--------------------------------------------------------------------------
  def initialize(battler)
    super(0, 320, 640, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
    @battler = battler
    battler.each {|actor|
      hp_bar_refresh(actor)
    }
    self.opacity = 0
  end
  #--------------------------------------------------------------------------
  # ● 釋放所佔用的記憶體空間
  #--------------------------------------------------------------------------
  def dispose
    super
  end
  #--------------------------------------------------------------------------
  # ● 刷新 HP 條
  #--------------------------------------------------------------------------
  def hp_bar_refresh(battler)
    draw_actor_hp_bar(battler, battler.index * 160 + 4, 44, 120, 12)
  end
  #--------------------------------------------------------------------------
  # ● 刷新 HP 速度
  #--------------------------------------------------------------------------
  def hp_space_count(battler)
    return battler.hp_space / Diminution_Bar::HP_Speed
  end
  #--------------------------------------------------------------------------
  # ● 更新
  #--------------------------------------------------------------------------
  def update
    super
    @battler.each {|actor|
      if actor.hp_space != 0 and !actor.dead?
        actor.hp_real -= hp_space_count(actor)
        actor.hp_space -= hp_space_count(actor)
        hp_bar_refresh(actor)
      elsif actor.hp_space != 0 and actor.dead?
        if actor.hp_space > 0
          actor.hp_real -= hp_space_count(actor)
          actor.hp_space -= hp_space_count(actor)
          hp_bar_refresh(actor)
        end
      end
    }
  end
end

#==============================================================================
# ■ Window_Battle_SP
#------------------------------------------------------------------------------
# 顯示戰鬥畫面同伴狀態的視窗。
#==============================================================================

class Window_Battle_SP < Window_Base
  #--------------------------------------------------------------------------
  # ● 初始化目標
  #--------------------------------------------------------------------------
  def initialize(battler)
    super(0, 320, 640, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
    @battler = battler
    battler.each {|actor|
      sp_bar_refresh(actor)
    }
    self.opacity = 0
  end
  #--------------------------------------------------------------------------
  # ● 釋放所佔用的記憶體空間
  #--------------------------------------------------------------------------
  def dispose
    super
  end
  #--------------------------------------------------------------------------
  # ● 刷新 SP
  #--------------------------------------------------------------------------
  def sp_bar_refresh(battler)
    draw_actor_sp_bar(battler, battler.index * 160 + 4, 76, 120, 12)
  end
  #--------------------------------------------------------------------------
  # ● 刷新 SP 速度
  #--------------------------------------------------------------------------
  def sp_space_count(battler)
    return battler.sp_space / Diminution_Bar::SP_Speed
  end
  #--------------------------------------------------------------------------
  # ● 更新
  #--------------------------------------------------------------------------
  def update
    super
    @battler.each {|actor|
      if actor.sp_space != 0 and !actor.dead?
        actor.sp_real -= sp_space_count(actor)
        actor.sp_space -= sp_space_count(actor)
        sp_bar_refresh(actor)
      elsif actor.sp_space != 0 and actor.dead?
        if actor.sp_space > 0
          actor.sp_real -= sp_space_count(actor)
          actor.sp_space -= sp_space_count(actor)
          sp_bar_refresh(actor)
        end
      end
    }
  end
end


#==============================================================================
# ■ Scene_Battle (第一部份)
#------------------------------------------------------------------------------
# 處理戰鬥畫面的類別。
#==============================================================================

class Scene_Battle
  alias main_osd main
  def main
    # 更新 HP
    $game_party.actors.each {|battler|
      battler.hp_real = battler.hp
      battler.sp_real = battler.sp
    }
    # 製作 HP 條
    @battler_hp = Window_Battle_HP.new($game_party.actors)
    @battler_hp.z = 100
    # 製作 SP 條
    @battler_sp = Window_Battle_SP.new($game_party.actors)
    @battler_sp.z = 100
    # 呼叫原有方法
    main_osd
    # 釋放
    @battler_hp.dispose
    @battler_sp.dispose
  end
  #--------------------------------------------------------------------------
  # ● 更新畫面
  #--------------------------------------------------------------------------
  alias update_osd update
  def update
    # 更新 HP 條
    @battler_hp.update
    # 更新 SP 條
    @battler_sp.update
    # 呼叫原有方法
    update_osd
  end
end

○範例下載:
下載點 1
下載點 2
送禮物贊助創作者 !
0
留言

創作回應

月見斐夜
用你原版不會有BUG,但我一調血條寫法BUG就出現了
hp_space居然出現負值OTZ
血條歸0居然就倒著充血了XD
2012-08-27 18:32:04
先行者
耶!!?[e28]
這....是怎麼回事!!?那應該不是我的問題吧....因為我懶的更改了XDD(去死
2012-08-27 18:48:57
月見斐夜
改寫法修好了...
雙色漸變搞死人= =
2012-08-27 19:11:00
先行者
恩?雙色漸變的話我猜是不是要寫兩次?
2012-08-27 19:27:51
月見斐夜
是先判斷兩個顏色的距離
然後分別混合兩個顏色的red、green、blue、alpha
再用fill_rect描繪出來

我表示我自己的寫法血會倒充
所以最後是套用別人的寫法= =
2012-08-27 19:37:45
先行者
還是用現成的好[e29]
2012-08-27 20:02:00
Anly
我是覺得先扣寫在顯示傷害有點怪怪的啦XD
2013-08-09 20:05:42
先行者
對阿,不過我其實自己專案有改,反正我小屋也沒什麼人氣所以就不更新了[e26]
2013-08-09 20:36:35
白羽優莉奈
呵呵,這個VA裡面有內建~~
2014-02-02 11:04:04
先行者
恩恩,超想要這效果所以就寫出來了[e16]
2014-02-02 17:49:49

更多創作