Sha256: 93c1b862c1a846f77652e8ce199764ec175d94e23c3a8553337a9d3cb3e3fe75

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

module AdventureRL
  class Rectangle < Mask
    include Helpers::Error

    # Default settings for Rectangle.
    # <tt>settings</tt> passed to #new take precedence.
    DEFAULT_SETTINGS = Settings.new(
      color:   0xff_ffffff,
      z_index: 0,
      position: {
        x: 0,
        y: 0
      },
      size: {
        width:  128,
        height: 128
      },
      origin: {
        x: :left,
        y: :top
      }
    )

    # Initialize with a Settings object <tt>settings</tt>.
    def initialize settings = {}
      @settings = DEFAULT_SETTINGS.merge settings
      super @settings
      @color           = nil
      @color_temporary = nil
      @color_original  = @settings.get :color
      @z_index         = @settings.get :z_index
    end

    def set_color color
      @color = color
    end

    # Set the color only for the next frame.
    def set_temporary_color color
      @color_temporary = color
    end

    def get_color
      return @color_temporary || @color || @color_original
    end

    def reset_color
      @color = nil
    end

    def draw
      corner = get_corner :left, :top
      Gosu.draw_rect(
        corner.x, corner.y,
        get_size(:width), get_size(:height),
        get_color,
        @z_index
      )
      @color_temporary = nil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adventure_rl-0.0.2 lib/AdventureRL/Rectangle.rb
adventure_rl-0.0.1.pre.ld42 lib/AdventureRL/Rectangle.rb