Class: CyberarmEngine::Paint

Inherits:
Object
  • Object
show all
Defined in:
lib/cyberarm_engine/background.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(background) ⇒ Paint

Returns a new instance of Paint.



125
126
127
# File 'lib/cyberarm_engine/background.rb', line 125

def initialize(background)
  set(background)
end

Instance Attribute Details

#bottom_leftObject

Returns the value of attribute bottom_left.



123
124
125
# File 'lib/cyberarm_engine/background.rb', line 123

def bottom_left
  @bottom_left
end

#bottom_rightObject

Returns the value of attribute bottom_right.



123
124
125
# File 'lib/cyberarm_engine/background.rb', line 123

def bottom_right
  @bottom_right
end

#top_leftObject

Returns the value of attribute top_left.



123
124
125
# File 'lib/cyberarm_engine/background.rb', line 123

def top_left
  @top_left
end

#top_rightObject

Returns the value of attribute top_right.



123
124
125
# File 'lib/cyberarm_engine/background.rb', line 123

def top_right
  @top_right
end

Instance Method Details

#set(background) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/cyberarm_engine/background.rb', line 129

def set(background)
  @background = background

  if background.is_a?(Numeric)
    @top_left     = background
    @top_right    = background
    @bottom_left  = background
    @bottom_right = background
  elsif background.is_a?(Gosu::Color)
    @top_left     = background
    @top_right    = background
    @bottom_left  = background
    @bottom_right = background
  elsif background.is_a?(Array)
    if background.size == 1
      set(background.first)
    elsif background.size == 2
      @top_left     = background.first
      @top_right    = background.last
      @bottom_left  = background.first
      @bottom_right = background.last
    elsif background.size == 4
      @top_left     = background[0]
      @top_right    = background[1]
      @bottom_left  = background[2]
      @bottom_right = background[3]
    else
      raise ArgumentError, "background array was empty or had wrong number of elements (expected 2 or 4 elements)"
    end
  elsif background.is_a?(Hash)
    @top_left     = background[:top_left]
    @top_right    = background[:top_right]
    @bottom_left  = background[:bottom_left]
    @bottom_right = background[:bottom_right]
  elsif background.is_a?(Range)
    set([background.begin, background.begin, background.end, background.end])
  else
    raise ArgumentError, "background '#{background.inspect}' of type '#{background.class}' was not able to be processed"
  end
end