Class: HarlemBits::Harlem

Inherits:
Object
  • Object
show all
Defined in:
lib/harlem_bits/harlem.rb

Instance Method Summary collapse

Constructor Details

#initialize(width, height) ⇒ Harlem

Returns a new instance of Harlem.



3
4
5
6
# File 'lib/harlem_bits/harlem.rb', line 3

def initialize(width, height)
  @arena = Arena.new width, height
  @alive = true
end

Instance Method Details

#killObject



8
9
10
# File 'lib/harlem_bits/harlem.rb', line 8

def kill
  @alive = false
end

#startObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/harlem_bits/harlem.rb', line 12

def start
  start_t = Time.now.to_f
  last_t = Time.now.to_i
  frame = 0
  switched = false
  
  while @alive
    cur_t = Time.now.to_f
    delta = cur_t - start_t

    @arena.clear      
    @arena.center.switch if delta % 2.0 == 0 || (delta % 2.0) / 2.0 > 0.3
    @arena.random! if delta >= (DURATION / 2) + 1
    @arena.draw

    break if delta > DURATION
    sleep 1/FRAME_RATE
  end
end