Direction

o1.world.Direction
See theDirection companion class
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.*.

Attributes

Companion
class
Graph
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Direction.type

Members list

Type members

Inherited and Abstract types

The names of the product elements

The names of the product elements

Attributes

Inherited from:
Mirror

The name of the type

The name of the type

Attributes

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.

Parameters

key

any key on the keyboard

Attributes

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.

Attributes

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.

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

Attributes

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.

Parameters

key

any key on the keyboard

Attributes

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.

Attributes

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.

Parameters

key

any key on the keyboard

Attributes

Returns

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

See also
def random(): Direction

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

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

Attributes

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

Attributes

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

Attributes

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

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

Attributes

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

Attributes

val Up: Direction

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

Attributes

Givens