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.

Red Color on Game_player

cayoda

Member

I need a code to change the character color to Red like a aura

Example:

    |    O  |
    |  |<- Char  |
    |  |  | -> red aura on char
    | | | | || -> Red aura on char


Thanks sorry for my bad Char =) and my bad english =X
 
Code:
#==============================================================================
# ** Character Auras
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1.0
# 2008-09-20
#==============================================================================

#==============================================================================
# ** Game_Character
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :aura_on
  attr_accessor :aura_color
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias_method :seph_sprchraura_gmchr_init, :initialize
  def initialize
    seph_sprchraura_gmchr_init
    @aura_on = self.is_a?(Game_Player) ? true : false
    @aura_color = Color.new(255, 0, 0)
  end
end

#==============================================================================
# ** Sprite_Character
#==============================================================================

class Sprite_Character < RPG::Sprite
  #--------------------------------------------------------------------------
  # * Clear color
  #--------------------------------------------------------------------------
  Clear_Color = Color.new(255, 255, 255, 0)
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  alias_method :seph_sprchraura_sprchr_update, :update
  def update
    # Check to see if aura needs update
    need_aura_updated = @character != nil && 
      (@aura_on != @character.aura_on ||
       @tile_id != @character.tile_id ||
       @character_name != @character.character_name ||
       @character_hue != @character.character_hue)
    # Original update
    seph_sprchraura_sprchr_update
    # Update aura if needs it
    update_aura if need_aura_updated
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update_aura
    # If nil and not on
    if @aura_on == nil && @character.aura_on != true
      @aura_on == @character.aura_on
      return
    end
    # If now off
    if @aura_on && @character.aura_on != true
      @aura_on == @character.aura_on
      self.bitmap = RPG::Cache.character(@character.character_name,
        @character.character_hue)
      # Set rectangular transfer
      sx = @character.pattern * @cw
      sy = (@character.direction - 2) / 2 * @ch
      self.src_rect.set(sx, sy, @cw, @ch)
      return
    end
    # Turn on
    @aura_on = true
    # Dup bitmap
    self.bitmap = self.bitmap.dup
    # Pass through bitmap
    for x in 0...bitmap.width
      for y in 0...bitmap.height
        # Get pixel
        pixel = bitmap.get_pixel(x, y)
        # Skip if not clear pixel
        next unless pixel == Clear_Color
        # Collect surrounding pixels
        pixels = {}
        pixels[[x - 1, y]] = bitmap.get_pixel(x - 1, y)
        pixels[[x + 1, y]] = bitmap.get_pixel(x + 1, y)
        pixels[[x, y - 1]] = bitmap.get_pixel(x, y - 1)
        pixels[[x, y + 1]] = bitmap.get_pixel(x, y + 1)
        # Pass through each surrounding pixel
        pixels.each do |loc, p|
          # If not clear color or aura color
          if p != Clear_Color && p != @character.aura_color
            # Draw aura pixel
            bitmap.set_pixel(loc[0], loc[1], @character.aura_color)
          end
        end
      end
    end
  end
end

To turn it on and off:
Code:
game_character.aura_on = true or false
# where game_character:
# events: $game_map.events[event_id]
# player: $game_player[

To change color:
Code:
game_character.aura_color = Color.new(red, green, blue, opacity)
 

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