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.

Simple Bars

I just need a script so I can draw some bars in a window, based off the hero's HP, MP and EXP.

I need the actual script, then I need to know how to implement it into a window...
 

arev

Sponsor

Code:
bar_width = 128
    percent = 0.00
    percent += actor.hp
    percent /= actor.maxhp
    self.contents.fill_rect(x, y + 28, bar_width, 4, Color.new(224,224,224,255))
    self.contents.fill_rect(x + 1, y + 29, bar_width - 2, 2, Color.new(32,32,32,255))
    self.contents.fill_rect(x + 1, y + 29, percent * (bar_width - 2), 2, Color.new(255,128,128,255))

this draws a bar with white (almost) outline, and black (almost) background. the "actor.hp" and "actor.maxhp" are the two variables to draw. you can place what you want in there. there's some messing around with counting those variables for "exp" as the previous level value isn't stored directly in any actor viariable.
 
Just place this above main:
Code:
class Game_Actor < Game_Battler  
#--------------------------------------------------------------------------
  # * Get the current EXP
  #--------------------------------------------------------------------------
  def now_exp
    return @exp - @exp_list[@level]
  end
  #--------------------------------------------------------------------------
  # * Get the next level's EXP
  #--------------------------------------------------------------------------
  def next_exp
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
  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

To draw bars do somethin like this
Code:
def draw_slant_bar(x, y, $game_party.actors[0].hp, $game_party.actors[0].maxhp, width = 152, height = 6, bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255)) # draw HP Bar
def draw_slant_bar(x, y, $game_party.actors[0].sp, $game_party.actors[0].maxsp, width = 152, height = 6, bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))# draw SP Bar
def draw_slant_bar(x, y, $game_party.actors[0].now_exp, $game_party.actors[0].next_exp, width = 152, height = 6, bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))# draw EXP Bar

Just change the x and y position and the color at the end of the command ^_^
 
Where would I put the "Draw_Slant_Bar" bits in this script?

#----------------------------------------
# Window_HudStats
#----------------------------------------

class Window_HudStats < Window_Base
#----------------------------------------
# Object Initialization
#----------------------------------------
def initialize
super(10, 10, 175, 70)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end

def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.font.size = 12
self.contents.draw_text(7, 7, 50, 25, @actors.name)
self.contents.draw_text(9, 28, 20, 32, HP)
self.contents.draw_text(9, 45, 20, 32, MP)
self.contents.draw_text(9, 62, 20, 32, XP)
bar_width = 175
percent = 0.00
percent += actor.hp
percent /= actor.maxhp
end
end


Sorry, I'm not that good at scripting...
 

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