Module: Nimo::Behavior::Moveable
- Defined in:
- lib/nimo/behavior/moveable.rb
Instance Method Summary collapse
- #initialize(*params) ⇒ Object
- #move_down ⇒ Object
- #move_left ⇒ Object
- #move_right ⇒ Object
- #move_up ⇒ Object
Instance Method Details
#initialize(*params) ⇒ Object
5 6 7 8 9 |
# File 'lib/nimo/behavior/moveable.rb', line 5 def initialize(*params) @speed = 0 @boundary = nil super(*params) end |
#move_down ⇒ Object
26 27 28 29 |
# File 'lib/nimo/behavior/moveable.rb', line 26 def move_down @y += @speed @y = @boundary.height - @height if @boundary && (@y + @height) > @boundary.height end |
#move_left ⇒ Object
11 12 13 14 |
# File 'lib/nimo/behavior/moveable.rb', line 11 def move_left @x -= @speed @x = @boundary.x if @boundary && @x < @boundary.x end |
#move_right ⇒ Object
16 17 18 19 |
# File 'lib/nimo/behavior/moveable.rb', line 16 def move_right @x += @speed @x = @boundary.width - @width if @boundary && (@x + @width) > @boundary.width end |
#move_up ⇒ Object
21 22 23 24 |
# File 'lib/nimo/behavior/moveable.rb', line 21 def move_up @y -= @speed @y = @boundary.y if @boundary && @y < @boundary.y end |