Class: Nyan::Stage
Constant Summary collapse
- SPACE =
"\x20"
- NOTHING =
""
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.
10 11 12 13 14 15 16 |
# File 'lib/nyan/stage.rb', line 10 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.
8 9 10 |
# File 'lib/nyan/stage.rb', line 8 def height @height end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
8 9 10 |
# File 'lib/nyan/stage.rb', line 8 def output @output end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
8 9 10 |
# File 'lib/nyan/stage.rb', line 8 def width @width end |
Instance Method Details
#add_sprite(sprite) ⇒ Object
22 23 24 |
# File 'lib/nyan/stage.rb', line 22 def add_sprite(sprite) self.sprites.push(sprite) end |
#animate! ⇒ Object
42 43 44 |
# File 'lib/nyan/stage.rb', line 42 def animate! sprites.each { |s| s.animate! } end |
#bottom ⇒ Object
54 55 56 |
# File 'lib/nyan/stage.rb', line 54 def bottom height - 1 end |
#clean! ⇒ Object
46 47 48 |
# File 'lib/nyan/stage.rb', line 46 def clean! sprites.delete_if { |s| s.outside?(self) } end |
#coloured? ⇒ Boolean
66 67 68 |
# File 'lib/nyan/stage.rb', line 66 def coloured? @coloured end |
#left ⇒ Object
58 59 60 |
# File 'lib/nyan/stage.rb', line 58 def left 0 end |
#play! ⇒ Object
30 31 32 33 34 |
# File 'lib/nyan/stage.rb', line 30 def play! render animate! clean! end |
#remove_sprite(sprite) ⇒ Object
26 27 28 |
# File 'lib/nyan/stage.rb', line 26 def remove_sprite(sprite) self.sprites.delete(sprite) end |
#render ⇒ Object
36 37 38 39 40 |
# File 'lib/nyan/stage.rb', line 36 def render clear_buffer sprites.sort.each { |s| write_to_buffer(s) } print_buffer end |
#right ⇒ Object
62 63 64 |
# File 'lib/nyan/stage.rb', line 62 def right width - 1 end |
#sprites ⇒ Object
18 19 20 |
# File 'lib/nyan/stage.rb', line 18 def sprites @sprites ||= [] end |
#top ⇒ Object
50 51 52 |
# File 'lib/nyan/stage.rb', line 50 def top 0 end |