Class: GameMachine::Navigation::Path

Inherits:
Object
  • Object
show all
Defined in:
server/lib/game_machine/navigation/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, current_location) ⇒ Path

Returns a new instance of Path


7
8
9
10
11
# File 'server/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_locationObject

Returns the value of attribute current_location


5
6
7
# File 'server/lib/game_machine/navigation/path.rb', line 5

def current_location
  @current_location
end

#current_pointObject (readonly)

Returns the value of attribute current_point


6
7
8
# File 'server/lib/game_machine/navigation/path.rb', line 6

def current_point
  @current_point
end

#pathObject

Returns the value of attribute path


5
6
7
# File 'server/lib/game_machine/navigation/path.rb', line 5

def path
  @path
end

Instance Method Details

#next_pointObject


18
19
20
21
22
23
# File 'server/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

Returns:

  • (Boolean)

25
26
27
28
# File 'server/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 'server/lib/game_machine/navigation/path.rb', line 13

def set_path(path)
  @path = path
  @current_point = path.first
end