Games::Object 0.11 review

Download
by rbytes.net on

Games::Object is a Perl module to provide a base class for game objects. SYNOPSIS package MyGameObject; use Games::Obj

License: Perl Artistic License
File size: 83K
Developer: Peter J. Stewart
0 stars award from rbytes.net

Games::Object is a Perl module to provide a base class for game objects.

SYNOPSIS

package MyGameObject;
use Games::Object;
use vars qw(@ISA);
@ISA = qw(Games::Object);

sub new {
# Create object
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = $class->SUPER::new(@_);
bless $self, $class;

# Add attributes
$self->new_attr(-name => "hit_points",
-type => 'int',
-value => 20,
-tend_to_rate => 1);
$self->new_attr(-name => "strength",
-type => 'int',
-value => 12,
-minimum => 3,
-maximum => 18);
...

return $self;
}

package MyObjectManager;
use Games::Object::Manager;
use vars qw(@ISA);
@ISA = qw(Games::Object::Manager);

sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = $class->SUPER::new(, @_);
bless $self, $class;
...
return $self;
}


my $world = new MyObjectManager;
my $object = new MyGameObject;
$world->add($object);

ABSTRACT

The purpose of this module is to allow a programmer to write a game in Perl easily by providing a basic framework in the form of a module that can be either subclassed to a module of your own or used directly as its own object class. The most important items in this framework are:

Attributes

You can define arbitrary attributes on objects with rules on how they may be updated, as well as set up automatic update of attributes whenever the object's process() method is invoked. For example, you could set an attribute on an object such that:

It ranges from 0 to 100.

Internally it tracks fractional changes to the value but accessing the attribute will always round the result to an integer.

It will automatically tend towards the maximum by 1 every time process() is called on the object.

A method in your subclass will be invoked automatically if the value falls to 0.
This is just one example of what you can do with attributes.

Flags

You can define any number of arbitrarily-named flags on an object. A flag is a little like a boolean attribute, in that it can have a value of either true or false. Like attributes, flags can be created independently on different objects. No "global" flag list is imposed.

Load/Save functionality

Basic functionality is provided for saving data from an object to a file, and for loading data back into an object. This handles the bulk of load game / save game processing, freeing the programmer to worry about the mechanics of the game itself.

The load functionality can also be used to create objects from object templates. An object template would be a save file that contains a single object.

Object Managers

New to version 0.10 of this module is object managers. An object manager is a Perl object that allows you to manage groups of related game objects. The object manager allows you to relate objects together (for example, you could define a relationship that allows certain objects to act as containers for other objects). In effect, the object manager acts as your world or universe.
Like the game object class, the manager class can be subclassed, allowing you augment its functionality. An object manager can be loaded and saved, which in turn performs a load or save of the objects being managed by it.

Requirements:
Perl

Games::Object 0.11 keywords