Class: Cursetank::BasicFish
- Inherits:
-
TankObject
- Object
- TankObject
- Cursetank::BasicFish
- Defined in:
- lib/cursetank/tank_objects/basic_fish.rb
Instance Method Summary collapse
- #draw ⇒ Object
- #frames ⇒ Object
- #frames_reverse ⇒ Object
-
#initialize(args = {}) ⇒ BasicFish
constructor
A new instance of BasicFish.
Methods inherited from TankObject
Constructor Details
#initialize(args = {}) ⇒ BasicFish
Returns a new instance of BasicFish.
8 9 10 11 12 13 14 15 |
# File 'lib/cursetank/tank_objects/basic_fish.rb', line 8 def initialize(args={}) super(args) @height = 1 @width = 5 @swin = @win.subwin(@height, @width, 0, 0) @color = args.fetch(:color, 1) @speed = args.fetch(:speed, 0.1) end |
Instance Method Details
#draw ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cursetank/tank_objects/basic_fish.rb', line 29 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] frame = frames_reverse[@frame.round.to_i] if @dir_right == -1 @swin.attron(Curses.color_pair(@color)){ @swin.addstr(frame) } change_row = rand(100) @pos_y += @speed * @dir_down if change_row == 7 @pos_x += @speed * @dir_right @swin.refresh() end |
#frames ⇒ Object
17 18 19 20 21 |
# File 'lib/cursetank/tank_objects/basic_fish.rb', line 17 def frames ["><_'>", "><_\">" ] end |
#frames_reverse ⇒ Object
23 24 25 26 27 |
# File 'lib/cursetank/tank_objects/basic_fish.rb', line 23 def frames_reverse ["<'_><", "<\"_><" ] end |