Class: Cursetank::Bubble

Inherits:
TankObject show all
Defined in:
lib/cursetank/tank_objects/bubble.rb

Instance Method Summary collapse

Methods inherited from TankObject

#set_direction

Constructor Details

#initialize(args = {}) ⇒ Bubble

Returns a new instance of Bubble.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cursetank/tank_objects/bubble.rb', line 8

def initialize(args={})
  super(args)
  @height    = 2
  @width     = 3
  @pos_x     = args.fetch(:pos_x)
  @pos_y     = @win.maxy - @height - rand(1..20)
  @swin      = @win.subwin(@height, @width, 0, 0)
  @color     = args.fetch(:color, 1)
  @speed     = 0.2
  @frame     = rand(0..frames.length - 1)
  @bubbles    = args.fetch(:bubbles)
end

Instance Method Details

#drawObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cursetank/tank_objects/bubble.rb', line 31

def draw
  @frame += @speed
  @frame = 0 if @frame > @maxframes - 1
  @swin.setpos(0, 0)
  @swin.move(@pos_y, @pos_x)
  frame  = frames[@frame.round.to_i]
  @swin.attron(Curses.color_pair(@color)){
    @swin.addstr(frame)
  }
  @swin.refresh()
  @pos_y += @speed * -1

  @bubbles.delete(self) if @pos_y <= 0

end

#framesObject



21
22
23
24
25
26
27
28
29
# File 'lib/cursetank/tank_objects/bubble.rb', line 21

def frames
  [".O
o *",
   ".
..o",
   ".o
."
   ]
end