Class: AdventureRL::Rectangle

Inherits:
Mask show all
Includes:
Helpers::Error
Defined in:
lib/AdventureRL/Rectangle.rb

Direct Known Subclasses

Textbox

Constant Summary collapse

DEFAULT_SETTINGS =

Default settings for Rectangle. settings passed to #new take precedence.

Settings.new(
  color:   0xff_ffffff,
  z_index: 0,
  position: {
    x: 0,
    y: 0
  },
  size: {
    width:  128,
    height: 128
  },
  origin: {
    x: :left,
    y: :top
  }
)

Constants included from Helpers::Error

Helpers::Error::PADDING, Helpers::Error::STACK_TRACE_PADDING, Helpers::Error::STACK_TRACE_SIZE

Constants inherited from Mask

Mask::MASKS

Constants inherited from Point

Point::POINTS

Instance Method Summary collapse

Methods included from Helpers::Error

directory_exists?, error, error_no_directory, error_no_file, file_exists?

Methods inherited from Mask

#assign_to, #assigned_to?, #collides_with?, #collides_with_hash?, #collides_with_mask?, #collides_with_point?, #get_assigned, #get_center, #get_corner, #get_layer, #get_mask, #get_origin, #get_real_center, #get_real_corner, #get_real_side, #get_real_sides, #get_side, #get_sides, #get_size, #has_layer?, #has_mask?, #set_layer, #set_size

Methods inherited from Point

#assign_to, #assigned_to?, #collides_with?, #collides_with_hash?, #collides_with_mask?, #collides_with_point?, #get_assigned, #get_layer, #get_point, #get_position, #get_real_point, #get_real_position, #has_layer?, #has_point?, #keys, #move_by, #set_layer, #set_position, #values, #x, #y

Constructor Details

#initialize(settings = {}) ⇒ Rectangle

Initialize with a Settings object settings.



25
26
27
28
29
30
31
32
# File 'lib/AdventureRL/Rectangle.rb', line 25

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

Instance Method Details

#drawObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/AdventureRL/Rectangle.rb', line 51

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

#get_colorObject



43
44
45
# File 'lib/AdventureRL/Rectangle.rb', line 43

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

#reset_colorObject



47
48
49
# File 'lib/AdventureRL/Rectangle.rb', line 47

def reset_color
  @color = nil
end

#set_color(color) ⇒ Object



34
35
36
# File 'lib/AdventureRL/Rectangle.rb', line 34

def set_color color
  @color = color
end

#set_temporary_color(color) ⇒ Object

Set the color only for the next frame.



39
40
41
# File 'lib/AdventureRL/Rectangle.rb', line 39

def set_temporary_color color
  @color_temporary = color
end