Project1

标题: 如何显示人物和怪物血条 [打印本页]

作者: norki2010    时间: 2011-7-22 13:39
提示: 作者被禁止或删除 内容自动屏蔽
作者: Cherry    时间: 2011-7-22 13:42
XP区搜索“血条”
作者: norki2010    时间: 2011-7-22 14:00
提示: 作者被禁止或删除 内容自动屏蔽
作者: 南宫爱    时间: 2011-7-22 14:06
本帖最后由 南宫爱 于 2011-7-22 14:07 编辑

直接插入脚本编辑器(如果没有特殊说明,就插在main之前)
作者: plummy    时间: 2011-7-22 20:43
  1. class Window_Base < Window  
  2.   #--------------------------------------------------------------------------
  3.   # * Draw Slant Bar
  4.   #--------------------------------------------------------------------------
  5.   def draw_slant_bar(x, y, min, max, width = 152, height = 6,
  6.       bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
  7.     # Draw Border
  8.     for i in 0..height
  9.       self.contents.fill_rect(x + i, y + height - i, width + 1, 1, Color.new(50, 50, 50, 255))
  10.     end
  11.     # Draw Background
  12.     for i in 1..(height - 1)
  13.       r = 100 * (height - i) / height + 0 * i / height
  14.       g = 100 * (height - i) / height + 0 * i / height
  15.       b = 100 * (height - i) / height + 0 * i / height
  16.       a = 255 * (height - i) / height + 255 * i / height
  17.       self.contents.fill_rect(x + i, y + height - i, width, 1, Color.new(r, b, g, a))
  18.     end
  19.     # Draws Bar
  20.     for i in 1..( (min / max.to_f) * width - 1)
  21.       for j in 1..(height - 1)
  22.         r = bar_color.red * (width - i) / width + end_color.red * i / width
  23.         g = bar_color.green * (width - i) / width + end_color.green * i / width
  24.         b = bar_color.blue * (width - i) / width + end_color.blue * i / width
  25.         a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
  26.         self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
  27.       end
  28.     end
  29.   end
  30. end


  31. class Window_EnemyHP < Window_Base
  32.   
  33.   def initialize
  34.     super(0, 0, 640, 480)
  35.     self.contents = Bitmap.new(width - 32, height - 32)
  36.     self.opacity = 0
  37.     refresh
  38.   end
  39.   
  40.   def refresh
  41.     self.contents.clear
  42.     for i in 0...$game_troop.enemies.size
  43.       @enemy = $game_troop.enemies[i]
  44.       @percent = (@enemy.hp * 100) / @enemy.maxhp
  45.       unless @enemy.hp == 0
  46.       draw_slant_bar(@enemy.screen_x - 55, @enemy.screen_y - 10, @enemy.hp, @enemy.maxhp, width = 75, height = 6, bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
  47.       self.contents.draw_text(@enemy.screen_x - 39, @enemy.screen_y - 22, 100, 32, "#{@percent}" + "%")
  48.     end
  49.   end
  50. end
  51. end

  52. class Scene_Battle
  53.   
  54.   alias raz_update update
  55.   alias raz_update_phase5 update_phase5
  56.   alias raz_update_phase4_step1 update_phase4_step1
  57.   alias raz_update_phase4_step5 update_phase4_step5
  58.   alias raz_enemy_hp_main main
  59.   
  60.    def main
  61.     @troop_id = $game_temp.battle_troop_id
  62.     $game_troop.setup(@troop_id)
  63.     @enemy_window = Window_EnemyHP.new
  64.     @enemy_window.z = 95
  65.     raz_enemy_hp_main
  66.     @enemy_window.dispose
  67.   end

  68.   
  69.   def update
  70.     @enemy_window.update
  71.     raz_update
  72.   end

  73.   def update_phase5
  74.     # If wait count is larger than 0
  75.     if @phase5_wait_count > 0
  76.       # Decrease wait count
  77.       @phase5_wait_count -= 1
  78.       # If wait count reaches 0
  79.       if @phase5_wait_count == 0
  80.         @enemy_window.visible = false
  81.         # Show result window
  82.         @result_window.visible = true
  83.         # Clear main phase flag
  84.         $game_temp.battle_main_phase = false
  85.         # Refresh status window
  86.         @status_window.refresh
  87.         @enemy_window.refresh
  88.       end
  89.       return
  90.     end
  91.    raz_update_phase5
  92. end

  93. def update_phase4_step1
  94.   raz_update_phase4_step1
  95.   @enemy_window.refresh
  96. end

  97.   def update_phase4_step5
  98.     # Hide help window
  99.     @help_window.visible = false
  100.     # Refresh status window
  101.     @status_window.refresh
  102.     @enemy_window.refresh
  103.     raz_update_phase4_step5
  104.   end
  105. end

  106. class Window_BattleStatus < Window_Base
  107.   #--------------------------------------------------------------------------
  108.   # * Object Initialization
  109.   #--------------------------------------------------------------------------
  110.   def initialize
  111.     super(0, 320, 640, 160)
  112.     self.contents = Bitmap.new(width - 32, height - 32)
  113.     @level_up_flags = [false, false, false, false]
  114.     refresh
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # * Dispose
  118.   #--------------------------------------------------------------------------
  119.   def dispose
  120.     super
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # * Set Level Up Flag
  124.   #     actor_index : actor index
  125.   #--------------------------------------------------------------------------
  126.   def level_up(actor_index)
  127.     @level_up_flags[actor_index] = true
  128.   end
  129.   #--------------------------------------------------------------------------
  130.   # * Refresh
  131.   #--------------------------------------------------------------------------
  132.   def refresh
  133.     self.contents.clear
  134.     @item_max = $game_party.actors.size
  135.     for i in 0...$game_party.actors.size
  136.       actor = $game_party.actors[i]
  137.       actor_x = i * 160 + 4
  138.       draw_slant_bar(actor_x, 55, actor.hp, actor.maxhp, 120)
  139.       draw_slant_bar(actor_x, 88, actor.sp, actor.maxsp, 120, 6, bar_color = Color.new(150, 0, 150, 255), end_color = Color.new(0, 0, 255, 255))
  140.       draw_actor_name(actor, actor_x, 0)
  141.       draw_actor_hp(actor, actor_x, 32, 120)
  142.       draw_actor_sp(actor, actor_x, 64, 120)
  143.       if @level_up_flags[i]
  144.         self.contents.font.color = normal_color
  145.         self.contents.draw_text(actor_x, 96, 120, 32, "LEVEL UP!")
  146.       else
  147.         draw_actor_state(actor, actor_x, 96)
  148.       end
  149.     end
  150.   end
  151.   #--------------------------------------------------------------------------
  152.   # * Frame Update
  153.   #--------------------------------------------------------------------------
  154.   def update
  155.     super
  156.     # Slightly lower opacity level during main phase
  157.     if $game_temp.battle_main_phase
  158.       self.contents_opacity -= 4 if self.contents_opacity > 191
  159.     else
  160.       self.contents_opacity += 4 if self.contents_opacity < 255
  161.     end
  162.   end
  163. end

复制代码
插在main之前
作者: yatanb    时间: 2011-7-30 18:18
提示: 作者被禁止或删除 内容自动屏蔽
作者: 个快快    时间: 2011-7-31 08:01
应搜索“血槽”。。。
作者: AEGIS    时间: 2011-8-3 10:56
提示: 作者被禁止或删除 内容自动屏蔽




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