Module: Nimo::Behavior::Moveable

Defined in:
lib/nimo/behavior/moveable.rb

Instance Method Summary collapse

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_downObject



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_leftObject



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_rightObject



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_upObject



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