Module: Location

Included in:
Dimensions, Mouse
Defined in:
tomes/spells/geometry/location.rb

Overview

A module for dealing with an object’s location in 2D space.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xObject

The X coordinate.



10
11
12
# File 'tomes/spells/geometry/location.rb', line 10

def x
  @x
end

#yObject

The Y coordinate.



10
# File 'tomes/spells/geometry/location.rb', line 10

attr_accessor :x, :y

Instance Method Details

#adjust_location(location_offset) ⇒ Void Also known as: move

Adds the X and Y values (indices 0 and 1) to the X and Y attributes, respectively.

Parameters:

  • location_offset (Array<Integer, Integer>)

    The X and Y offset values.

Returns:

  • (Void)


23
24
25
26
# File 'tomes/spells/geometry/location.rb', line 23

def adjust_location(location_offset)
  self.x += location_offset[0]
  self.y += location_offset[1]
end

#locationArray<Integer, Integer> Also known as: point

Returns an array of the object’s X and Y coordinates.

Returns:

  • (Array<Integer, Integer>)


31
32
33
# File 'tomes/spells/geometry/location.rb', line 31

def location
  [x, y]
end

#location=(new_location) ⇒ Void Also known as: change_location

Sets the X and Y attributes.

Parameters:

  • new_location (Array<Integer, Integer>)

    The new X and Y values.

Returns:

  • (Void)


15
16
17
# File 'tomes/spells/geometry/location.rb', line 15

def location=(new_location)
  self.x, self.y = new_location
end