Class: HitSq

Inherits:
Api show all
Defined in:
lib/api/hit_sq.rb

Overview

a pattern of hits to time a Snd

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Api

#<<, #>>, #parent

Constructor Details

#initializeHitSq

Returns a new instance of HitSq.



4
5
6
7
# File 'lib/api/hit_sq.rb', line 4

def initialize
  @hits=[]    
  super
end

Instance Attribute Details

#hitsObject

Returns the value of attribute hits.



3
4
5
# File 'lib/api/hit_sq.rb', line 3

def hits
  @hits
end

Instance Method Details

#countObject

return number of hits



57
58
59
# File 'lib/api/hit_sq.rb', line 57

def count
  hits.count
end

#eqly_spaced(possible_hits = 4, chance = 1, ignore_first = 0, ignore_last = 0) ⇒ Object

Adds into #hits.

possible_hits

number of hits that can occur. Must be int

chance

chance a hit will be included. range: 0 to 1

ignore_first

skip the first n possible hits

ignore_first

skip the last n possible hits

e.g. disperse_hits(16,1,4,4) makes this pattern [-|-|-|-|+|+|+|+|+|+|+|+|-|-|-|-|]



47
48
49
50
51
52
53
54
55
# File 'lib/api/hit_sq.rb', line 47

def eqly_spaced(possible_hits = 4, chance = 1, ignore_first=0, ignore_last=0)
  possible_hits.times do |i|
    if ignore_first <= i && possible_hits - ignore_last > i
      delay = i/possible_hits.to_f
      @hits.push delay if (rand + chance >= 1)
    end
  end
  self
end

#move(val = 0.5) ⇒ Object

Shift all hits by val, no validation atm



61
62
63
64
65
66
67
68
# File 'lib/api/hit_sq.rb', line 61

def move(val=0.5)
  self.hits.collect! {|x| 
    z = (x+val)
    z = (z*1000).round / 1000.0 # rounding
    x = z
  } # delay all
  self
end