PatrolActuator

class pygamelib.actuators.PatrolActuator(path=None, parent=None)

Bases: pygamelib.actuators.PathActuator

The patrol actuator is a subclass of PathActuator. The move inside the function next_move depends on path and index and the mode. Once it reaches the end of the move list it will start cycling back to the beggining of the list. Once it reaches the beggining it will start moving forwards If the state is not running it returns None otherwise it increments the index & then, further compares the index with length of the path. If they both are same then, index is set to value zero and the move is returned back.

Parameters:path (list) – A list of directions.
__init__(path=None, 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__([path, parent]) The constructor take only one (positional) parameter: the parent object.
load(data) Load data and create a new PatrolActuator out of it.
next_move() Return the movement based on current index
pause() Set the actuator state to PAUSED.
serialize() Return a dictionary with all the attributes of this object.
set_path(path) Defines a new path
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 PatrolActuator out of it.

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

Example:

method()
next_move()

Return the movement based on current index

The movement is selected from path if state is RUNNING, otherwise it returns NO_DIR from the constants module. When state is RUNNING, the movement is selected before incrementing the index by 1. When the index equals the length of path, the index should return back to 0 and the path list should be reversed before the next call.

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

Example:

patrolactuator.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
set_path(path)

Defines a new path

This will also reset the index back to 0.

Parameters:path (list) – A list of movements.

Example:

pathactuator.set_path([constants.UP,constants.DOWN,constants.LEFT,constants.RIGHT])
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()