Direction

object Direction

This companion object of class Direction provides some constants of type Direction and methods for creating new Direction instances.

The object has an alias in the top-level package o1, so it’s accessible to students simply via import o1.*.

Companion:
class
trait Product
trait Mirror
class Object
trait Matchable
class Any

Type members

Inherited types

The names of the product elements

The names of the product elements

Inherited from:
Mirror

The name of the type

The name of the type

Inherited from:
Mirror

Value members

Concrete methods

Returns the Direction that corresponds to the given arrow key. For example, the right arrow corresponds to Right.

Returns the Direction that corresponds to the given arrow key. For example, the right arrow corresponds to Right.

Value parameters:
key

any key on the keyboard

Returns:

one of Up, Down, Left, Right; None if the given key was not one of the four arrow keys

See also:

Takes in an angle as degrees and returns the corresponding Direction. Zero degrees points rightwards; positive angles are counterclockwise from there, negative ones clockwise.

Takes in an angle as degrees and returns the corresponding Direction. Zero degrees points rightwards; positive angles are counterclockwise from there, negative ones clockwise.

Takes in a difference between x coordinates and a difference between y coordinates and constructs a Direction from them.

Takes in a difference between x coordinates and a difference between y coordinates and constructs a Direction from them.

Value parameters:
dx

a difference between two x coordinates; it is not necessary that this is normalized between -1.0 and +1.0 like the dx and dy of the resulting Direction object

dy

a difference between two x coordinates; it is not necessary that this is normalized between -1.0 and +1.0 like the dx and dy of the resulting Direction object

Returns:

the Direction that corresponds to the given deltas. If both are exactly equal to zero, returns NoDirection.

Returns the Direction that corresponds to the given arrow key. For example, the right arrow or the D key corresponds to East.

Returns the Direction that corresponds to the given arrow key. For example, the right arrow or the D key corresponds to East.

Value parameters:
key

any key on the keyboard

Returns:

one of Up, Down, Left, Right; None if the given key was not one of the four arrow keys or one of the four WASD keys

See also:

Takes in an angle as radians and returns the corresponding Direction. Zero radians points rightwards; positive angles are counterclockwise from there, negative ones clockwise.

Takes in an angle as radians and returns the corresponding Direction. Zero radians points rightwards; positive angles are counterclockwise from there, negative ones clockwise.

Returns the Direction that corresponds to the given WASD key. For example, the D key corresponds to East.

Returns the Direction that corresponds to the given WASD key. For example, the D key corresponds to East.

Value parameters:
key

any key on the keyboard

Returns:

one of Up, Down, Left, Right; None if the given key was not one of the four WASD keys

See also:

Returns a randomly chosen direction (evenly distributed over 360 degrees).

Returns a randomly chosen direction (evenly distributed over 360 degrees).

Concrete fields

the “straight downwards” direction with a dx of zero, and a dy of +1

the “straight downwards” direction with a dx of zero, and a dy of +1

the “straight leftwards” direction with a dx of -1, and a dy of zero

the “straight leftwards” direction with a dx of -1, and a dy of zero

a “non-direction” whose dx and dy are both zero

a “non-direction” whose dx and dy are both zero

the “straight rightwards” direction with a dx of +1, and a dy of zero

the “straight rightwards” direction with a dx of +1, and a dy of zero

the “straight upwards” direction with a dx of zero, and a dy of -1

the “straight upwards” direction with a dx of zero, and a dy of -1