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?
-----
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);
}
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;
}
}
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
}
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;
}
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.
Looks good, only should change 70 & 20 by constants of course.
Cheers,
T.
Cool, somebody found my idea useful! :^)
Alan
# 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.
Hey Alan :) Yes it looks pretty good :)
-frl
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!
Not even, I dont have a clue what you're talking about, care to enlighten me ?
T.
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"
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)
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
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
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.
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.
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