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.

Window not updating

I'm making a mining system, and everything works except one window, which doesn't update.

Here's what I have so far: (do not use on pain of death/monkeyrape)

Code:
class Scene_Mining
  
  def main
    @hud = Sprite.new
    @hud.bitmap = RPG::Cache.minigame('mining_hud')
    @over = Sprite.new
    @over.bitmap = RPG::Cache.minigame('mining_overlay')
    @over.z = 9995
    
    @help = Window_Help.new
    @help.x = 57
    @help.y = 67
    @help.z = 9998
    @help.width = 420
    
    $game_variables[45] = 20 if $game_variables[45] == 0
    $game_variables[21] = 1 if $game_variables[21] == 0
    
    @rockwin = Window_Rocks.new
    
    @rockwin2 = Window_MineBase.new
    
    @toolbar = Window_Toolbar.new
    
    $power = 0
    
    @rockwin3 = Window_MineBar.new
    
    # Setup rocks
    amnt = $game_variables[21] # mining rank
    amnt = 1 if amnt == 0
    
    @rand = rand(amnt)
    @rand += 1
    case @rand
    when 1
      @rock = 'coal'
    when 2
      @rock = 'iron'
    when 3
      @rock = 'lead'
    when 4
      @rock = 'gold'
    when 5
      @rock = 'mith'
    end
    
    @help.visible = false
    
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    
    @hud.dispose
    @over.dispose
    @rockwin.dispose
    @rockwin2.dispose
    @help.dispose
    @rockwin3.dispose
  end
  
  def update
    
    @hud.update
    @rockwin.update
    @rockwin2.update
    @rockwin3.update
    @help.update
    
    if @restart == true
      @restart = false
      $scene = Scene_Mining.new
      return
    end      
      
    if Input.trigger?(Input::UP)
      $power += 2 unless $power >= 50
    else
      $power -= 1 unless $power <= 0
    end
      
    if Input.trigger?(Input::C)
      if $game_variables[34] <= 0
        @help.visible = true
        @help.set_text('You are too tired to mine right now.')
        @help.visible = true
        return
      end
      
      if $power <= 30
        @help.visible = true
        @help.set_text('You hit the rock with your pickaxe, but not powerful enough to break it.')
        @restart = true
      elsif $power >= 40
        @help.visible = true
        @help.set_text('You hit the rock with your pickaxe.')
        @help.set_text('You use too much power; the rock crumbles to dust.')
        @restart = true
      else
        swing
      end
      
    end
    
    if Input.trigger?(Input::B)
      $scene = Scene_Map.new
    end
      
    levelup if $game_variables[20] >= $game_variables[45]
      
  end
    
  def levelup
    @help.visible = true
    $game_variables[21] += 1
    $game_variables[45] *= 1.75
    $game_variables[45] = $game_variables[45].ceil
    $game_variables[20] = 0
    $fmin = $game_variables[34] = 100
    @help.contents.clear
    @help.set_text('Your mining rank is now ' + $game_variables[21].to_s + '!')
  end
  
  
  def swing
    @help.contents.clear
    @help.visible = true
    @help.set_text('You swing your pickaxe at the rock.')
    
    $game_variables[20] += 5 # temp
    
    @restart = true
  end
  
end

Not the best script in the world, but it should work, as far as I can see. The broken window is @rockwin3, or:

Code:
class Window_MineBar < Window_Base
  def initialize
    super(44-16,112-16,24+32,245+32)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.z = 9990
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.draw_hp_picture_vertical(0, 0, $power, 50, 'mining_back', 'mining_front')
  end
end

The HP bar doesn't update here. The script for the HP bar:

Code:
class Bitmap
  def draw_hp_picture_vertical(x, y, min, max, background, bar)
    background = RPG::Cache.picture(background)
    bar = RPG::Cache.picture(bar)
    background_rect = Rect.new(0, 0, background.width, background.height)
    h = bar.height * min / max
    bar_rect = Rect.new(0, 0, bar.width, h)
    self.blt(x, y, background, background_rect)
    self.blt(x, y+bar.height-h, bar, bar_rect)
  end
end

Anyone got any ideas?
 

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