Class: Nyan::Stage
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #add_sprite(sprite) ⇒ Object
- #animate! ⇒ Object
- #bottom ⇒ Object
- #clean! ⇒ Object
- #coloured? ⇒ Boolean
-
#initialize(options = {}) ⇒ Stage
constructor
A new instance of Stage.
- #left ⇒ Object
- #play! ⇒ Object
- #remove_sprite(sprite) ⇒ Object
- #render ⇒ Object
- #right ⇒ Object
- #sprites ⇒ Object
- #top ⇒ Object
Methods included from Shape
Constructor Details
#initialize(options = {}) ⇒ Stage
Returns a new instance of Stage.
7 8 9 10 11 12 13 |
# File 'lib/nyan/stage.rb', line 7 def initialize( = {}) @output = .fetch(:output, $stdout) @height = .fetch(:height, ANSI::Terminal.terminal_height) @width = .fetch(:width, ANSI::Terminal.terminal_width) @coloured = .fetch(:coloured, true) clear_buffer end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
5 6 7 |
# File 'lib/nyan/stage.rb', line 5 def height @height end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
5 6 7 |
# File 'lib/nyan/stage.rb', line 5 def output @output end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
5 6 7 |
# File 'lib/nyan/stage.rb', line 5 def width @width end |
Instance Method Details
#add_sprite(sprite) ⇒ Object
19 20 21 |
# File 'lib/nyan/stage.rb', line 19 def add_sprite(sprite) self.sprites.push(sprite) end |
#animate! ⇒ Object
39 40 41 |
# File 'lib/nyan/stage.rb', line 39 def animate! sprites.each { |s| s.animate! } end |
#bottom ⇒ Object
51 52 53 |
# File 'lib/nyan/stage.rb', line 51 def bottom height - 1 end |
#clean! ⇒ Object
43 44 45 |
# File 'lib/nyan/stage.rb', line 43 def clean! sprites.delete_if { |s| s.outside?(self) } end |
#coloured? ⇒ Boolean
63 64 65 |
# File 'lib/nyan/stage.rb', line 63 def coloured? @coloured end |
#left ⇒ Object
55 56 57 |
# File 'lib/nyan/stage.rb', line 55 def left 0 end |
#play! ⇒ Object
27 28 29 30 31 |
# File 'lib/nyan/stage.rb', line 27 def play! render animate! clean! end |
#remove_sprite(sprite) ⇒ Object
23 24 25 |
# File 'lib/nyan/stage.rb', line 23 def remove_sprite(sprite) self.sprites.delete(sprite) end |
#render ⇒ Object
33 34 35 36 37 |
# File 'lib/nyan/stage.rb', line 33 def render clear_buffer sprites.sort.reverse.each { |s| write_to_buffer(s) } print_buffer end |
#right ⇒ Object
59 60 61 |
# File 'lib/nyan/stage.rb', line 59 def right width - 1 end |
#sprites ⇒ Object
15 16 17 |
# File 'lib/nyan/stage.rb', line 15 def sprites @sprites ||= [] end |
#top ⇒ Object
47 48 49 |
# File 'lib/nyan/stage.rb', line 47 def top 0 end |