1.14.07 - Destructible object

A destructible object is an entity that can be cut or lifted by the hero and that may hide a pickable treasure.

This type of map entity can be declared in the map data file. It can also be created dynamically with map:create_destructible().

Overview

Destructible objects can be customized in various ways. You can allow the hero to lift them or to cut them. The ones that can be lifted may require a minimum level of the "lift" ability. Their size is always 16x16 pixels (like the hero).

Methods inherited from map entity

Destructible objects are particular map entities. Therefore, they inherit all methods from the type map entity.

See Methods of all entity types to know these methods.

Methods of the type destructible

The following methods are specific to destructible objects.

destructible:get_treasure()

Returns what pickable treasure this object will drop when being lifted, when being cut or when exploding.

destructible:set_treasure([item_name, [variant, [savegame_variable]]])

Sets the pickable treasure that this object will drop when being lifted, when being cut or when exploding.

destructible:get_destruction_sound()

Returns the sound to be played when this object is cut or broken.

destructible:set_destruction_sound(destruction_sound_id)

Sets the sound to be played when this object is cut or broken.

destructible:get_weight()

Returns the weight of this destructible object. The weight corresponds to the "lift" ability required to lift the object.

destructible:set_weight(weight)

Sets the weight of this destructible object. The weight corresponds to the "lift" ability required to lift the object.

destructible:get_can_be_cut()

Returns whether this object can be cut by the sword.

destructible:set_can_be_cut(can_be_cut)

Sets whether this object can be cut by the sword.

destructible:get_can_explode()

Returns whether this object explodes when it is hit or after a delay when it is lifted.

destructible:set_can_explode(can_explode)

Sets whether this object explodes when it is hit or after a delay when it is lifted.

destructible:get_can_regenerate()

Returns whether this object regenerates after a delay when it is destroyed.

destructible:set_can_regenerate(can_regenerate)

Sets whether this object regenerates after a delay when it is destroyed.

destructible:get_damage_on_enemies()

Returns the number of life points that an enemy loses when the hero throws this object at it.

destructible:set_damage_on_enemies(damage_on_enemies)

Sets the number of life points that an enemy loses when the hero throws this object at it.

destructible:get_modified_ground()

Returns the ground defined by this destructible object on the map.

The presence of a destructible object can modify the ground of the map. The ground is usually "wall", but it may sometimes be "traversable", or for example "grass" to make the destructible object traversable too but with an additional grass sprite below the hero.

Events inherited from map entity

Events are callback methods automatically called by the engine if you define them.

Destructible objects a reparticular map entities. Therefore, they inherit all events from the type map entity.

See Events of all entity types to know these events.

Events of the type destructible

The following events are specific to destructible objects.

destructible:on_looked()

Called when the hero looks this destructible object, that is, when the player presses the action key but is not allowed to lift the object.

By default, nothing happens in this case. You can for example show a dialog to give the player a hint like "This is too heavy".

Remarks
If you want to do the same action for all destructible objects of your game, use the metatable trick. Just define this event on the metatable of the destructible object type instead of each individual object, and it will be applied to all of them.

destructible:on_cut()

Called when the hero has just cut this destructible object.

destructible:on_lifting()

Called when the hero starts lifting this destructible object.

At this point, the hero is in state "lifting". The animation "lifting" of his sprites is playing and the player cannot control the hero.

Remarks
This destructible object no longer exists (unless it can regenerate). It is replaced by a carried object with the same sprite.

destructible:on_exploded()

Called when this destructible object is exploding.

If destructible:get_can_explode() is true, the destructible object explodes when there is an explosion nearby or when the hero lifts it, after a delay.

destructible:on_regenerating()

Called when this destructible object regenerates.

If destructible:get_can_regenerate() is true, the destructible object regenerates after a delay when it was lifted or exploded.