Menu

Command Palette

Search for a command to run...

Direction

Enum representing different directions, used for navigating the world.

Overview

The Direction class provides a flexible and powerful interface for working with two-dimensional coordinates. It defines a set of cardinal and intercardinal directions that can be used for navigating the world.

Attributes

NORTH

tuple

Direction that points north (up).

dx

int

The change in the x-coordinate when moving in the NORTH direction.

Default: 0

dy

int

The change in the y-coordinate when moving in the NORTH direction.

Default: 1

NORTH_EAST

tuple

Direction that points northeast (up and right).

dx

int

The change in the x-coordinate when moving in the NORTH_EAST direction.

Default: 1

dy

int

The change in the y-coordinate when moving in the NORTH_EAST direction.

Default: 1

EAST

tuple

Direction that points east (right).

dx

int

The change in the x-coordinate when moving in the EAST direction.

Default: 1

dy

int

The change in the y-coordinate when moving in the EAST direction.

Default: 0

SOUTH_EAST

tuple

Direction that points southeast (down and right).

dx

int

The change in the x-coordinate when moving in the SOUTH_EAST direction.

Default: 1

dy

int

The change in the y-coordinate when moving in the SOUTH_EAST direction.

Default: -1

SOUTH

tuple

Direction that points south (down).

dx

int

The change in the x-coordinate when moving in the SOUTH direction.

Default: 0

dy

int

The change in the y-coordinate when moving in the SOUTH direction.

Default: -1

SOUTH_WEST

tuple

Direction that points southwest (down and left).

dx

int

The change in the x-coordinate when moving in the SOUTH_WEST direction.

Default: -1

dy

int

The change in the y-coordinate when moving in the SOUTH_WEST direction.

Default: -1

WEST

tuple

Direction that points west (left).

dx

int

The change in the x-coordinate when moving in the WEST direction.

Default: -1

dy

int

The change in the y-coordinate when moving in the WEST direction.

Default: 0

NORTH_WEST

tuple

Direction that points northwest (up and left).

dx

int

The change in the x-coordinate when moving in the NORTH_WEST direction.

Default: -1

dy

int

The change in the y-coordinate when moving in the NORTH_WEST direction.

Default: 1

Methods

get_random_direction()

Returns a random direction.

Returns

Direction

A random direction.

Example:

dir = Direction.get_random_direction()
# Returns Direction.NORTH 
 
dir = Direction.get_random_direction()
# Returns Direction.SOUTH_EAST

Additional Notes

The Direction enum supports iteration, allowing you to easily loop over all defined directions. This can be useful when you need to process each direction or perform operations on every direction. For example, you can loop over the directions like this:

for direction in Direction:
  print(direction)