Project1

标题: 求把这个显示HP条的脚本加一个开关=w= [打印本页]

作者: 天使喝可乐    时间: 2012-7-11 13:29
标题: 求把这个显示HP条的脚本加一个开关=w=
这个脚本可以在地图上显示HP SP  希望能加一个开关,打开X号开关时,才显示HP SP条  如果没有打开则不显示。(也就是默认不显示)
感谢 这是脚本  由于有点素材 也可以下载范例:
HP.rar (201.67 KB, 下载次数: 44)
  1. #======================================
  2. # ■ 图片显示生命
  3. #======================================
  4. #  By: pudding
  5. #======================================
  6. class Hp_Window  < Window_Base
  7.   def initialize  
  8.     super(-15, -16, 740, 580)
  9.     self.contents = Bitmap.new(width - 32, height - 32)
  10.     self.opacity = 0
  11.     self.z = 0
  12.     self.visible = true
  13.     refresh
  14.   end

  15.   #--------------------------------------------------------------------------
  16.   # ● 刷新画面
  17.   #--------------------------------------------------------------------------
  18.   def update
  19.     value_x = -188
  20.     actor = $game_party.actors[0]  #主角
  21.     draw_hp_background(0 + value_x,0)    # HP底图
  22.     draw_mp_background(312 + value_x,8)  # MP底图
  23.     draw_hp(actor, 209 + value_x, 8) #生命条
  24.     draw_mp(actor, 312 + value_x, 8) #能量条
  25.     draw_map_exp(actor, 246 + value_x, 29)   #经验条
  26.       #角色死亡处理
  27. if $game_party.actors[0].hp <= 1
  28. #游戏结束
  29. $scene = Scene_Gameover.new
  30. end
  31.     end
  32.   #--------------------------------------------------------------------------
  33.   # ● 刷新画面
  34.   #--------------------------------------------------------------------------
  35.   def refresh
  36.     self.contents.clear
  37.     value_x = -188
  38.     actor = $game_party.actors[0]  #主角
  39.   end
  40.    #----------------------------------------------------------------------------
  41.   # ● 底图
  42.   #----------------------------------------------------------------------------
  43.   def draw_hp_background(x,y)
  44.     hp_background = RPG::Cache.picture("HPdi")
  45.     hp_back = Rect.new(0, 0, hp_background.width, hp_background.height)
  46.     self.contents.blt(x, y, hp_background, hp_back)
  47.   end
  48.   def draw_mp_background(x,y)
  49.     hp_background = RPG::Cache.picture("MP")
  50.     hp_back = Rect.new(0, 0, hp_background.width, hp_background.height)
  51.     self.contents.blt(x, y, hp_background, hp_back)
  52.   end
  53.   #----------------------------------------------------------------------------
  54.   # ● 生命条
  55.   #----------------------------------------------------------------------------
  56. def draw_hp(actor,x,y)
  57.     hp = RPG::Cache.picture("HP条")
  58.     hp_w = hp.width * actor.hp / [actor.maxhp,1].max
  59.     rect2 = Rect.new(0,0,hp_w,hp.height)
  60.     self.contents.blt(x,y,hp,rect2)
  61.   end #def HP
  62.   #----------------------------------------------------------------------------
  63.   # ● 能量条
  64.   #----------------------------------------------------------------------------
  65.    def draw_mp(actor,x,y)
  66.     mp = RPG::Cache.picture("MP条")
  67.     mp_w = mp.width * (actor.maxsp-actor.sp)  / [actor.maxsp,1].max
  68.     rect3 = Rect.new(0,0,mp_w,mp.height)
  69.     self.contents.blt(x,y,mp,rect3)
  70.   end #def MP
  71.   #----------------------------------------------------------------------------
  72.   # ● 描绘地图界面经验条
  73.   #----------------------------------------------------------------------------
  74.   def draw_map_exp(actor, x, y)
  75.     bitmap = RPG::Cache.picture("EXP条")
  76.     actor = $game_party.actors[0]
  77.     if actor.nextexp != 0
  78.       jisuan = actor.nowexp.to_f / actor.nextexp
  79.     else
  80.       jisuan = 1
  81.     end
  82.     if actor.level < 99 # 最大等级
  83.       nw = bitmap.width * jisuan
  84.     else
  85.       nw = bitmap.width
  86.     end  
  87.     src_rect = Rect.new(0, 0, nw, bitmap.height)
  88.     self.contents.blt( x, y, bitmap, src_rect)
  89.   end
  90. end
  91. #==============================================================================
  92. # ■ Game_Actor
  93. #==============================================================================
  94. class Game_Actor
  95.   #--------------------------------------------------------------------------
  96.   # ● 获取目前经验
  97.   #--------------------------------------------------------------------------
  98.   def nowexp
  99.      return @exp - @exp_list[@level]
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # ● 下一等级还需的经验
  103.   #--------------------------------------------------------------------------
  104.   def nextexp
  105.     return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
  106.   end
  107. end

  108. class Scene_Map
  109.   #--------------------------------------------------------------------------
  110.   # ● 主处理
  111.   #--------------------------------------------------------------------------
  112.   alias fox_text_window_main main
  113.   def main
  114.     @HP_window = Hp_Window.new
  115.     @item_1_new = $game_party.item_number(1).to_s
  116.     @item_2_new = $game_party.item_number(2).to_s
  117.     @item_3_new = $game_party.item_number(3).to_s
  118.     @item_4_new = $game_party.item_number(4).to_s
  119.     fox_text_window_main
  120.     # 释放
  121.     @HP_window.dispose
  122.     if $scene.is_a?(Scene_Title)
  123.       # 淡入淡出画面
  124.       Graphics.transition
  125.       Graphics.freeze
  126.     end
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # ● 更新
  130.   #--------------------------------------------------------------------------
  131.   alias fox_text_window_update update
  132.   def update
  133.     # 刷新地图状态窗口
  134.     if @item_1_new != $game_party.item_number(1).to_s
  135.       @HP_window.refresh
  136.       @item_1_new = $game_party.item_number(1).to_s
  137.     end
  138.     if @item_2_new != $game_party.item_number(2).to_s
  139.       @HP_window.refresh
  140.       @item_2_new = $game_party.item_number(2).to_s
  141.     end
  142.     if @item_3_new != $game_party.item_number(3).to_s
  143.       @HP_window.refresh
  144.       @item_3_new = $game_party.item_number(3).to_s
  145.     end
  146.     if @item_4_new != $game_party.item_number(4).to_s
  147.       @HP_window.refresh
  148.       @item_4_new = $game_party.item_number(4).to_s
  149.     end
  150.     fox_text_window_update
  151.     if @HP_window.visible
  152.       @HP_window.update
  153.     end
  154.   end
  155. end
复制代码
dsu_plus_rewardpost_czw
作者: 英顺的马甲    时间: 2012-7-11 16:46
在def update下面插入
@HP_window.visible = $game_switches[开关id]





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