Subject: Some more simple level generation in QBasic Date: Fri, 22 Feb 2002 22:23:23 GMT From: olli.wilkman@pp.inet.fi (Olli Wilkman) Organization: Sonera corp Newsgroups: rec.games.roguelike.development (Someone's probably done all this already, but what the hell) Inspired by the post by R. Alan Monroe (17.2.2002), I called on my old QBasic skills (that's what I started coding with) and tested a very simple level generation algorithm that uses (I don't know proper terms) random movers, which are placed onto a clear map in random locations and move around, filling map squares with desired type. By use of parameters, I can control the number of "walkers" used and the steps they take. By changing these and applying the algorithm several times, I can create different kinds of levels. By using few walkers with many steps, I can create cavernous dungeon levels. Several walkers with few steps make rather nice trees or ruins on a outdoors map. I also used my procedure to place some items and monsters and a player character (one walker with only one step) onto the map, though these are just to make it look better. The sample code here creates an outdoors map with trees, some old ruins, a small pond. It also scatters around some monsters, items and a red player character. I used the same kind of graphics style as in ADOM. This algorithm is probably not all that useful, but it's simple and it could probably be used in some light-weigth RL project that does not need extremely complicated or realistic level generation. One of the big flaws is that it can't create dungeons with straight tunnels. ---- Begin code block ---- DECLARE SUB walk (count AS INTEGER, steps AS INTEGER, c AS INTEGER, char AS STRING) DIM SHARED xMax AS INTEGER, yMax AS INTEGER yMax = 23 xMax = 80 CLS RANDOMIZE TIMER start: ' First draw the ground (this outdoors map uses light green dots as the ' basic ground, a dungeon would probably have dark grey '#' symbols) FOR x = 1 TO xMax FOR y = 1 TO yMax COLOR 10, 0 LOCATE y, x: PRINT "." NEXT y NEXT x ' ' walk(count, steps, c, char) ' ' The first parameter in the "walk" procedure is the number of ' different walkers. All are assigned a random starting location ' within the bounds of (xMax, yMax). ' The second parameter is the amount of steps each walker moves. ' For both axis, the chance of moving on step in either direction ' is 50% (so the walker has a 25% chance of not moving at all). ' The third parameter is the color of the character to be drawn. ' The fourth parameter is the character to be drawn. ' Example: ' walk(5, 30, 2, "T") ' This will create five small patches of trees. CALL walk(100, 2, 2, "T") 'trees CALL walk(30, 7, 8, "#") 'ruins CALL walk(40, 1, 8, "*") 'rocks CALL walk(1, 200, 1, "=") 'a pond CALL walk(10, 1, 10, "o") 'some orcs CALL walk(5, 1, 13, "o") 'some different colour orcs CALL walk(3, 1, 9, "g") 'some goblins CALL walk(3, 1, 7, ")") 'some weapons CALL walk(3, 1, 7, "[") 'some armour CALL walk(5, 1, 6, "%") 'some food items CALL walk(1, 1, 4, "@") 'a player character a$ = INPUT$(1) 'Wait for input SELECT CASE (a$) CASE CHR$(27) 'Quit if Esc pressed END CASE ELSE 'Otherwise create a new map GOTO start END SELECT SUB walk (count AS INTEGER, steps AS INTEGER, c AS INTEGER, char AS STRING) FOR ll = 1 TO count wx = INT(RND * xMax) + 1 wy = INT(RND * yMax) + 1 FOR l = 1 TO steps IF wx > xMax THEN wx = xMax IF wy > yMax THEN wy = yMax IF wx < 1 THEN wx = 1 IF wy < 1 THEN wy = 1 COLOR c, 0 LOCATE wy, wx: PRINT char wx = wx + (RND * 1 - RND * 1) wy = wy + (RND * 1 - RND * 1) NEXT l NEXT ll END SUB ---- End code block ---- -- Olli "Dronir" Wilkman The Heirophant is Disguised and Confused.