Class: BaseObject
- Inherits:
-
Object
- Object
- BaseObject
- Defined in:
- lib/rutui/objects.rb
Overview
Base Object Class Dynamic Objects that get drawn on the Screen This class is used as basic class for other objects
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#obj ⇒ Object
Returns the value of attribute obj.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#each ⇒ Object
"special" each methods for objects.
-
#get_pixel(x, y) ⇒ Object
Get pixel by position.
-
#initialize(options) ⇒ BaseObject
constructor
Ex.: BaseObject.new({ :x => 1, :y => 20, :obj => [[Pixel.new(1),Pixel.new(2,4,"#")]] }).
-
#move(x, y) ⇒ Object
Move object X and Y (modifiers like: -2, 2).
-
#set_pixel(x, y, pixel) ⇒ Object
Set pixel on position on object.
-
#set_position(x, y) ⇒ Object
Set object position X Y.
Constructor Details
#initialize(options) ⇒ BaseObject
Ex.: BaseObject.new({ :x => 1, :y => 20, :obj => [[Pixel.new(1),Pixel.new(2,4,"#")]] })
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rutui/objects.rb', line 10 def initialize @obj = [:obj] @obj = Array.new(height){ Array.new(width) } if @obj.nil? @x = [:x] @y = [:y] @x = 1 if @x.nil? @y = 1 if @y.nil? @height = @obj.size @width = @obj[0].size end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
8 9 10 |
# File 'lib/rutui/objects.rb', line 8 def height @height end |
#obj ⇒ Object
Returns the value of attribute obj.
8 9 10 |
# File 'lib/rutui/objects.rb', line 8 def obj @obj end |
#width ⇒ Object
Returns the value of attribute width.
8 9 10 |
# File 'lib/rutui/objects.rb', line 8 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
8 9 10 |
# File 'lib/rutui/objects.rb', line 8 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
8 9 10 |
# File 'lib/rutui/objects.rb', line 8 def y @y end |
Instance Method Details
#each ⇒ Object
"special" each methods for objects
37 38 39 40 41 42 43 |
# File 'lib/rutui/objects.rb', line 37 def each @obj.each_with_index do |row,row_count| row.each_with_index do |pixel,col_count| yield row_count, col_count, pixel end end end |
#get_pixel(x, y) ⇒ Object
Get pixel by position
32 33 34 |
# File 'lib/rutui/objects.rb', line 32 def get_pixel x, y @obj[x][y] if !@obj[x].nil? and !@obj[x][y].nil? end |
#move(x, y) ⇒ Object
Move object X and Y (modifiers like: -2, 2)
24 |
# File 'lib/rutui/objects.rb', line 24 def move x, y; @x += x; @y += y; end |
#set_pixel(x, y, pixel) ⇒ Object
Set pixel on position on object
28 29 30 |
# File 'lib/rutui/objects.rb', line 28 def set_pixel x, y, pixel @obj[x][y] = pixel if !@obj[x].nil? and !@obj[x][y].nil? end |
#set_position(x, y) ⇒ Object
Set object position X Y
26 |
# File 'lib/rutui/objects.rb', line 26 def set_position x, y; @x = x; @y = y; end |