Class: Diamante::Scene::Space::Star

Inherits:
Object
  • Object
show all
Defined in:
lib/diamante/scenes/space.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStar

Returns a new instance of Star.



36
37
38
39
40
41
42
43
# File 'lib/diamante/scenes/space.rb', line 36

def initialize
  @pastel = Pastel.new
  @term = ANSI.new
  @char = @pastel.white.bold("*")
  @x = 0
  @y = 0
  init
end

Instance Attribute Details

#charObject (readonly)

Returns the value of attribute char.



32
33
34
# File 'lib/diamante/scenes/space.rb', line 32

def char
  @char
end

#xObject (readonly)

Returns the value of attribute x.



33
34
35
# File 'lib/diamante/scenes/space.rb', line 33

def x
  @x
end

#yObject (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

#initObject



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

#renderObject



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

#updateObject



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