NAME
Term::Animation::Entity
SYNOPSIS
use Term::Animation::Entity;
# Constructor
my $entity = Term::Animation::Entity->new(
shape => ';-)',
position => [ 1, 2, 3 ],
callback_args => [ 0, 1, 0, 0 ],
);
ABSTRACT
A sprite object for use with Term::Animation
DESCRIPTION
Term::Animation::Entity is used by Term::Animation to represent a single sprite on the screen.
PARAMETERS
name < SCALAR >
A string uniquely identifying this object
shape < REF >
The ASCII art for this object. It can be provided as:
1) A single multi-line text string (no animation)
2) An array of multi-line text strings, where each
element is a single animation frame
3) An array of 2D arrays. Each element in the outer
array is a single animation frame.
If you provide an array, each element is a single frame of animation.
If you provide either 1) or 2), a single newline will be stripped off
of the beginning of each string. 3) is what the module uses internally.
auto_trans < BOOLEAN >
Whether to automatically make whitespace at the beginning of each line
transparent. Default: 0
position < ARRAY_REF >
A list specifying initial x,y and z coordinates
Default: [ 0, 0, 0 ]
callback < SUBROUTINE_REF >
Callback routine for this entity. Default: I<move_entity()>
callback_args < REF >
Arguments to the callback routine.
curr_frame < INTEGER >
Animation frame to begin with. Default: 0
wrap < BOOLEAN >
Whether this entity should wrap around the edge of the screen. Default: 0
transparent < SCALAR >
Character used to indicate transparency. Default: ?
die_offscreen < BOOLEAN >
Whether this entity should be killed if
it goes off the screen. Default: 0
die_time < INTEGER >
The time at which this entity should be killed. This
should be a UNIX epoch time, as returned
by I<time>. Default: undef
die_frame < INTEGER >
Specifies the number of frames that should be displayed
before this entity is killed. Default: undef
death_cb < SUBROUTINE_REF >
Callback routine used when this entity dies
dcb_args < REF >
Arguments to the entity death callback routine
color
Color mask. This follows the same format as 'shape'.
See the 'COLOR' section below for more details.
default_color < SCALAR >
A default color to use for the entity. See the 'COLOR' section
for more details.
data < REF >
Store some data about this entity. It is not used by the module.
You can use it to store state information about this entity.
METHODS
- new
-
my $entity = Term::Animation::Entity->new( shape => ';-)', position => [ 1, 2, 3 ], callback_args => [ 0, 1, 0, 0 ], );
Create a Term::Animation::Entity instance. See the PARAMETERS section for details. The only required parameter is
shape
. - physical
-
$entity->physical( 1 ); $state = $entity->physical();
Enables or disabled collision detection for this entity.
- auto_trans
-
$entity->auto_trans( 1 ); $state = $entity->auto_trans();
Enables or disables automatic transparency for this entity's sprite. This will only affect subsequent calls to shape, the current sprite will be unchanged.
- data
-
$entity->data( $stuff ); $data = $entity->data();
Get or set the 'data' associated with the entity. It should be a single scalar or ref. This can be whatever you want, it is not used by the module and is provided for convenience.
- name
-
$name = $entity->name();
Returns the name of the entity.
- type
-
$entity->type( 'this_type' ); $type = $entity->type();
Get or set the 'type' of the entity. The type can be any string, and is not used by the animation itself.
- frame
-
$entity->frame( 3 ); $current_frame = $entity->frame();
Gets or sets the current animation frame of the entity.
- width
-
my $width = $entity->width();
Returns the width (columns) of the entity.
- height
-
my $height = $entity->height();
Returns the height (rows) of the entity.
- depth
-
my $depth = $entity->depth();
Returns the depth of the entity.
- size
-
my ($width, $height, $depth) = $entity->size();
Returns the X / Y / Z dimensions of the entity.
- position
-
my ($x, $y, $z) = $entity->position(); $entity->position($x, $y, $z);
Gets or sets the X / Y / Z coordinates of the entity. Note that you should normally position an entity using its callback routine, instead of calling position.
- callback_args
-
$entity->callback_args( $args ); $args = $entity->callback_args();
Get or set the arguments to the entity's callback routine. This should be either a single scalar or a single ref.
- callback
-
$entity->callback( \&callback_routine ); $callback_routine = $entity->callback();
Get or set the callback routine for the entity
- shape
-
$entity->shape($new_shape);
Set the sprite image for the entity. See the
shape
argument to new for details. - collisions
-
$collisions = $entity->collisions();
Returns a reference to a list of entities that this entity collided with during this animation cycle.
- animation
-
$entity->animation( $anim ); $anim = $entity->animation();
Get or set the Term::Animation object that this entity is part of.
- default_color
-
$entity->default_color( 'blue' ); $def_color = $entity->default_color();
Get or set the default color for the entity. The color can be either a single character or the full name of the color.
- color_mask
-
$entity->color_mask( $mask );
Set the color mask for the entity. See the Term::Animation/COLOR section of Term::Animation for details.
- move_entity
-
The default callback. You can also call this from your own callback to do the work of moving and animating the entity after you have done whatever other processing you want to do.
sub my_callback { my ($entity, $animation) = @_; # do something here return $entity->move_object($animation); }
- kill
-
$entity->kill();
Remove this entity from the animation. This is equivilent to:
$animation->del_entity($entity);
This does not destroy the object, so you can still readd it later (or put it in a different animation) as long as you have a reference to it.
AUTHOR
Kirk Baucom <kbaucom@schizoid.com>
SEE ALSO
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 453:
alternative text 'Term::Animation/COLOR' contains non-escaped | or /