Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Enemy Window

Here you go:
Code:
#==============================================================================
# ** Scene_Battle (part 1)
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle
  alias raz_old_main main
  alias raz_old_update update
  alias raz_old_update_phase4_step5 update_phase4_step5
  alias raz_old_update_phase5 update_phase5
  alias raz_old_update_phase4_step1 update_phase4_step1
    #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    @troop_id = $game_temp.battle_troop_id
    $game_troop.setup(@troop_id)
    # Make actor command window
    @enemy_name = Window_EnemyName.new
    raz_old_main
    @enemy_name.dispose
  end
  
  def update
    @enemy_name.update
    raz_old_update
  end
  

  def update_phase4_step5
    @enemy_name.refresh
    raz_old_update_phase4_step5 
  end

    def update_phase5
    # If wait count is larger than 0
    if @phase5_wait_count > 0
      # Decrease wait count
      @phase5_wait_count -= 1
      # If wait count reaches 0
      if @phase5_wait_count == 0
        # Show result window
        @result_window.visible = true
        # Clear main phase flag
        $game_temp.battle_main_phase = false
        # Refresh status window
        @status_window.refresh
        @enemy_name.refresh
      end
      return
    end
   raz_old_update_phase5
   end

  def update_phase4_step1
    raz_old_update_phase4_step1
    @enemy_name.refresh
  end

end


class Window_EnemyName < Window_Base
  def initialize
    super(0, 0, 160, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.z = 50
    self.back_opacity = 160
    refresh
  end
  
  def refresh
   self.contents.clear
   self.contents.font.size = 21
   self.contents.draw_text(4, 0, 110, 32, "Enemies:")
    for i in 0...$game_troop.enemies.size
       x = 4 + i % 2 * 60
       enemy = $game_troop.enemies[i]
       y = i / 2 * 25 + 20
       self.contents.font.size = 16
       unless enemy.hp == 0
       draw_slant_bar(x ,y + 25, enemy.hp, enemy.maxhp, 50, 6)
       self.contents.draw_text(x, y, 130, 32, "#{enemy.name}")
       end
    end
  end

end

class Window_Base < Window  
  #--------------------------------------------------------------------------
  # * Draw Slant Bar(by SephirothSpawn)
  #--------------------------------------------------------------------------
  def draw_slant_bar(x, y, min, max, width = 152, height = 6,
      bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
    # Draw Border
    for i in 0..height
      self.contents.fill_rect(x + i, y + height - i, width + 1, 1, Color.new(50, 50, 50, 255))
    end
    # Draw Background
    for i in 1..(height - 1)
      r = 100 * (height - i) / height + 0 * i / height
      g = 100 * (height - i) / height + 0 * i / height
      b = 100 * (height - i) / height + 0 * i / height
      a = 255 * (height - i) / height + 255 * i / height
      self.contents.fill_rect(x + i, y + height - i, width, 1, Color.new(r, b, g, a))
    end
    # Draws Bar
    for i in 1..( (min / max.to_f) * width - 1)
      for j in 1..(height - 1)
        r = bar_color.red * (width - i) / width + end_color.red * i / width
        g = bar_color.green * (width - i) / width + end_color.green * i / width
        b = bar_color.blue * (width - i) / width + end_color.blue * i / width
        a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
        self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
      end
    end
  end
end

Just ask if you have some questions or if you want me to change something.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top