[XP] Circular HP Guage

Started by JellalFerd, June 02, 2011, 06:52:00 am

Previous topic - Next topic

JellalFerd

Well, I'm horrible with explaining, but I'll give it a shot.
I was wondering if it were possible to create a circular HP gauge script.
Basically, here's a model of how I wanted it to work;
Spoiler: ShowHide






QuoteFrank says:
But obviously they put on that shirt on in the morning.
Hmmm..
Booty shirts are nice.
Depends on the girl.
Jellal says:
booty shirts
lolwut

brewmeister

It's huge!!!   :)

Can you post it completely empty?  HP 0

ForeverZer0

He's not posting it as a resource. This is a script request for providing functionality for a circular HP meter.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

brewmeister

June 10, 2011, 02:58:22 pm #3 Last Edit: June 10, 2011, 03:05:50 pm by brewmeister
Quote from: ForeverZer0 on June 07, 2011, 05:18:30 pm
He's not posting it as a resource. This is a script request for providing functionality for a circular HP meter.


I know. I just didn't want to guess what it should look like completely empty, and he only shows what it looks like 1/4 empty.
I suppose I could assume that the rest of the gauge is 'somewhat' darker when empty, but I've been burned too many times
in the past starting something without complete requirements that I just don't do it anymore.

The next question would be, how do you want this to integrate into the scenes that use an HP gauge?
Do you want it to completely replace "draw_actor_hp" every place HP is displayed (menu, status, battle),
and how do you want those windows rearranged to make room for the much larger HP gauge?

Or, do you want it simply as a new class that you can implement yourself?

Also, you are showing it with 4 increments of ~22.5 degrees (6.25%).  Which would be 16 increments overall.
Is that the desired precision?   or do you need a higher precision?

JellalFerd

I didn't want it to replace anything. Just to be incorporated into a HUD.

It wasn't the desired precision, I suppose I need a higher precision.
QuoteFrank says:
But obviously they put on that shirt on in the morning.
Hmmm..
Booty shirts are nice.
Depends on the girl.
Jellal says:
booty shirts
lolwut

Ryex

it would probably be best to do this as two overlaid images with the top one partially removed in a circular pattern. but at the moment I'm cumming up completely blank on writing an algorithm that could draw a a portion of a circle with the speed needed for a hud
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

brewmeister

June 12, 2011, 01:44:27 pm #6 Last Edit: June 12, 2011, 04:57:43 pm by brewmeister
Scratching my head on an algorithm for this too....

1) Ryex idea. It would be easy to write a method that subtracts (draws transparent) a line from the image. Then depending on the difference between the current & new value, iterate between the two. If the precision is a percent (100 possible values), and the value changes from 100 to 99, you draw 3 or 4 lines from the center of the circle at angles 0, 1, 2, 3.6.   The problem with this is I think the edges would end up jagged looking unless you added some kind of anti-alias algorithm, which would slow down the execution.

2) multiple images on layers.  What if we broke the top image up into 4 separate images (quadrants). Make 6 separate sprites (background, gauge1(100 - 75%), gauge2, gauge3, gauge4, and another upper left quadrant of the background).  then rotate each sprite to partially hide it behind the next sprite.  The last sprite, the partial background would turn on (become visible) when the value is less than 25%, for gauge4 to hide behind.

3) Make the top image like a big character set (except 10 x 10) with a separate image for each percent value, then just .blt the appropriate cell for the new value.

This will do the last option. It actually needs an image that's 10 x 11. first row starts with 0 & ends with 9. 11th row just has 100 in the first cell. (101 images in all)
Cells can be any size.  Call it with     @hp_gauge = Sprite_HPgauge.new(actor_id, x, y)
Don't forget to also dispose & update it in whichever scene you add it to.

#==============================================================================
# ** Sprite_HPgauge
#------------------------------------------------------------------------------
#  This sprite is used to display an hpgauge.
#  Create an image 10 cells wide, 11 cells tall with the gauge at 0%
#  in the first cell, the gauge at 100% in the first cell of the 11th row.
#==============================================================================

class Sprite_HPgauge < Sprite
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(actor_id, x = 0, y = 0)
    super()
    @charset = RPG::Cache.picture("hpgauge")
    @cw = @charset.width / 10
    @ch = @charset.height / 11
    self.bitmap = Bitmap.new(@cw, @ch)
    self.x = x
    self.y = y
    self.z = 500
    self.visible = true
    @actor_id = actor_id
    @hpp = -1
    update
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    if self.bitmap != nil
      self.bitmap.dispose
    end
    super
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    if @hpp != $game_actors[@actor_id].hp * 100 / $game_actors[@actor_id].maxhp
      @hpp = $game_actors[@actor_id].hp * 100 / $game_actors[@actor_id].maxhp
      row = @hpp / 10
      col = @hpp % 10
      rect = Rect.new(col * @cw, row * @ch, @cw, @ch)
      self.bitmap.blt(0, 0, @charset, rect)
    end
  end
end