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.

Hello, i need some help

Hi, i would like to know how to make the game find the stuff im asking at the place i want to find it at, for expample:

Code:
  def draw_actor_face(actor, x, y)
  face = RPG::Cache.picture("Faces/" + actor.character_name, actor.character_hue)
  fw = face.width
  fh = face.height
  src_rect = Rect.new(0, 0, fw, fh)
  self.contents.blt(x - fw / 23, y - fh, face, src_rect)
  end

make that to look for any file i want it to at an exact place... cuz im starting to use lots of this type of codes and they all take the same pics, but i need to change the size of some of them.

Thx in advance.
 

Jared

Member

Sry, but I don't really understand your problem (my English is not so good). Do you want a method, which finds files in a directory?
If this is your question, I would use the Find-Module of the standard ruby library:
Code:
module Find
  def find(*paths) # :yield: path
    paths.collect!{|d| d.dup}
    while file = paths.shift
      catch(:prune) do
	yield file.dup.taint
        next unless File.exist? file
	begin
	  if File.lstat(file).directory? then
	    d = Dir.open(file)
	    begin
	      for f in d
		next if f == "." or f == ".."
		if File::ALT_SEPARATOR and file =~ /^(?:[\/\\]|[A-Za-z]:[\/\\]?)$/ then
		  f = file + f
		elsif file == "/" then
		  f = "/" + f
		else
		  f = File.join(file, f)
		end
		paths.unshift f.untaint
	      end
	    ensure
	      d.close
	    end
	  end
        rescue Errno::ENOENT, Errno::EACCES
	end
      end
    end
  end
  def prune
    throw :prune
  end
  module_function :find, :prune
end

example:
Code:
#gimme all graphics in ".\graphics\facesets\"
PATH = "Graphics/Faces/"
bitmaps = Array.new
Find.find(PATH) {|name| 
  unless File.directory?(name)  then
    bitmaps << RPG::Cache.load_bitmap(PATH, File.basename(name))
  end
}
 
but where should i put that? for example, where should i put it at this script that looks for the faces and such at Characters/Faces what i would like, is that this search the faces at "for example" Pictures/Faces:

Code:
#==============================================================================
# ** TDS Window_Base EDITS
#------------------------------------------------------------------------------
#  This class is for all in-game windows.
#  Change what you want if you know how
#==============================================================================

class Window_Base < Window
  
  #--------------------------------------------------------------------------
  # * Draw draw_actor_face
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------
  def draw_actor_battler(actor, x, y)
  face = RPG::Cache.character("Battler/" + actor.character_name, actor.character_hue)
  fw = face.width
  fh = face.height
  src_rect = Rect.new(0, 0, fw, fh)
  self.contents.blt(x - fw / 23, y - fh, face, src_rect)
  end
 
  def draw_actor_face(actor, x, y)
  face = RPG::Cache.picture("Faces/" + actor.character_name, actor.character_hue)
  fw = face.width
  fh = face.height
  src_rect = Rect.new(0, 0, fw, fh)
  self.contents.blt(x - fw / 23, y - fh, face, src_rect)
  end
  end
  
  #--------------------------------------------------------------------------
  # * Draw Parameter
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     type  : parameter type (0-6)
  #--------------------------------------------------------------------------
  def edited_draw_actor_parameter(actor, x, y, type)
    case type
    when 0
      parameter_name = 'Attack:' 
      parameter_value = actor.atk
    when 1
      parameter_name = 'Defense:'  
      parameter_value = actor.pdef
    when 2
      parameter_name = 'Magic Def:' 
      parameter_value = actor.mdef
    when 3
      parameter_name = 'Strength:' 
      parameter_value = actor.str
    when 4
      parameter_name = 'Dexterity:'
      parameter_value = actor.dex
    when 5
      parameter_name = 'Agility:'
      parameter_value = actor.agi
    when 6
      parameter_name = 'Intelligence:'
      parameter_value = actor.int
    end
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 120, 32, parameter_name,0,5)
    self.contents.font.color = normal_color
    self.contents.draw_text(x + 120 + 30, y, 36, 32, parameter_value.to_s,0,5)
  end


#==============================================================================
# ** TDS Window_Status
#------------------------------------------------------------------------------
#  This window displays full status specs on the status screen.
#  I just added a different display
#==============================================================================

class Window_Status < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     actor : actor
  #--------------------------------------------------------------------------
  def initialize(actor)
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    @actor = actor
    @type = 0    
    @show_faces = false #change this if you dont want faces
    @status_message = 'View player status, weapons etc.'
    refresh
  end
  
  #--------------------------------------------------------------------------
  # * Type Change
  #--------------------------------------------------------------------------    
  def type_change
    if @type == 0
      @type = 1
    else
      @type = 0
    end
    refresh
  end
    
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.draw_text(150, 0, 400, 32,@status_message.to_s,0,5)    
    
    draw_actor_face(@actor, 10, 85 + 64)
    draw_actor_battler(@actor, 85, 360 + 64) if @show_faces == false
    draw_actor_graphic(@actor, 0, 110) if @show_battler == true
    draw_actor_name(@actor, 105, 0 + 64)    
    draw_actor_class(@actor, 334, 64)
    
    draw_actor_level(@actor, 198, 64)
    draw_actor_state(@actor, 520, 64)
    
    draw_actor_hp(@actor, 100, 112 - 10 , 172)
    draw_actor_sp(@actor, 120, 144 - 10 , 172)
    
    edited_draw_actor_parameter(@actor, 0, 192, 0)
    edited_draw_actor_parameter(@actor, 0, 224, 1)
    edited_draw_actor_parameter(@actor, 0, 256, 2)
    
    edited_draw_actor_parameter(@actor, 0, 304 + 20 , 3)
    edited_draw_actor_parameter(@actor, 0, 336 + 20, 4)
    edited_draw_actor_parameter(@actor, 0, 368 + 20, 5)
    edited_draw_actor_parameter(@actor, 0, 400 + 20, 6)
    self.contents.font.color = system_color
    if @type == 0
     self.contents.draw_text(330, 130 + 50, 420, 36,'Weapons & Armor',0,5)  
    else
     self.contents.draw_text(325, 130 + 50, 420, 36,'Elemental Resistance',0,5 )  
    end
      
    self.contents.draw_text(32, 0, 400, 32,'Status',0,5 )    
    self.contents.draw_text(460, 64, 80, 32, "State:",0,5)      
    self.contents.draw_text(275, 64, 80, 32, "Class:",0,5)  
    self.contents.draw_text(360, 112 - 5, 80, 32, "Exp:",0,5)
    self.contents.draw_text(380, 144 - 5, 80, 32, "Next lv:",0,5)
    self.contents.font.color = normal_color
    self.contents.draw_text(360 + 80, 112 - 5, 84, 32, @actor.exp_s,0,5)
    self.contents.draw_text(380 + 80, 144 - 5, 84, 32, @actor.next_rest_exp_s,0,5)
    self.contents.font.color = system_color

    
    draw_actor_element_radar_graph(@actor, 270, 210, radius = 72) if @type == 1       

  if @type == 0
     self.contents.draw_text(0 + 210, 188 + 36, 92, 32, $data_system.words.weapon + ":",0,5)
     self.contents.draw_text(0 + 210, 240 + 32, 92, 32, $data_system.words.armor1 + ":",0,5)
     self.contents.draw_text(0 + 210, 292 + 32, 92, 32, $data_system.words.armor2 + ":",0,5)
     self.contents.draw_text(0 + 210, 344 + 30, 92, 32, $data_system.words.armor3 + ":",0,5)
     self.contents.draw_text(0 + 210, 396 + 25, 99, 32, $data_system.words.armor4 + ":",0,5)
   end
if @type == 0   
     self.contents.font.color = normal_color
     if @actor.weapon_id == 0
       self.contents.draw_text(54 + 295, 188 + 36, 212, 32, "-nothing equiped-",0,5)
     else
       draw_item_name($data_weapons[@actor.weapon_id], 32  + 295, 188 + 36)
     end
     if @actor.armor1_id == 0
       self.contents.draw_text(54  + 295, 240 + 32, 212, 32, "-nothing equiped-",0,5)
     else
       draw_item_name($data_armors[@actor.armor1_id], 32  + 295, 240 + 32)
     end
     if @actor.armor2_id == 0
       self.contents.draw_text(54  + 295, 322, 212, 32, "-nothing equiped-",0,5)
     else
       draw_item_name($data_armors[@actor.armor2_id], 32  + 295, 322)
     end
     if @actor.armor3_id == 0
       self.contents.draw_text(54  + 295, 370, 212, 32, "-nothing equiped-",0,5)
     else
       draw_item_name($data_armors[@actor.armor3_id], 32  + 295, 373) 
     end
     if @actor.armor4_id == 0
       self.contents.draw_text(54  + 295, 422, 212, 30, "-nothing equiped-",0,5)
     else
       draw_item_name($data_armors[@actor.armor4_id], 32  + 295, 420)
     end
   end 
end
end 
  
  
  
#==============================================================================
# ** TDS Scene_Status
#------------------------------------------------------------------------------
#  This class performs status screen processing.
#==============================================================================

class Scene_Status
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     actor_index : actor index
  #--------------------------------------------------------------------------
  def initialize(actor_index = 0, equip_index = 0)
    @actor_index = actor_index
    @visible_windows = true
    @one_window = false #Change this to false if you want one full window
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Get actor
    @actor = $game_party.actors[@actor_index]
    # Make status window
    @status_window = Window_Status.new(@actor)
    @title_window = Window_Base.new(0,0, 150, 64)                
    @description_window = Window_Base.new(150,0, 490, 64)                
    @face_window = Window_Base.new(0,64, 640, 130)            
    @battlestats_window = Window_Base.new(0,130 + 64 , 220, 350 - 64)        
    if @one_window == true
       @full_window = Window_Base.new(220, 130 + 100 , 420, 250)        
     else      
      @weapon_window = Window_Base.new(220, 130 + 64 + 36 , 420, 50) 
      @armor1_window = Window_Base.new(220, 130 + 114 + 36 , 420, 50)
      @armor2_window = Window_Base.new(220, 130 + 164 + 36 , 420, 50)    
      @armor3_window = Window_Base.new(220, 130 + 214 + 36 , 420, 50)        
      @armor4_window = Window_Base.new(220, 130 + 264  + 36 , 420, 50) 
   end
    @weapon_armor_window = Window_Base.new(220, 130 + 64 , 420, 36)         
    @elemental_window = Window_Base.new(220, 130 + 100 , 420, 250) 
    @elemental_window.visible = false    
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @status_window.dispose
    @title_window.dispose               
    @description_window.dispose              
    @face_window.dispose            
    @battlestats_window.dispose 
    @weapon_armor_window.dispose
  
  if @elemental_window.visible
    @elemental_window.dispose
  end
  
  if @one_window == true
    @full_window.dispose      
  end

   if @visible_windows == true  && @one_window == false    
    @weapon_window.dispose       
    @armor1_window.dispose
    @armor2_window.dispose
    @armor3_window.dispose
    @armor4_window.dispose
  end
end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to menu screen
      $scene = Scene_Menu.new(3)
      return
    end
    
    if Input.trigger?(Input::C)
    $game_system.se_play($data_system.cursor_se)      
   @status_window.type_change
   if @visible_windows == true && @one_window == false
    @weapon_window.visible = false
    @armor1_window.visible = false
    @armor2_window.visible = false
    @armor3_window.visible = false
    @armor4_window.visible = false
    @elemental_window.visible = true
    @visible_windows = false      
    return
  end
  if @visible_windows == false
    @weapon_window.visible = true
    @armor1_window.visible = true
    @armor2_window.visible = true
    @armor3_window.visible = true
    @armor4_window.visible = true    
    @elemental_window.visible = false
    @visible_windows = true  
   return
end
return
end

    # If R button was pressed
    if Input.trigger?(Input::R)
      # Play cursor SE
      $game_system.se_play($data_system.cursor_se)
      # To next actor
      @actor_index += 1
      @actor_index %= $game_party.actors.size
      # Switch to different status screen
      $scene = Scene_Status.new(@actor_index)
      return
    end
    # If L button was pressed
    if Input.trigger?(Input::L)
      # Play cursor SE
      $game_system.se_play($data_system.cursor_se)
      # To previous actor
      @actor_index += $game_party.actors.size - 1
      @actor_index %= $game_party.actors.size
      # Switch to different status screen
      $scene = Scene_Status.new(@actor_index)
      return
    end
  end
end
 

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