Games::3D::World - contains all things in the game world
use Games::3D::World; # construct world from templates file and level file my $level = Games::3D::World->new( $templates, $file); # load the same level again $level->reload(); # create a new world from sratch: my $world = Games::3D::World->new(); $world->load_templates( $templates_file ); # add some thing directly $world->create ( $thing_class ); # create another one my $thing = Games::3D::Thingy->new( ... ); $thing->visible(1); $thing->think_time(100); # and make our world contain it $world->register($thing); # save the world $world->save_to_file(); # foreach frame to render: while ($not_quit) { # other code like user input handling here ... # update the world with the current frame time: $world->update( $now ); ... # then let world call $callback for each visible object $world->render( $now, $callback ); # other drawing code here ... }
Exports nothing on default.
This class represents the entire in-game object system. It contains Templates, e.g. the blue-prints for objects, as well as the objects itself.
my $world = Games::3D::World->new( templates => $file );
Creates a new game world/level and reads in the templates from $file.
$file
$world->load_from_file( $file );
Load the game world/level from a file, replacing all existing data.
$world->load_templates( $templates_file );
Loads the templates from a file. Alternatively, if given a scalar ref, will load the templates from the contents of the scalar.
my $rc = $world->save_to_file( $file );
Save game world/level to a file, returns undef for success, otherwise ref to error message.
my $rc = $world->save_templates( $file );
print "I have ", $world->templates(), " templates\n";
Returns the number of templates the world currently knows about.
$world->render();
Calls the method render() on all things that want to be rendered.
render()
$world->update( $now );
Let's all objects that want to think regulary think, and then updates objects that need updating. After this call, each object represents the the state if has at the time $now.
$now
$world->time( );
Return the current time. Usefull for objects that want to know the time, because update() might cause some object to send a signal to another object, and the second one needs to know when the signal arrives.
my $object = $world->create($class);
Create an object based on a template (class name) and populate it's settings with the default values.
my $template_object = $world->find_template($class);
Given a class name, return the template object for it..
my $id = $world->id();
Return the ID of this world, which is always 0.
$self->register($thingy);
Register an object with the world.
This method is automatically called to unregister objects with the world upon their death.
$world->reload();
Loads the world from the file again, thus resetting it to its initial state again.
my $things = $world->things();
Returns the count of things in this world.
my $thinkers = $world->thinkers();
Get the count of thinking things this world has.
(c) 2003, 2004, 2006 Tels <http://bloodgate.com/>
Games::3D::Thingy, Games::3D::Link, Games::Irrlicht.
To install Games::3D, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Games::3D
CPAN shell
perl -MCPAN -e shell install Games::3D
For more information on module installation, please visit the detailed CPAN module installation guide.