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.

Help with modifing a script written for me here.

With the help of this forum I got a script for both RMXP and RMVX to change the scale of a sprite. The code was written to make things smaller but I learned how to modify it to also make things bigger. I was wondering how to combine the 2 into one script or something so I can do either one at any time in the 'game' I am working on.

Here is the script as its is normally written.

Code:
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
#  This class deals with characters. It's used as a superclass for the
#  Game_Player and Game_Event classes.
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias_method :algn_shrinking_game_character_initialize, :initialize
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :shrinking
  attr_reader :growing
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    algn_shrinking_game_character_initialize
    @shrinking = nil
  end
  #--------------------------------------------------------------------------
  # * Shrinky Dink Mode On
  #--------------------------------------------------------------------------
  def shrink
    @shrinking = true
  end
  #--------------------------------------------------------------------------
  # * Get Bigger Quicker
  #--------------------------------------------------------------------------
  def unshrink
    @shrinking = nil
  end
end

#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
#  This sprite is used to display the character. It observes the Game_Character
#  class and automatically changes sprite conditions.
#==============================================================================

class Sprite_Character < RPG::Sprite
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias_method :algn_shrinking_sprite_character_update, :update
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  SHRINK_RATE = 0.02 # Translates to a percentage of a 100%
  SMALLEST_SIZE = 0.20 # The smallest percentage size the character can be.
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    algn_shrinking_sprite_character_update

    # If the character is shrinking.
    if @character.shrinking
      # Test to see if we should continue to shrink.
      if self.zoom_x > SMALLEST_SIZE
        self.zoom_x -= SHRINK_RATE
        self.zoom_y -= SHRINK_RATE
      else
        # Just in case the rate is uneven.
        self.zoom_x = SMALLEST_SIZE
        self.zoom_y = SMALLEST_SIZE
      end
    else
      # If we are still smaller than 1.0
      if self.zoom_x < 1.0
        self.zoom_x += SHRINK_RATE
        self.zoom_y += SHRINK_RATE
      else
        # Just in case the rate is uneven.
        self.zoom_x = 1.0
        self.zoom_y = 1.0
      end
    end
  end
end

I also know if you change the SMALLEST_SCALE to a number larger then 1.00 it makes the character larger. So as I said my question is how to have both a shrinking and giant code at the same time so I can either make a giant or a shrunk character in the same script.
 

khmp

Sponsor

Haha I wrote that. Ok you want to keep the shrinking code but add in giantizing(word?).

Code:
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
#  This class deals with characters. It's used as a superclass for the
#  Game_Player and Game_Event classes.
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias_method :algn_shrinking_game_character_initialize, :initialize
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :size_setting
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    algn_shrinking_game_character_initialize
    size_setting = 1
  end
  #--------------------------------------------------------------------------
  # * Change the Size Setting
  #--------------------------------------------------------------------------
  def size_setting=(size)
    return unless size.is_a?(Integer)
    return if size < 0 || size > 2
    @size_setting = size
  end
end

#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
#  This sprite is used to display the character. It observes the Game_Character
#  class and automatically changes sprite conditions.
#==============================================================================

class Sprite_Character < RPG::Sprite
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias_method :algn_shrinking_sprite_character_update, :update
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  SIZE_SETTINGS = 
  {
    0 => 0.2,     # Miniature size
    1 => 1.0,     # Normal size
    2 => 2.0      # Giant size
  }
  SIZE_RATE = 0.02 # Translates to a percentage of a 100 (Default 2%)
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    algn_shrinking_sprite_character_update

    case @character.size_setting
    when 0
      if self.zoom_x != SIZE_SETTINGS[0]
        if self.zoom_x > SIZE_SETTINGS[0]
          self.zoom_x -= SIZE_RATE
          self.zoom_y -= SIZE_RATE
        end
      end
    when 1
      if self.zoom_x != SIZE_SETTINGS[1]
        if self.zoom_x < SIZE_SETTINGS[1]
          self.zoom_x += SIZE_RATE
          self.zoom_y += SIZE_RATE
        elsif self.zoom_x > SIZE_SETTINGS[1]
          self.zoom_x -= SIZE_RATE
          self.zoom_y -= SIZE_RATE
        end
      end
    when 2
      if self.zoom_x != SIZE_SETTINGS[2]
        if self.zoom_x < SIZE_SETTINGS[2]
          self.zoom_x += SIZE_RATE
          self.zoom_y += SIZE_RATE
        end
      end
    end
  end
end

Now the syntax goes like this:
0, 1, 2 are valid size numbers. (0 is mini mode, 1 is normal size, 2 is giant)
Code:
$game_player.size_setting = 1
 

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