Class: Cursetank::Octopus
- Inherits:
-
TankObject
- Object
- TankObject
- Cursetank::Octopus
- Defined in:
- lib/cursetank/tank_objects/octopus.rb
Instance Method Summary collapse
- #draw ⇒ Object
- #frames ⇒ Object
-
#initialize(args = {}) ⇒ Octopus
constructor
A new instance of Octopus.
Methods inherited from TankObject
Constructor Details
#initialize(args = {}) ⇒ Octopus
Returns a new instance of Octopus.
8 9 10 11 12 13 14 15 |
# File 'lib/cursetank/tank_objects/octopus.rb', line 8 def initialize(args={}) super(args) @height = 5 @width = 8 @swin = @win.subwin(@height, @width, 0, 0) @color = args.fetch(:color, 1) @speed = args.fetch(:speed, 0.1) end |
Instance Method Details
#draw ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cursetank/tank_objects/octopus.rb', line 36 def draw set_direction @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) } change_col = rand(10) @pos_y += @speed * @dir_down @pos_x += @speed * @dir_right if change_col == 7 @swin.refresh() end |
#frames ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cursetank/tank_objects/octopus.rb', line 17 def frames # credit to (hh) from http://ascii.co.uk/art/octopus octopus_frame1 = <<-OCTOPUS_FRAME1 ,---. ( @ @ ) ).-.( '/|||\\` '|` OCTOPUS_FRAME1 octopus_frame2 = <<-OCTOPUS_FRAME2 ,---. ( @ @ ) ).-.( \\|||/ |'| OCTOPUS_FRAME2 [octopus_frame1, octopus_frame2] end |