Project1

标题: 怎样使图片显示生命的脚本改成从上至下减少? [打印本页]

作者: 南宫爱    时间: 2011-7-22 10:29
标题: 怎样使图片显示生命的脚本改成从上至下减少?
用了这个脚本:(怎样使它从上至下减少(垂直),而不是从右至左减少(水平))
  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 = 998
  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.     end
  27.   #--------------------------------------------------------------------------
  28.   # ● 刷新画面
  29.   #--------------------------------------------------------------------------
  30.   def refresh
  31.     self.contents.clear
  32.     value_x = -188
  33.     actor = $game_party.actors[0]  #主角
  34.   end
  35.    #----------------------------------------------------------------------------
  36.   # ● 底图
  37.   #----------------------------------------------------------------------------
  38.   def draw_hp_background(x,y)
  39.     hp_background = RPG::Cache.picture("HPdi")
  40.     hp_back = Rect.new(0, 0, hp_background.width, hp_background.height)
  41.     self.contents.blt(x, y, hp_background, hp_back)
  42.   end
  43.   def draw_mp_background(x,y)
  44.     hp_background = RPG::Cache.picture("MP")
  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.   #----------------------------------------------------------------------------
  49.   # ● 生命条
  50.   #----------------------------------------------------------------------------
  51. def draw_hp(actor,x,y)
  52.     hp = RPG::Cache.picture("HP条")
  53.     hp_w = hp.width * actor.hp / [actor.maxhp,1].max
  54.     rect2 = Rect.new(0,0,hp_w,hp.height)
  55.     self.contents.blt(x,y,hp,rect2)
  56.   end #def HP
  57.   #----------------------------------------------------------------------------
  58.   # ● 能量条
  59.   #----------------------------------------------------------------------------
  60.    def draw_mp(actor,x,y)
  61.     mp = RPG::Cache.picture("MP条")
  62.     mp_w = mp.width * (actor.maxsp-actor.sp)  / [actor.maxsp,1].max
  63.     rect3 = Rect.new(0,0,mp_w,mp.height)
  64.     self.contents.blt(x,y,mp,rect3)
  65.   end #def MP
  66.   #----------------------------------------------------------------------------
  67.   # ● 描绘地图界面经验条
  68.   #----------------------------------------------------------------------------
  69.   def draw_map_exp(actor, x, y)
  70.     bitmap = RPG::Cache.picture("EXP条")
  71.     actor = $game_party.actors[0]
  72.     if actor.nextexp != 0
  73.       jisuan = actor.nowexp.to_f / actor.nextexp
  74.     else
  75.       jisuan = 1
  76.     end
  77.     if actor.level < 99 # 最大等级
  78.       nw = bitmap.width * jisuan
  79.     else
  80.       nw = bitmap.width
  81.     end  
  82.     src_rect = Rect.new(0, 0, nw, bitmap.height)
  83.     self.contents.blt( x, y, bitmap, src_rect)
  84.   end
  85. end
  86. #==============================================================================
  87. # ■ Game_Actor
  88. #==============================================================================
  89. class Game_Actor
  90.   #--------------------------------------------------------------------------
  91.   # ● 获取目前经验
  92.   #--------------------------------------------------------------------------
  93.   def nowexp
  94.      return @exp - @exp_list[@level]
  95.   end
  96.   #--------------------------------------------------------------------------
  97.   # ● 下一等级还需的经验
  98.   #--------------------------------------------------------------------------
  99.   def nextexp
  100.     return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
  101.   end
  102. end

  103. class Scene_Map
  104.   #--------------------------------------------------------------------------
  105.   # ● 主处理
  106.   #--------------------------------------------------------------------------
  107.   alias fox_text_window_main main
  108.   def main
  109.     @HP_window = Hp_Window.new
  110.     @item_1_new = $game_party.item_number(1).to_s
  111.     @item_2_new = $game_party.item_number(2).to_s
  112.     @item_3_new = $game_party.item_number(3).to_s
  113.     @item_4_new = $game_party.item_number(4).to_s
  114.     fox_text_window_main
  115.     # 释放
  116.     @HP_window.dispose
  117.     if $scene.is_a?(Scene_Title)
  118.       # 淡入淡出画面
  119.       Graphics.transition
  120.       Graphics.freeze
  121.     end
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # ● 更新
  125.   #--------------------------------------------------------------------------
  126.   alias fox_text_window_update update
  127.   def update
  128.     # 刷新地图状态窗口
  129.     if @item_1_new != $game_party.item_number(1).to_s
  130.       @HP_window.refresh
  131.       @item_1_new = $game_party.item_number(1).to_s
  132.     end
  133.     if @item_2_new != $game_party.item_number(2).to_s
  134.       @HP_window.refresh
  135.       @item_2_new = $game_party.item_number(2).to_s
  136.     end
  137.     if @item_3_new != $game_party.item_number(3).to_s
  138.       @HP_window.refresh
  139.       @item_3_new = $game_party.item_number(3).to_s
  140.     end
  141.     if @item_4_new != $game_party.item_number(4).to_s
  142.       @HP_window.refresh
  143.       @item_4_new = $game_party.item_number(4).to_s
  144.     end
  145.     fox_text_window_update
  146.     if @HP_window.visible
  147.       @HP_window.update
  148.     end
  149.   end
  150. end
复制代码
dsu_plus_rewardpost_czw
作者: Wind2010    时间: 2011-7-22 10:47
  1. class Hp_Window
  2.   def draw_hp(actor,x,y)
  3.     hp = RPG::Cache.picture("HP条")
  4.     hp_h = hp.height * actor.hp / [actor.maxhp,1].max
  5.     rect2 = Rect.new(0,hp.height-hp_h,hp.width,hp_h)
  6.     self.contents.blt(x,y,hp,rect2)
  7.   end #def HP
  8.   #----------------------------------------------------------------------------
  9.   # ● 能量条
  10.   #----------------------------------------------------------------------------
  11.    def draw_mp(actor,x,y)
  12.     mp = RPG::Cache.picture("MP条")
  13.     mp_h = mp.height * (actor.maxsp-actor.sp)  / [actor.maxsp,1].max
  14.     rect3 = Rect.new(0,mp.height-mp_h,mp.width,mp_h)
  15.     self.contents.blt(x,y,mp,rect3)
  16.   end #def MP
  17. end
复制代码

作者: 南宫爱    时间: 2011-7-22 11:28
本帖最后由 南宫爱 于 2011-7-22 11:32 编辑

恩恩...不过应该是这样的...(如果直接把你的那个脚本改上去的话...会有意想不到的结果...)
  1.   #----------------------------------------------------------------------------
  2.   # ● 生命条
  3.   #----------------------------------------------------------------------------
  4. def draw_hp(actor,x,y)
  5.     hp = RPG::Cache.picture("HP")
  6.     hp_h = hp.height * actor.hp / [actor.maxhp,1].max
  7.     rect2 = Rect.new(0,hp.height-hp_h,hp.width,hp_h)
  8.     self.contents.blt(x,y+(hp.height-hp_h),hp,rect2)
  9.   end #def HP

  10.   #----------------------------------------------------------------------------
  11.   # ● 能量条
  12.   #----------------------------------------------------------------------------
  13. def draw_mp(actor,x,y)
  14.     mp = RPG::Cache.picture("PP")
  15.     mp_h = mp.height * actor.sp / [actor.maxsp,1].max
  16.     rect3 = Rect.new(0,mp.height-mp_h,mp.width,mp_h)
  17.     self.contents.blt(x,y+(mp.height-mp_h),mp,rect3)
  18.   end #def MP
复制代码
(如果不加上 self.contents.blt(x,y+(mp.height-mp_h),mp,rect3)
和self.contents.blt(x,y+(hp.height-hp_h),hp,rect2))
就是从下至上了...(额...= =)






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