Class: PirateGame::BridgeButton

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

Constant Summary collapse

TOP =
150

Instance Attribute Summary

Attributes inherited from WavingItem

#speed

Instance Method Summary collapse

Methods inherited from WavingItem

#waving_offset

Constructor Details

#initialize(shoes, text, row, column, &click_action) ⇒ BridgeButton

Returns a new instance of BridgeButton.


5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/pirate_game/bridge_button.rb', line 5

def initialize shoes, text, row, column, &click_action
  super rand(90), 10, 4

  @shoes        = shoes
  @text         = text
  @row          = row
  @column       = column
  @click_action = click_action

  @button = nil
  @left   = nil
  @top    = nil
end

Instance Method Details

#animate(frame) ⇒ Object


19
20
21
22
23
# File 'lib/pirate_game/bridge_button.rb', line 19

def animate frame
  top_offset, left_offset = waving_offset frame

  @button.move @top + top_offset, @left + left_offset
end

#drawObject


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pirate_game/bridge_button.rb', line 25

def draw
  width = @shoes.app.width
  chunk = width / 6

  # something is wrong in my head, these are switched
  @top  = chunk / 3 + 2 * @column * chunk
  @left = TOP + @row * 40

  @button = @shoes.button @text, &@click_action
  @button.move @left, @top
end