Module: Movable2

Includes:
Moon::Eventable
Included in:
Camera2, Cursor2
Defined in:
lib/moon/packages/twod/movable2.rb

Overview

required methods, #position, #position=

Instance Method Summary collapse

Methods included from Moon::Eventable

#allow_event?, #clear_events, #each_listener, #each_typed_listener, filter_from_options, #has_events?, #initialize_eventable, #off, #on, #ppd_ev, #trigger, #typing

Instance Method Details

#adjust_position(position) ⇒ Moon::Vector2


18
19
20
# File 'lib/moon/packages/twod/movable2.rb', line 18

def adjust_position(position)
  position
end

#backward(d = 1.0) ⇒ Object


44
45
46
# File 'lib/moon/packages/twod/movable2.rb', line 44

def backward(d = 1.0)
  move(0, -d)
end

#forward(d = 1.0) ⇒ Object


40
41
42
# File 'lib/moon/packages/twod/movable2.rb', line 40

def forward(d = 1.0)
  move(0, d)
end

#left(d = 1.0) ⇒ Object


48
49
50
# File 'lib/moon/packages/twod/movable2.rb', line 48

def left(d = 1.0)
  move(-d, 0)
end

#movable?Boolean


12
13
14
# File 'lib/moon/packages/twod/movable2.rb', line 12

def movable?
  true
end

#move(*args) ⇒ Object


36
37
38
# File 'lib/moon/packages/twod/movable2.rb', line 36

def move(*args)
  moveto(position + Moon::Vector2[*args] * move_distance)
end

#move_distanceObject


8
9
10
# File 'lib/moon/packages/twod/movable2.rb', line 8

def move_distance
  1
end

#moveto(position) ⇒ self #moveto(x, y) ⇒ self


28
29
30
31
32
33
34
# File 'lib/moon/packages/twod/movable2.rb', line 28

def moveto(*args)
  return self unless movable?
  old_pos = position
  self.position = adjust_position(Moon::Vector2[*args])
  trigger { Moon::MovedEvent.new self, old_pos, position }
  self
end

#right(d = 1.0) ⇒ Object


52
53
54
# File 'lib/moon/packages/twod/movable2.rb', line 52

def right(d = 1.0)
  move(d, 0)
end