Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: legacyblade on November 08, 2009, 05:42:47 pm

Title: Tiling HP Image[resolved]
Post by: legacyblade on November 08, 2009, 05:42:47 pm
Hello everyone. I'm working on making a CMS for my game, and I've run up against a wall. I'm using blizzABS and it's ZHUD addon (http://forum.chaos-project.com/index.php?topic=4284.0), and I would like my menu system to have the same tiled images to represent health that the ZHUD does. However, after looking through the code, I was unable to figure out how to do this. Does anyone know how I can duplicate the ZHUD's HP tiling in my CMS?

Any help would be appreciated. And thanks for reading :)
Title: Re: Tiling HP Image
Post by: winkio on November 08, 2009, 06:04:37 pm
Err, did you try just using the code in draw_hp?
Title: Re: Tiling HP Image
Post by: legacyblade on November 08, 2009, 06:08:36 pm
I tried to put it in, but had a bit of trouble understanding the code. Dealing with graphics is my weak point in coding still.

-edit

alright, I've been working with this for awhile, and I still can't get it to work right. The HP doesn't display properly, it just shows one image(though it is showing the correct image), no matter how much health the actor has. Here's a screenie:

Spoiler: ShowHide
(http://i33.tinypic.com/2uol6gy.png)


and here's a copy of my script so far

class Scene_Menu
 
  def initialize
   
    # set the background #
   
    @spriteset = Spriteset_Map.new
   
    # create the windows #
   
    @actor_list = []
   
    $game_party.actors.each_index{|actor|
    @actor_list.push Window_Party_Actor.new($game_party.actors[actor].id,actor)}

    #@obj_description      = Window_Obj_Description.new
    #@window_menu_commands = Window_Menu_Comands.new
   
  end
 
  def main
   
    # enter the scene's loop #
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
   
    # dispose of the windows #   
    Graphics.freeze
    @actor_list.each{|actorWindow|actorWindow.dispose}
    #@class_list.dispose
    #@class_description.dispose
    @spriteset.dispose
  end

  def update
    @actor_list.each{|actorWindow|actorWindow.update}
    #@obj_description.update
    #@window_menu_commands.update
    @spriteset.update
  end

end

class Window_Base
 
  def draw_tiled_hp(actor,mode,x,y,w,h)
    rate = (actor.maxhp > 0 ? actor.hp.to_f / actor.maxhp : 0)
    b1 = RPG::Cache.picture("HUD/" + BlizzCFG::Z_HP_FILE + mode)
    b2 = RPG::Cache.picture("HUD/" + BlizzCFG::Z_HP_FILE_EMPTY + mode)
    tiles = actor.maxhp / BlizzCFG::Z_HP_PER_TILE
    rows = (tiles.to_f / BlizzCFG::Z_HP_TILE_COLUMNS).ceil
      w, h = b1.width, b1.height
      self.contents.fill_rect(x, y, w * BlizzCFG::Z_HP_TILE_COLUMNS,
          h * rows, Color.new(0, 0, 0, 0))
      full_tiles = (rate * tiles).to_i
      semi_full = ((rate * tiles != full_tiles) ? 1 : 0)
      (0...full_tiles).each {|i|
          draw_x = x + (i % BlizzCFG::Z_HP_TILE_COLUMNS) * w
          draw_y = y + (i / BlizzCFG::Z_HP_TILE_COLUMNS) * h
          self.contents.blt(x, y, b1, Rect.new(0, 0, w, h))}
      if semi_full > 0
        draw_x = x + (full_tiles % BlizzCFG::Z_HP_TILE_COLUMNS) * w
        draw_y = y + (full_tiles / BlizzCFG::Z_HP_TILE_COLUMNS) * h
        if BlizzCFG::Z_HP_FILL_UP
          h2 = ((1 - rate * tiles + full_tiles) * h).to_i
          self.contents.blt(draw_x, draw_y, b2, Rect.new(0, 0, w, h2))
          self.contents.blt(draw_x, draw_y + h2, b1, Rect.new(0, h2, w, h - h2))
        else
          w2 = ((rate * tiles - full_tiles) * w).to_i
          self.contents.blt(x, y, b1, Rect.new(0, 0, w2, h))
          self.contents.blt(x + w2, y, b2, Rect.new(w2, 0, w - w2, h))
        end
      end
    ((full_tiles + semi_full)...tiles).each {|i|
    draw_x = x + (i % BlizzCFG::Z_HP_TILE_COLUMNS) * w
    draw_y = y + (i / BlizzCFG::Z_HP_TILE_COLUMNS) * h
    self.contents.blt(draw_x, draw_y, b2, Rect.new(0, 0, w, h))}
  end 
end

class Window_Party_Actor < Window_Base
 
  def initialize(actorID,num)
    @actorID = actorID
    super(88, (64 + (num * 88)), 240, 88)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.size = 22
    refresh
  end
  def refresh
    self.contents.clear
    draw_actor_name($game_actors[@actorID], 0, 0)
    draw_tiled_hp($game_actors[@actorID],'_thumb',0,28,200,64)
  end
end


and, if you need it, here's my ZHud configuration

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# START Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 
  # maximum height of the HUD
  Z_HUD_HEIGHT = 96
 
  # tiling HP images
  Z_HP_TILING = true
  # displays as if the images are filled up (only when tiling)
  Z_HP_FILL_UP = true
  # how many columns are used for the tile in one row (only when tiling)
  Z_HP_TILE_COLUMNS = 10
  # how many HP per column (only when tiling)
  Z_HP_PER_TILE = 3
  # full image file
  Z_HP_FILE = 'hud_HP'
  # empty image file
  Z_HP_FILE_EMPTY = 'hud_HP_empty'
 
  # tiling SP images
  Z_SP_TILING = false
  # displays as if the images are filled up (only when tiling)
  Z_SP_FILL_UP = false
  # how many columns are used for the tile in one row (only when tiling)
  Z_SP_TILE_COLUMNS = 10
  # how many SP per column (only when tiling)
  Z_SP_PER_TILE = 10
  # full image file
  Z_SP_FILE = 'hud_SP'
  # empty image file
  Z_SP_FILE_EMPTY = 'hud_SP_empty'
 
  # item hotkey background
  Z_ITEM_BACK = 'item'
  # skill hotkey background
  Z_SKILL_BACK = 'skill'
 
  # hotkeys display background
  Z_HOTKEYS_BACK = 'hotkey'
 
  # minimap background
  Z_MINIMAP_BACK = 'minimap'
 
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# END Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


if anyone could help me figure this out, that'd be great. (btw, if you're wondering why I'm using self.contents for the draw_tiled_hp method rather than self.bitmap like in the ZHud, it's because windows use self.contents for methods such as fill_rect.
Title: Re: Tiling HP Image
Post by: legacyblade on November 09, 2009, 08:40:01 pm
bump D:
Title: Re: Tiling HP Image
Post by: Fantasist on November 13, 2009, 02:05:23 pm
I could be wrong, but isn't this:


      (0...full_tiles).each {|i|
          draw_x = x + (i % BlizzCFG::Z_HP_TILE_COLUMNS) * w
          draw_y = y + (i / BlizzCFG::Z_HP_TILE_COLUMNS) * h
          self.contents.blt(x, y, b1, Rect.new(0, 0, w, h))}


supposed to be:


      (0...full_tiles).each {|i|
          draw_x = x + (i % BlizzCFG::Z_HP_TILE_COLUMNS) * w
          draw_y = y + (i / BlizzCFG::Z_HP_TILE_COLUMNS) * h
          self.contents.blt(draw_x, draw_y, b1, Rect.new(0, 0, w, h))}


(notice the line "self.contents.blt(draw_x, draw_y, b1, Rect.new(0, 0, w, h))}")
Title: Re: Tiling HP Image[resolved]
Post by: legacyblade on November 13, 2009, 03:12:40 pm
That works perfectly :D Thanks Fantasist, that really helped me out. I really appreciate this, now I can finish my CMS!

This topic is now officially resolved!