Class: PirateGame::Wave

Inherits:
WavingItem show all
Defined in:
lib/pirate_game/wave.rb

Constant Summary collapse

COLORS =
PirateGame::Boot::BLUE_COLORS + PirateGame::Boot::GREEN_COLORS
OFFSET =
210
SIZE =
40

Instance Attribute Summary

Attributes inherited from WavingItem

#speed

Instance Method Summary collapse

Methods inherited from WavingItem

#waving_offset

Constructor Details

#initialize(shoes, top) ⇒ Wave

Returns a new instance of Wave.



8
9
10
11
12
13
14
15
# File 'lib/pirate_game/wave.rb', line 8

def initialize shoes, top
  super rand(40), SIZE, 5

  @shoes = shoes
  @top   = top + OFFSET
  @arcs  = []
  @clear = @shoes.rgb 0, 0, 0, 0
end

Instance Method Details

#animate(frame) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/pirate_game/wave.rb', line 17

def animate frame
  top_offset, left_offset = waving_offset frame

  @arcs.each do |arc, top, left|
    arc.move top + top_offset, left + left_offset
  end
end

#drawObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pirate_game/wave.rb', line 25

def draw
  for i in (-3..12) do
    for j in [0,2,4] do
      color_index = (@seed + j) % COLORS.size
      @shoes.fill @clear
      @shoes.stroke COLORS[color_index]
      @shoes.strokewidth 3
      arc_dif = (j/360.0)*Shoes::TWO_PI

      top  = i * SIZE - j
      left = @top + j

      arc = @shoes.arc(i * SIZE - j, @top + j, SIZE + j, SIZE + j,
                       0 + arc_dif, Shoes::PI - arc_dif)

      @arcs << [arc, top, left]
    end
  end
end