Class: Nyan::Sprite
Instance Attribute Summary collapse
-
#blk ⇒ Object
readonly
Returns the value of attribute blk.
-
#frame_index ⇒ Object
Returns the value of attribute frame_index.
-
#frames ⇒ Object
Returns the value of attribute frames.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #animate! ⇒ Object
- #bottom ⇒ Object
- #frame ⇒ Object
- #height ⇒ Object
-
#initialize(options = {}, &blk) ⇒ Sprite
constructor
A new instance of Sprite.
- #left ⇒ Object
- #lines ⇒ Object
- #right ⇒ Object
- #top ⇒ Object
- #width ⇒ Object
Methods included from Shape
Constructor Details
#initialize(options = {}, &blk) ⇒ Sprite
Returns a new instance of Sprite.
9 10 11 12 13 14 15 16 17 |
# File 'lib/nyan/sprite.rb', line 9 def initialize( = {}, &blk) @options = self.x = @options.fetch(:x, 0) self.y = @options.fetch(:y, 0) self.z = @options.fetch(:z, 0) self.frames = @options.fetch(:frames, []) self.frame_index = @options.fetch(:frame_index, 0) @blk = blk || @options[:animation] end |
Instance Attribute Details
#blk ⇒ Object (readonly)
Returns the value of attribute blk.
7 8 9 |
# File 'lib/nyan/sprite.rb', line 7 def blk @blk end |
#frame_index ⇒ Object
Returns the value of attribute frame_index.
6 7 8 |
# File 'lib/nyan/sprite.rb', line 6 def frame_index @frame_index end |
#frames ⇒ Object
Returns the value of attribute frames.
6 7 8 |
# File 'lib/nyan/sprite.rb', line 6 def frames @frames end |
#x ⇒ Object
Returns the value of attribute x.
6 7 8 |
# File 'lib/nyan/sprite.rb', line 6 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
6 7 8 |
# File 'lib/nyan/sprite.rb', line 6 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
6 7 8 |
# File 'lib/nyan/sprite.rb', line 6 def z @z end |
Instance Method Details
#<=>(other) ⇒ Object
56 57 58 |
# File 'lib/nyan/sprite.rb', line 56 def <=>(other) z <=> other.z end |
#animate! ⇒ Object
27 28 29 30 |
# File 'lib/nyan/sprite.rb', line 27 def animate! self.frame_index = (self.frame_index + 1) % frames.length self.instance_eval(&blk) if blk end |
#bottom ⇒ Object
44 45 46 |
# File 'lib/nyan/sprite.rb', line 44 def bottom y + height end |
#frame ⇒ Object
19 20 21 |
# File 'lib/nyan/sprite.rb', line 19 def frame frames[frame_index] end |
#height ⇒ Object
32 33 34 |
# File 'lib/nyan/sprite.rb', line 32 def height @height ||= frame.lines.count end |
#left ⇒ Object
48 49 50 |
# File 'lib/nyan/sprite.rb', line 48 def left x end |
#lines ⇒ Object
23 24 25 |
# File 'lib/nyan/sprite.rb', line 23 def lines frame.lines end |
#right ⇒ Object
52 53 54 |
# File 'lib/nyan/sprite.rb', line 52 def right x + width end |
#top ⇒ Object
40 41 42 |
# File 'lib/nyan/sprite.rb', line 40 def top y end |
#width ⇒ Object
36 37 38 |
# File 'lib/nyan/sprite.rb', line 36 def width @width ||= frame.lines.map { |l| l.chomp.unansi.length }.max end |