Class: Diamante::Scene::Space::Star
- Inherits:
-
Object
- Object
- Diamante::Scene::Space::Star
- Defined in:
- lib/diamante/scenes/space.rb
Instance Attribute Summary collapse
-
#char ⇒ Object
readonly
Returns the value of attribute char.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #init ⇒ Object
-
#initialize ⇒ Star
constructor
A new instance of Star.
- #render ⇒ Object
- #update ⇒ Object
Constructor Details
Instance Attribute Details
#char ⇒ Object (readonly)
Returns the value of attribute char.
32 33 34 |
# File 'lib/diamante/scenes/space.rb', line 32 def char @char end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
33 34 35 |
# File 'lib/diamante/scenes/space.rb', line 33 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
34 35 36 |
# File 'lib/diamante/scenes/space.rb', line 34 def y @y end |
Instance Method Details
#init ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/diamante/scenes/space.rb', line 45 def init @last_y = @y @last_x = @x @y = rand(@term.height).to_f @x = rand(@term.width).to_f @speed = rand * 0.000000001 end |
#render ⇒ Object
66 67 68 69 70 71 |
# File 'lib/diamante/scenes/space.rb', line 66 def render return if (@x - @last_x + @y - @last_y).zero? ANSI.print_text_at(@last_y.to_i, @last_x.to_i + 1, " ") text = @pastel.white.bold(@char) ANSI.print_text_at(@y.to_i, @x.to_i + 1, text) end |
#update ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/diamante/scenes/space.rb', line 53 def update sleep 0.1 @last_y = @y @last_x = @x @x += @x + @speed * 0.000000000001 if @x >= @term.width ANSI.print_text_at(@last_y.to_i, @last_x.to_i + 1, " ") @y = rand(@term.height).to_f @x = 0 @speed = rand * 0.00000001 end end |