Erik Aronesty > Roguelike-Utils-0.5.260 > Games::Roguelike::World



Annotate this POD


New  3
Open  0
View/Report Bugs
Module Version: 0.4.256   Source  


Games::Roguelike::World - Roguelike World


 package myWorld;
 use base 'Games::Roguelike::World';

 $r = myWorld->new(w=>80,h=>50,dispw=>40,disph=>18);     # creates a world with specified width/height & map display width/height
 $r->area(new Games::Roguelike::Area(name=>'1'));                       # create a new area in this world called "1"
 $r->area->genmaze2();                                   # make a cavelike maze
 $char = Games::Roguelike::Mob->new($r->area, sym=>'@', pov=>8);      # add a mobile object with symbol '@'
 $r->setvp($char);                                       # set viewpoint to be from $char's perspective
 $r->drawmap();                                          # draw the active area map from the current perspective
 while (!((my $c = $r->getch()) eq 'q')) {


General pupose object which pulls together field of view, item, mob handling and map drawing code.

        * contains a hash of Games::Roguelike::Area's for each "level" or "region" in the game
        * uses the Games::Roguelike::Console library to draw the current area
        * assumes the user will be using overridden Games::Roguelike::Mob's as characters in the game
        * assumes the user will be using overridden Games::Roguelike::Item's as items in the game


new(OPT1=>VAL1, OPT2=>VAL2...)

Options can also all be set/get as class accessors:

        vp => undef                     # Games::Roguelike::Mob that is the 'viewpoint'
        dispx, dispy => (0,1)           # x/y location, of the map
        dispw, disph => (60,24)         # width & height of the map
        msgx, msgy => (0,0)             # x/y location of the "scrolling message box"
        msgw, msgh => (60, 1)           # width & height of the "scrolling message box"
        maxlog => 80,                   # maximum number of rows stored message log
        msgoldcolor => 'gray',          # color of non-curent messages (if left blank, color is left alone)
        wsym => '#',                    # default wall symbol
        fsym => '.',                    # default floor symbol
        dsym => '+',                    # default door symbol
        debugmap => 0,                  # turn on map coordinate display
        debug => 0,                     # debug level (higher = more)
        noview => '#+',                 # list of symbols that block view
        nomove => '#',                  # list of symbols that block movement   
        area => undef,                  # Games::Roguelike::Area that contains the currrent map

None of these features have to be used, and can be easily ignored or overridden.

area([name or Games::Roguelike::Area])

No arguments: returns the current area

Specify a scalar name: returns an area with that name

Specify an Games::Roguelike::Area object: stores that object in the area hash, overwriting any with the same name, then makes it the active area

dprint ( msg1 [,msg2...msgn] [,level] )

Debug print messages

For now, hard coded to far right side of screen, at col 82, past most terminal game widths

getch ()

Read one character, blocks until a char is pressed.

getstr ([echo=>1[,empty=>0]])

Calls getch repeatedly, optionally echoing characters to the active console. If "empty" is not set to true, it will not return empty strings.

refresh ()

Refreshes the console display.

nbgetch ()

Read one character, nonblocking, returns undef if none are available.

findfeature (symbol)

searches "map feature list" for the given symbol, returns coordinates if found

dispclear ()

Erases the "display world", and resets the "display line" (used by dispstr)

Useful for displaying an in-game menu, inventory, ability or skill list, etc.

dispstr (str[, line])

Draws a tagged string at the "displine" position and increments the "displine".

Return value: 0 (offscreen, did not draw), 1 (ok), 2 (ok, but next call will be offscreen).

drawmap ()

Draws the map, usually do this after each move

prompt (msg[, match])

Same as showmsg, but also shows the cursor, and gets a character response, optionally waiting until it matches.

cursor (bool)

Turn on/off display of cursor for next operation.

pushmsg (msg, color)

Shows a message and pushes it into the log. Use of color argument is deprecated. Prefer to use "<$color>$msg" tagged strings.

showmsg (msg, color[, push])

Shows a message at msgx, msgy coorinates and optionally logs it. Also displays up to (msgh-1) old messages.

save ([file])

Saves the world (!), optionally specify filename which defaults to "".

load ([file])

Loads a world, optionally specify filename, returns a reference to the new world.

Console is not initialized, and is, instead, copied from the current world.


Games::Roguelike::Area, Games::Roguelike::Mob, Games::Roguelike::Console


Erik Aronesty


This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See or the included LICENSE file.

syntax highlighting: