diff --git a/docs/reference/directions.rst b/docs/reference/directions.rst new file mode 100644 index 00000000..ff1e77ac --- /dev/null +++ b/docs/reference/directions.rst @@ -0,0 +1,8 @@ +.. py:currentmodule:: ppb.directions + +=============================== +Directions +=============================== + +.. automodule:: ppb.directions + :members: diff --git a/docs/reference/index.rst b/docs/reference/index.rst index 25eed3a2..9062c4b3 100644 --- a/docs/reference/index.rst +++ b/docs/reference/index.rst @@ -26,4 +26,5 @@ decisions are made, see the :doc:`/discussion/index` section. engine sound camera + directions features/index diff --git a/ppb/__init__.py b/ppb/__init__.py index aefa6277..68043972 100644 --- a/ppb/__init__.py +++ b/ppb/__init__.py @@ -12,12 +12,28 @@ The classes, modules, and methods exported directly are the most used parts of the library and intended to be used by users at all levels (barring make_engine). Advanced features tend to be in their own modules and subpackages. + +Exports: + +* :class:`~ppb_vector.Vector` +* :class:`BaseScene` +* :class:`Circle` +* :class:`Image` +* :class:`Sprite` +* :class:`Square` +* :class:`Sound` +* :class:`Triangle` +* :mod:`events` +* :class:`Font` +* :class:`Text` +* :mod:`directions` """ import logging import warnings from typing import Callable +from ppb import directions from ppb import events from ppb_vector import Vector from ppb.assets import Circle @@ -34,7 +50,7 @@ __all__ = ( # Shortcuts 'Vector', 'BaseScene', 'BaseSprite', 'Circle', 'Image', 'Sprite', - 'Square', 'Sound', 'Triangle', 'events', 'Font', 'Text', + 'Square', 'Sound', 'Triangle', 'events', 'Font', 'Text', 'directions', # Local stuff 'run', 'make_engine', ) @@ -78,6 +94,7 @@ def run(setup: Callable[[BaseScene], None] = None, *, log_level=logging.WARNING, Sample usage: :: + import ppb def setup(scene): @@ -87,6 +104,7 @@ def setup(scene): Alternatively: :: + import ppb class Game(ppb.BaseScene): diff --git a/ppb/directions.py b/ppb/directions.py new file mode 100644 index 00000000..78618e4f --- /dev/null +++ b/ppb/directions.py @@ -0,0 +1,17 @@ +""" +The ordinal directions. + +A collection of normalized vectors to be referenced by name. + +Best used for the positions or facings of :class:`Sprites `. +""" +from ppb_vector import Vector + +Up = Vector(0, 1).normalize() #: Unit vector to the top of the screen from center. +Down = Vector(0, -1).normalize() #: Unit vector to the bottom of the screen from center. +Left = Vector(-1, 0).normalize() #: Unit vector to the left of the screen from center. +Right = Vector(1, 0).normalize() #: Unit vector to the right of the screen from center. +UpAndLeft = (Up + Left).normalize() #: Unit vector diagonally up and to the left of the screen from center. +UpAndRight = (Up + Right).normalize() #: Unit vector diagonally up and to the right of the screen from center. +DownAndLeft = (Down + Left).normalize() #: Unit vector diagonally down and to the left of the screen from center. +DownAndRight = (Down + Right).normalize() #: Unit vector diagonally down and to the right of the screen from center.