earwax.mapping.portal module

Provides the Portal class.

class earwax.mapping.portal.Portal(level: BoxLevel, coordinates: earwax.point.Point, bearing: Optional[int] = None, enter_sound: Optional[pathlib.Path] = None, exit_sound: Optional[pathlib.Path] = None, can_use: Optional[Callable[[], bool]] = None)

Bases: earwax.mixins.RegisterEventMixin

A portal to another map.

An object that can be added to a earwax.Box to make a link between two maps.

This class implements pyglet.event.EventDispatcher, so events can be registered and dispatched on it.

The currently-registered events are:

  • on_enter()
  • on_exit()
Variables:
  • level – The destination level.
  • coordinates – The exit coordinates.
  • bearing – If this value is None, then it will be used for the player’s bearing after this portal is used. Otherwise, the bearing from the old level will be used.
  • enter_sound

    The sound that should play when entering this portal.

    This sound is probably only used when an NPC uses the portal.

  • exit_sound

    The sound that should play when exiting this portal.

    This is the sound that the player will hear when using the portal.

  • can_use

    An optional method which will be called to ensure that this portal can be used at this time.

    This function should return True or False, and should handle any messages which should be sent to the player.

on_enter() → None

Handle a player entering this portal.

on_exit() → None

Handle a player exiting this portal.