BaseActor

The base class for Actors.

Actors are objects that: can be used, can be interacted with, can be talked to, or can be picked up by the user. The BaseActor does not have any shape and, as a result, it can not be drawn into the world. The BaseActor is intended to serve as a parent class to children that can be drawn to the world. See ShapeActor as an example.

Note: if your object can not be used, can not be interacted with, can not be talked to, and can not be picked up by the player, there is no reason to extend BaseActor.

When extending this object, the following functions may be interesting to overwrite:
  • onUse: Called when this object is used. Overwritting ‘onUse’ sets ‘canUse’ to True.
  • onInteract: Called when this object is interacted with. Overwriting ‘onInteract’ sets ‘canInteract’ to True.
  • onPickup: Called when this object is picked up. Overwriting ‘onPickup’ does NOT set ‘canPickup’ to True, see ‘pickup’.

Constructor

BaseActor([interact, use, pickup, returned, ...]) The base class for Actors.

Instance Attributes

canInteract Boolean indicating whether this object can be interacted with.
canPickup Boolean indicating whether this object can be picked up by the player.
canUse Indicates whether this actor can be used Can be set to False anywhere to limit use.
portrait An optional portrait of the actor used in conversations.
returned Anything, will be the object that is returned to the player upon pickup.
tag A tag, generally a string, usefull for classifying this actor as something.
userData A dictionary to which you can add arbitrary data if you want to.

Methods

bind(name, function) Binds a function to this instance.
draw(levelWorld) Adds this object to the level world.
installCollision(collision, shape) Adds a collision event to the shape, and sets its userData to this instance.
installSeparation(separation, shape) Adds a separation event to the shape, and sets its userData to this instance.
isOverwritten(function) Returns whether the indicated function is overwritten.
onInteract(items) Called when this object is interacted with.
onPickup() Called when this object is picked up.
onUse([items]) Called when this object is used.

Details

class BaseActor(interact=None, use=None, pickup=False, returned=None, onPickup=None, description=None, tag='actor')[source]

Bases: object

Constructs a BaseActor.

Parameters:
  • interact – Function of the form func(self, items), called when this object is interacted with.
  • use – Function of the form func(self) called when this object is used.
  • pickup – Anything, generally will be the object that is returned to the player upon pickup. If set to True, will return the Actor object itself instead. If set to True, and a value for returned is povided, will return whatever value returned was set to. (deprecated) If pickup is the string “self”, a reference to this instance will be returned instead, just as if pickup was set to True.
  • returned – Anything, will be the object that is returned to the player if pickup is set to True.
  • onPickup – Function of the form func(self) called when this object is picked up by the player. Note: passing a value for onPickup is NOT enough to enable the player to pickup this object.
  • description – A description of this object, used when this object is printed. If left blank, the class and memory address of this object is printed.
  • tag – The tag of the actor, usually a string helpful for identifying what kind of actor you are dealing with.

Instance Attributes

canInteract

Boolean indicating whether this object can be interacted with. Can be set to false at any time to prevent the player from interacting with it.

canPickup

Boolean indicating whether this object can be picked up by the player. Can be set to false at any time to prevent the player from picking it up.

canUse

Indicates whether this actor can be used Can be set to False anywhere to limit use.

portrait

An optional portrait of the actor used in conversations.

returned

Anything, will be the object that is returned to the player upon pickup.

tag

A tag, generally a string, usefull for classifying this actor as something.

userData

A dictionary to which you can add arbitrary data if you want to.

Methods

bind(name, function)[source]

Binds a function to this instance.

Usefull adding functions to an instance of a class after it was created.

Example:

def func(self):
    print(self)

instance = LRC_Object()
instance.bind("printMe", func)
instance.printMe()
Parameters:
  • name – A string containing the name this function will bind to.
  • function – A function of the form: func(self, ...)
draw(levelWorld)[source]

Adds this object to the level world.

This function should be overwritten, such that it adds all shapes associated with this object to the window of the level world (levelWorld.win.draw(shape)). In addition, this function should also register any callback functions, the common ones being levelWindow.interactCollide and levelWindow.pickupCollide. Lastly, this function should set any other attributes that require the bodies of the shapes to be initialized.

Important: first draw all relevant shapes to the window before settings body properties, object bodies do not exist before they have been added to the simulator.

Parameters:levelWorld – an instance of LevelWorld.
installCollision(collision, shape)[source]

Adds a collision event to the shape, and sets its userData to this instance.

Does not complain when either the collision function or the shape is None, but it does usher a warning when the shape exists, but does not have a body.

Parameters:
  • collision – A function of the form: func(myfixture, otherfixture, contact).
  • shape – An instance of a Calico Shape object.
installSeparation(separation, shape)[source]

Adds a separation event to the shape, and sets its userData to this instance.

Does not complain when either the separation function or the shape is None, but it does usher a warning when the shape exists, but does not have a body.

Parameters:
  • separation – A function of the form: func(myfixture, otherfixture).
  • shape – An instance of a Calico Shape object.
isOverwritten(function)[source]

Returns whether the indicated function is overwritten.

Parameters:function – A string indicating the function to be queried.
Returns:True if the function is overwritten, False otherwise.
onInteract(items)[source]

Called when this object is interacted with. To be overwritten.

Parameters:items – A list of things passed by the user, where the things can be anything.
onPickup()[source]

Called when this object is picked up. To be overwritten.

onUse(items=[])[source]

Called when this object is used. To be overwritten.