UnidirectionalActuator

class pygamelib.actuators.UnidirectionalActuator(direction=10000100, parent=None)

Bases: pygamelib.actuators.Actuator

A class that implements a single movement.

The unidirectional actuator is a subclass of Actuator. It is simply implementing a mono directional movement. It is primarily target at projectiles.

Parameters:
__init__(direction=10000100, parent=None)

The constructor take only one (positional) parameter: the parent object.

Important

The default state of ALL actuators is RUNNING. If you want your actuator to be in a different state (PAUSED for example), you have to do it yourself.

Methods

__init__([direction, parent]) The constructor take only one (positional) parameter: the parent object.
load(data) Load data and create a new UnidirectionalActuator out of it.
next_move() Return the direction.
pause() Set the actuator state to PAUSED.
serialize() Return a dictionary with all the attributes of this object.
start() Set the actuator state to RUNNING.
stop() Set the actuator state to STOPPED.
classmethod load(data: dict = None)

Load data and create a new UnidirectionalActuator out of it.

Parameters:data (dict) – Data to create a new actuator (usually generated by serialize())
Returns:A new actuator.
Return type:UnidirectionalActuator

Example:

method()
next_move()

Return the direction.

The movement is always direction if state is RUNNING, otherwise it returns NO_DIR from the constants module.

Returns:The next movement
Return type:int | pygamelib.constants.NO_DIR

Example:

unidirectional_actuator.next_move()
pause()

Set the actuator state to PAUSED.

Example:

mygame.pause()
serialize() → dict

Return a dictionary with all the attributes of this object.

Returns:A dictionary with all the attributes of this object.
Return type:dict
start()

Set the actuator state to RUNNING.

If the actuator state is not RUNNING, actuators’ next_move() function (and all derivatives) should not return anything.

Example:

mygame.start()
stop()

Set the actuator state to STOPPED.

Example:

mygame.stop()