Games::Roguelike::World::Daemon - roguelike game telnet daemon
# for an extended example with move overrides, see the scripts/netgame included use strict; package myWorld; # always override use base 'Games::Roguelike::World::Daemon'; my $r = myWorld->new(w=>80,h=>50,dispw=>40,disph=>18); # create a networked world $r->area(new Games::Roguelike::Area(name=>'1')); # create a new area in this world called "1" $r->area->generate('cavelike'); # make a cavelike maze while (1) { $r->proc(); } sub readinput { # called when input is available my $self = shift; if (my $c = $self->getch()) { # returns undef on failure if ($self->{vp}->kbdmove($c, 1)) { # '1' in second param means "test only" $r->queuemove($self->{vp}, $c); # if the move is good, queue it } } } sub newconn { # called when someone connects my $self = shift; my $char = mychar->new($self->area(1), # create a new character sym=>'@', color=>'green', pov=>7 ); $self->{vp} = $char; # viewpoint is a connection state obect $self->{state} = 'MOVE'; # set state (another state object) } package mychar; use base 'Games::Roguelike::Mob';
This module uses the Games::Roguelike::World object as the basis for a finite-state based network game engine.
* uses Games::Roguelike::Console::ANSI library to draw the current area * currently assumes Games::Roguelike::Mob's as characters in the game * currently assumes Games::Roguelike::Item's as items in the game
The module provides th eservice of accepting connections, maintainting he association between the connection and a "state" and "viewpoint" for each connection, managing "tick" times, and rendering maps for each connection.
Similar to ::World new, but with arguments: host, port, and addr
This begins listening for connections, and sets up some signal handlers for graceful death.
Look for waiting input and calls:
newconn() - for new conneciton readinput() - when input is available tick() - to process per-turn moves drawallmaps() - to render all the maps
When those functions are called the class {vp} and {state} variables are set to the connection's "viewpoint" (character) and "state".
Also, the special scalar state 'QUIT' gracefully removes a connection.
(It might be interesting to use code refs as states)
Reads a string from the active connection.
Returns undef if the string is not ready.
Reads a character from the active connection.
Returns undef if no input is ready.
Calls showmsg on the console contained in $char;
Must override and call getch() or getstr().
The {vp}, {state}, and {con} vars are set on this call, can be changed, and will be preserved.
Actual action/movement by a charcter should be queued here, then processed according to a random sort and/or a sort based on the speed of the character.
For example: If a tank and a motorcycle move during the same tick, the motorcycle would always go first, even if the tank's player has a faster internet connection. Queueing the moves allows you to do this.
Remember never to do something that blocks or waits for input, game is single-threaded.
Must override and either create a character or show an intro screen, or something.
Change the display color/symbol of the {vp} character here in order to distinguish it from other (enemy?) characters.
Pushes a "move" for char $char showing message $msg. By default will not queu if a move has been set. The "move" variabe is set in the "char" object to record whether a move has occured.
Override for per-turn move processing. This is called for each game turn, which defaults to a half-second. Default behavior is to sort all the queued moves and execute them.
A good way to handle this might be to make the "moves" be code references, which get passed "char" as the argument.
Currently this fails on Win32
Games::Roguelike::World
Erik Aronesty earonesty@cpan.org
earonesty@cpan.org
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html or the included LICENSE file.
To install Games::Roguelike::Mob, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Games::Roguelike::Mob
CPAN shell
perl -MCPAN -e shell install Games::Roguelike::Mob
For more information on module installation, please visit the detailed CPAN module installation guide.