Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Java] [Code] Map generation exchange?

14 views
Skip to first unread message

Fu, Ren-Li

unread,
Oct 19, 2003, 2:36:55 PM10/19/03
to
Hi, I propose a simple interface called class RandomLevel.

If your game uses this class, then it can use basic kinds of maps.. what do
you think? How could this be extended to include concepts like treasure
rooms.. etc?

-----


Fu, Ren-Li

unread,
Oct 19, 2003, 2:37:37 PM10/19/03
to
// defines the interface for random map generators.

package game.world.mapgen;

import game.world.*;

abstract public class RandomMap
{
public int map_x;
public int map_y;

/** Creates a new instance of RandomMap */
public RandomMap()
{
}

abstract public void generate(Level lvl);
}


Fu, Ren-Li

unread,
Oct 19, 2003, 2:38:21 PM10/19/03
to
//
// creates a test level.
//
package game.world.mapgen;

import game.world.*;

public class TestLevel extends RandomMap
{

/** Creates a new instance of TestLevel */
public TestLevel()
{
}

public void generate(Level lvl)
{
String a_map[] =
{
"####################",
"#..................#",
"#..................#",
"#############+######",
"#........#.........#",
"#........+.........#",
"###+######.........#",
"#......+....<......#",
"#......#...........#",
"#s#############+####",
"#.#.+......+.#.....#",
"############.#.....#",
"#.+........#.#.....#",
"##########.#.#.....#",
"#.....+..#.#.#.....#",
"#.########.#.#.....#",
"#............#.....#",
"#####.########.....#",
"#...#........#.....#",
"#.#########.##.....#",
"#.#...+......#.....#",
"#.#####.######.....#",
"#..#..#...#..#.....#",
"##+#+####+#+##.....#",
"#.....##.....#.....#",
"###+######+###.....#",
"#.s.##..##.###.....#",
"###+##ss##+###.....#",
"#............+.....#",
"####################"
};

map_x = 20;
map_y = 30;
lvl.resizeto(20,30);

for (int lineno = 0; lineno < map_y; lineno++)
lvl.readmapline(a_map[lineno], lineno);

return;
}

}


Fu, Ren-Li

unread,
Oct 19, 2003, 2:39:09 PM10/19/03
to
//
// LCave.java
// Create random caves using L shaped cookie cutters.
//
package game.world.mapgen;

import game.world.*;
import game.dice.*;

public class LCave extends RandomMap
{
/** Creates a new instance of LCave */
public LCave()
{
}

public void generate(Level lvl)
{
char[][] a = new char[70][20];

for (int i = 0; i < 150; i++)
{
int x = Dice.roll(6,60); // INT(RND * 59) + 6
int y = Dice.roll(6,10); // INT(RND * 9) + 6
int d = Dice.roll(0,3); // INT(RND * 4)

a[x][y] = '1';

int jmax = Dice.roll(0,4);
switch(d)
{
case 0:
for (int j = 1; j <= jmax; j++)// to FOR i = 1 TO
INT(RND * 5)
{
a[x + j][y] = '1';
a[x][y - j] = '1';
}
break;

case 1:
for (int j = 1; j <= jmax; j++)// to FOR i = 1 TO
INT(RND * 5)
{
a[x + j][y] = '1';
a[x][y + j] = '1';
}
break;

case 2:
for (int j = 1; j <= jmax; j++)// to FOR i = 1 TO
INT(RND * 5)
{
a[x - j][y] = '1';
a[x][y - j] = '1';
}
break;

case 3:
for (int j = 1; j <= jmax; j++)// to FOR i = 1 TO
INT(RND * 5)
{
a[x - j][y] = '1';
a[x][y + j] = '1';
}
break;
}//switch
} // 150 times

// Convert algorithm results to a maplevel.
map_x = 70;
map_y = 20;
lvl.resizeto(70,20);
for (int row = 0; row < 20; row++)
{
String maprow = "";
for (int col = 0; col < 70; col++)
{
if(a[col][row] == '1')
maprow = maprow + ".";
else
maprow = maprow + "#";
}
lvl.readmapline(maprow, row);
System.out.println(maprow);
}// for

}

// generate

}


Fu, Ren-Li

unread,
Oct 19, 2003, 2:42:35 PM10/19/03
to
// reads in a text line for the map..
// then converts it into tiles.
public void readmapline(String line, int mapy)
{
int tile_kind;

for (int xpos = 0; xpos < xmax; xpos++)
{
switch(line.charAt(xpos))
{
case '#':
tile_kind = TileType.WALL;
break;
case '+':
tile_kind = TileType.CLOSEDDOOR;
break;
case '-':
tile_kind = TileType.OPENDOOR;
break;
case '.':
tile_kind = TileType.FLOOR;
break;
case '<':
tile_kind = TileType.UPSTAIRS;
break;
case '>':
tile_kind = TileType.DNSTAIRS;
break;
case 'c':
tile_kind = TileType.CORRIDOR;
break;
case 's':
tile_kind = TileType.SECDOOR;
break;
default:
tile_kind = TileType.VOID;
break;
} // switch (on character, to find tile kind)

put_tile_by_tilekind(tile_kind, xpos, mapy);
} // for (every x position listed in map line.
return;
}

konijn

unread,
Oct 20, 2003, 3:02:58 AM10/20/03
to
"Fu, Ren-Li" <fr...@rogers.com> wrote in message news:<vWAkb.398642$Lnr1....@news01.bloor.is.net.cable.rogers.com>...

I'd just keep my tiles in one array ( if you're working in 1 color )
and then

for(int y = 0; y < ssy; y++)
for(int x = 0; x < ssx; x++)
buffergraphics.drawImage(tile[(int)screen[x][y]], x * dx, y * dy,
dx, dy, null);

tile[65] would be the tile of 'A' for example ( ASCII logic )
And when printting a string to the screen, I'd have some functions to
fill up the screen[][] array.

Cheers,
T.

konijn

unread,
Oct 20, 2003, 11:58:48 AM10/20/03
to
"Fu, Ren-Li" <fr...@rogers.com> wrote in message news:<hTAkb.398635$Lnr1....@news01.bloor.is.net.cable.rogers.com>...

> //
> // LCave.java
> // Create random caves using L shaped cookie cutters.
> //
> package game.world.mapgen;
>
> import game.world.*;
> import game.dice.*;
>
<big snip>

Looks good, only should change 70 & 20 by constants of course.

Cheers,
T.

R. Alan Monroe

unread,
Oct 20, 2003, 8:29:25 PM10/20/03
to

Cool, somebody found my idea useful! :^)

Alan

konijn

unread,
Oct 21, 2003, 2:11:21 AM10/21/03
to
"Fu, Ren-Li" <fr...@rogers.com> wrote in message news:<bRAkb.398629$Lnr1....@news01.bloor.is.net.cable.rogers.com>...
Slightly modified from Angband Vault file

# granite
X impenetrable rock
* treasure or trap
- secret door
+ door
^ trap
& chest
1 Normal random monster
2 OOD random monster
3 Tough OOD random monster
a Normal random item
b OOD random item
c Excellent random
A 1 & a
B 2 & b
C 3 & c

I think this could be a nice convention to start with in order to
easily swap map generators.

Any other ideas ?

Cheers,
T.

Fu, Ren-Li

unread,
Oct 20, 2003, 9:39:26 PM10/20/03
to
"R. Alan Monroe" <amon...@yahoo.com> wrote in message
news:F5%kb.79126$uJ2....@fe3.columbus.rr.com...
> ><big snip>

> >
>
> Cool, somebody found my idea useful! :^)
>
> Alan

Hey Alan :) Yes it looks pretty good :)

-frl


David Damerell

unread,
Oct 22, 2003, 11:52:02 AM10/22/03
to
konijn <kende...@hotmail.com> wrote:
>Slightly modified from Angband Vault file
> # granite
> X impenetrable rock

You've made, here, the assumption that one isn't going to do line-drawing
stuff for rooms, as Rogue/Hack/NetHack family games do.
--
David Damerell <dame...@chiark.greenend.org.uk> Kill the tomato!

konijn

unread,
Oct 23, 2003, 8:11:56 AM10/23/03
to
David Damerell <dame...@chiark.greenend.org.uk> wrote in message news:<Agg*ON...@news.chiark.greenend.org.uk>...

> konijn <kende...@hotmail.com> wrote:
> >Slightly modified from Angband Vault file
> > # granite
> > X impenetrable rock
>
> You've made, here, the assumption that one isn't going to do line-drawing
> stuff for rooms, as Rogue/Hack/NetHack family games do.

Not even, I dont have a clue what you're talking about, care to enlighten me ?

T.

Martin Read

unread,
Oct 23, 2003, 8:32:11 AM10/23/03
to

In Angband, a room looks like this:

#######
#.....#
...<..#
#.....#
#......
###.###

In Nethack, the same room looks like this:
-------
|.....|
...<..|
|.....|
|......
---.---

Different characters are used for different pieces of the room's walls.

m.
--
\_\/_/| Martin Read - my opinions are my own. share them if you wish.
\ / | a passer by was staring deep into your open skirt as we lay there
\/ | in the dirt as we lay there in the dirt should we make ourselves do
------+ painful things? and do they really hurt? -- Naevus, "Harm"

Jeff Lait

unread,
Oct 23, 2003, 10:43:06 PM10/23/03
to
kende...@hotmail.com (konijn) wrote in message news:<ab7ca5c9.03102...@posting.google.com>...

>
> Slightly modified from Angband Vault file
>
> # granite
> ... various definitions ...

> C 3 & c
>
> I think this could be a nice convention to start with in order to
> easily swap map generators.
>
> Any other ideas ?

I'd rather the meaning of the symbols was defined by the map itself.
The map thus consists of the raw array of symbols, the legend
describing the meaning of those symbols, and likely some additional
meta-data (does this map have a preferred depth? Etc.)

The pre-made .maps in POWDER, for example, have the following raw text
appearance:

----- lair.map ------
# A more complicated lair...
# This has a guaranteed mirror shield.

+--------------+
| , |
|,,,, ######## |
|###, #...#D]# |
|#.s,,s...s.D# |
|### ,#...#D.# |
| ,,,,######## |
| , |
+--------------+

: SQUARE_EMPTY
x: SQUARE_DOOR
s: SQUARE_SECRETDOOR
.: SQUARE_FLOOR
,: SQUARE_CORRIDOR
#: SQUARE_WALL
D: SQUARE_FLOOR, MOB_BLUEDRAGON
]: SQUARE_FLOOR, ITEM_REFLECTSHIELD
----- end of lair.map -----

Needless to say, this has some limitations. The legend in particular
is very specific to POWDER's enumerated definitions of all types.
This could be alleviated by defining certain meta-types, such as
SQUAREs (ground tiles), MOBs (mobiles, monsters, etc) and ITEMs
(loot). Then it might read:

D: square(floor), mob(blue dragon)
]: square(floor), item(shield of reflection)

One's code can then do a "wish" style pattern recognition on the
contents of the parenthesis to actually generate the item. If my
system lacked a shield of reflection, it might thus default to a
regular shield or to an amulet of reflection, both of which would be
adequate subsitutes.

- Jeff Lait
(POWDER: http://www.zincland.com/powder)

Mark 'Kamikaze' Hughes

unread,
Oct 26, 2003, 8:28:46 PM10/26/03
to
Martin Read <mpr...@chiark.greenend.org.uk>

wrote on 23 Oct 2003 13:32:11 +0100 (BST):
> In Nethack, the same room looks like this:
> -------
> |.....|
> ...<..|
> |.....|
> |......
> ---.---
> Different characters are used for different pieces of the room's walls.
> m.

You compute those (or ANSI line-drawing chars, or selecting from
multiple graphics images) from the neighboring tiles. I doubt Nethack
stores anything but a WALL constant internally.

--
<a href="http://kuoi.asui.uidaho.edu/~kamikaze/"> Mark Hughes </a>
"I believe in communication. If I communicate with you every so often,
you'll be bothered by what I say enough that you won't ask me to, which
means more sleep for me." -Something Positive, 2003Sep22

Fu, Ren-Li

unread,
Oct 26, 2003, 9:04:42 PM10/26/03
to
"Mark 'Kamikaze' Hughes" <kami...@kuoi.asui.uidaho.edu> wrote in message
news:slrnbpot6e....@kuoi.asui.uidaho.edu...

> Martin Read <mpr...@chiark.greenend.org.uk>
> wrote on 23 Oct 2003 13:32:11 +0100 (BST):
> > In Nethack, the same room looks like this:
> > -------
> > |.....|
> > ...<..|
> > |.....|
> > |......
> > ---.---
> > Different characters are used for different pieces of the room's walls.
> > m.
>
> You compute those (or ANSI line-drawing chars, or selecting from
> multiple graphics images) from the neighboring tiles. I doubt Nethack
> stores anything but a WALL constant internally.

True, I just thought of how this was done this afternoon.

When you print a wall, just do a table lookup or some sort of algorithm.
123
4x5
678

8 bits around the wall you're drawing. true = if they are walls. For
example, if (either or only) bits 2 or 7 are set, draw |.

-frl


konijn

unread,
Oct 27, 2003, 4:01:13 AM10/27/03
to
torespon...@hotmail.com (Jeff Lait) wrote in message news:<774acfb8.03102...@posting.google.com>...

I'm afraid that's way too complicated,
who would write a wish engine for this ?

But my proposed system could use like 3 flags
per tile ( like tome does ), lighting , monsters, treasure.

Cheers,
T.

Mark 'Kamikaze' Hughes

unread,
Oct 27, 2003, 9:38:17 AM10/27/03
to
Fu, Ren-Li <fr...@rogers.com>

wrote on Mon, 27 Oct 2003 02:04:42 GMT:
> "Mark 'Kamikaze' Hughes" <kami...@kuoi.asui.uidaho.edu> wrote in message
> news:slrnbpot6e....@kuoi.asui.uidaho.edu...
>> > Different characters are used for different pieces of the room's walls.
>> > m.
>> You compute those (or ANSI line-drawing chars, or selecting from
>> multiple graphics images) from the neighboring tiles. I doubt Nethack
>> stores anything but a WALL constant internally.
> True, I just thought of how this was done this afternoon.
> When you print a wall, just do a table lookup or some sort of algorithm.
> 123
> 4x5
> 678
> 8 bits around the wall you're drawing. true = if they are walls. For
> example, if (either or only) bits 2 or 7 are set, draw |.

You only need 8 bits if diagonal walls are solid in your game:
-- --
..\b|. Can't move from a to b.
..a\|.

In most roguelikes, you can cut that down to 4 bits:
1
8+2
4

0: #
1: |
2: -
etc.

A similar process can be used in graphical games to add transition
tiles and curves to blocks of similar terrain.

Martin Read

unread,
Oct 28, 2003, 10:52:20 AM10/28/03
to
kami...@kuoi.asui.uidaho.edu (Mark 'Kamikaze' Hughes) wrote:
>Martin Read <mpr...@chiark.greenend.org.uk>
>wrote on 23 Oct 2003 13:32:11 +0100 (BST):
>> In Nethack, the same room looks like this:
>> -------
>> |.....|
>> ...<..|
>> |.....|
>> |......
>> ---.---
>> Different characters are used for different pieces of the room's walls.
>> m.
>
> You compute those (or ANSI line-drawing chars, or selecting from
>multiple graphics images) from the neighboring tiles. I doubt Nethack
>stores anything but a WALL constant internally.

Guess what: It does. From nethack 3.4.1, include/rm.h:
/* Level location types */
#define STONE 0
#define VWALL 1
#define HWALL 2
#define TLCORNER 3
#define TRCORNER 4
#define BLCORNER 5
#define BRCORNER 6
#define CROSSWALL 7 /* For pretty mazes and special levels */
#define TUWALL 8
#define TDWALL 9
#define TLWALL 10
#define TRWALL 11
#define DBWALL 12
#define TREE 13 /* KMH */
#define SDOOR 14
#define SCORR 15
#define POOL 16
#define MOAT 17 /* pool that doesn't boil, adjust messages */
#define WATER 18
#define DRAWBRIDGE_UP 19
#define LAVAPOOL 20
#define IRONBARS 21 /* KMH */
#define DOOR 22
#define CORR 23
#define ROOM 24
#define STAIRS 25
#define LADDER 26
#define FOUNTAIN 27
#define THRONE 28
#define SINK 29
#define GRAVE 30
#define ALTAR 31
#define ICE 32
#define DRAWBRIDGE_DOWN 33
#define AIR 34
#define CLOUD 35

0 new messages