Class: GameMachine::Navigation::Path
- Inherits:
-
Object
- Object
- GameMachine::Navigation::Path
- Defined in:
- lib/game_machine/navigation/path.rb
Instance Attribute Summary collapse
-
#current_location ⇒ Object
Returns the value of attribute current_location.
-
#current_point ⇒ Object
readonly
Returns the value of attribute current_point.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path, current_location) ⇒ Path
constructor
A new instance of Path.
- #next_point ⇒ Object
- #point_reached? ⇒ Boolean
- #set_path(path) ⇒ Object
Constructor Details
#initialize(path, current_location) ⇒ Path
Returns a new instance of Path.
7 8 9 10 11 |
# File 'lib/game_machine/navigation/path.rb', line 7 def initialize(path,current_location) @path = path @current_point = path.first @current_location = current_location end |
Instance Attribute Details
#current_location ⇒ Object
Returns the value of attribute current_location.
5 6 7 |
# File 'lib/game_machine/navigation/path.rb', line 5 def current_location @current_location end |
#current_point ⇒ Object (readonly)
Returns the value of attribute current_point.
6 7 8 |
# File 'lib/game_machine/navigation/path.rb', line 6 def current_point @current_point end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/game_machine/navigation/path.rb', line 5 def path @path end |
Instance Method Details
#next_point ⇒ Object
18 19 20 21 22 23 |
# File 'lib/game_machine/navigation/path.rb', line 18 def next_point if point_reached? @current_point = path.shift end @current_point end |
#point_reached? ⇒ Boolean
25 26 27 28 |
# File 'lib/game_machine/navigation/path.rb', line 25 def point_reached? return true if current_point.nil? current_location.distance(current_point) < 1 end |
#set_path(path) ⇒ Object
13 14 15 16 |
# File 'lib/game_machine/navigation/path.rb', line 13 def set_path(path) @path = path @current_point = path.first end |