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 script

Hey, I used to be into scripting big time a few months ago, but I haven't touched RMXP for like 5 months and forgot practically everything about scripting.

I'd like it if somebody could make me a very simple bars script which can display HP. If at all possible, put comments in it as well so that I can learn from them.

Thanks
 

poccil

Sponsor

This is a very simple module for displaying a simple bar:

Code:
module BarWriter
  # x, y, width, height - rectangle to display the bar
  # value - current value
  # maxvalue - max value
  # color - color (like Color.new(255,255,255))
  def self.drawBar(bitmap,x,y,width,height,value,maxvalue,color)
   bitmap.fill_rect(x,y+2,width,height,Color.new(0,0,0))
   bitmap.fill_rect(x,y,width*value/maxvalue,height,color)    
  end
end

Example of usage

Code:
  bitmap=Bitmap.new(200,200)
  actor=$game_actors[1]
  # Draw a blue HP bar at the top left of the bitmap
  BarWriter.drawBar(bitmap,0,0,100,20,actor.hp,actor.maxhp,Color.new(0,0,255))
 

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