I have decided to see if I can make some generator for a level system and to study this I'm currently looking at rogue like programming
http://roguebasin.roguelikedevelopment.org...title=Main_PageI would LOVE to wrap my head around it, Because I CAN'T see a program randomly generating 2 doors, then generating the next ones because this WOULD conflict errors, like just say the first room was North and South, you loop around and the last door would make it so you appear in the last room.
Kinda like:
XXX
X X
SXX
S being the start. You would loop around, wall detection just seams far too hard for this type of work, and FAR too many if statements.
I could see something like, just say you have 9 room textures,
789
456
123
room 1: NORTH and EAST exits
room 2: NORTH and EAST and WEST exits
room 3: NORTH and SOUTH exits
.etc.
then you could generate from point 1, picking a 1-9 room, then if say 4 is selected you would display 4's exits, like NORTH, EAST and SOUTH then the user goes north, because we came from the bottom up you would have to pick IF USER SELECT NORTH randomly pick room 4 5 6 7 8 9.
Something like that? if I have explained myself correctly. That would be pritty good for, say creating new walls because the user 'destroyed' it, replace the room with another appropreate room.
EDIT:
I mocked up something in console written in c#
CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Level_Generator
{
class Program
{
static string a = "┌";
static string b = "─";
static string c = "┐";
static string d = "│";
static string e = "┘";
static string f = "└";
static string g = " ";
static string Space = "";
static string Space1 = "";
static string Space2 = "";
static string Space3 = "";
static string Space4 = "";
static string Space5 = "";
static string Space6 = "";
static string Space7 = "";
static string Space8 = "";
static string Space9 = "";
static int genlevel;
static int prevgenlevel;
static Random randy = new Random((int)DateTime.Now.Ticks);
static void Main(string[] args)
{
string end = "no";
do
{
Space = "";
Space1 = "";
Space2 = "";
Space3 = "";
Space4 = "";
Space5 = "";
Space6 = "";
Space7 = "";
Space8 = "";
Space9 = "";
//789
//456
//123
//** Do Space 7
SpaceGen();
Space7 = Space;
Console.Write(Space);
// If space 7 is right then do this
if (Space7 == b || Space7 == c || Space7 == e)
{
RightGen();
}
//** Since space 8 has no more connections with space 7 we can continue to the space 8 code and generate a space for it
// Do Space 8
SpaceGen();
Space8 = Space;
// Show the generated level
Console.Write(Space);
// If space 7 is right then do this
if (Space8 == b || Space8 == c || Space8 == e)
{
RightGen();
}
//** Since space 9 has no more connections with space 8 we can continue to the space 9 code and generate a space for it
// Do Space 9
SpaceGen();
Space9 = Space;
// Show the generated level
Console.WriteLine(Space); //Start at 4 now
// If space 9 is right then do this
if (Space9 == b || Space9 == c || Space9 == e)
{
RightGen();
}
//
//** Start space 4 now check space 7 if it's pointing down
// If space 1 is right then do this
if (Space7 == d || Space7 == e || Space7 == f)
{
DownGen();
Space4 = Space;
}
// Else generate somehing else
else
{
SpaceGen();
Space4 = Space;
}
// Show the generated level
Console.Write(Space);
//** Do Space 5, if space 8 is down check it
if (Space8 == d || Space8 == e || Space8 == f)
{
DownGen();
Space5 = Space;
}
// Else if space 4 is right
else if (Space8 == a || Space8 == b || Space8 == f)
{
LeftGen();
Space5 = Space;
}
// Else just generate!
else
{
SpaceGen();
Space5 = Space;
}
// Show the generated level
Console.Write(Space);
//** Do Space 6, if space 9 is down check it
if (Space9 == d || Space9 == e || Space9 == f)
{
DownGen();
Space6 = Space;
}
// Else if space 4 is right
else if (Space9 == a || Space9 == b || Space9 == f)
{
LeftGen();
Space6 = Space;
}
// Else just generate!
else
{
SpaceGen();
Space6 = Space;
}
// Show the generated level
Console.WriteLine(Space); //Start at 1 now
//
//** Start space 1 now check space 4 if it's pointing down
// If space 1 is right then do this
if (Space4 == d || Space4 == e || Space4 == f)
{
DownGen();
Space1 = Space;
}
// Else generate somehing else
else
{
SpaceGen();
Space1 = Space;
}
// Show the generated level
Console.Write(Space);
//** Do Space 2, if space 5 is down check it
if (Space5 == d || Space5 == e || Space5 == f)
{
DownGen();
Space2 = Space;
}
// Else if space 4 is right
else if (Space5 == a || Space5 == b || Space5 == f)
{
LeftGen();
Space2 = Space;
}
// Else just generate!
else
{
SpaceGen();
Space2 = Space;
}
// Show the generated level
Console.Write(Space);
//** Do Space 3, if space 6 is down check it
if (Space6 == d || Space6 == e || Space6 == f)
{
DownGen();
Space3 = Space;
}
// Else if space 4 is right
else if (Space6 == a || Space6 == b || Space6 == f)
{
LeftGen();
Space3 = Space;
}
// Else just generate!
else
{
SpaceGen();
Space3 = Space;
}
// Show the generated level
Console.WriteLine(Space); // New Line and end the generator
Console.WriteLine("");
Console.WriteLine("Generate again?");
Console.WriteLine("(1) Generate");
Console.WriteLine("(2) Generate and Clear");
Console.WriteLine("(3) Exit");
Console.Write(">");
int Choice = Convert.ToInt16(Console.ReadLine());
if (Choice == 2)
{
Console.Clear();
}
if (Choice == 3)
{
end = "yes";
}
Console.WriteLine("");
} while (end == "no");
}
/// <summary>
/// Generate right
/// </summary>
public static void RightGen()
{
// Randomize
genlevel = randy.Next(1, 4);
// 3 Spot picker
if (genlevel == 1)
{
Space = b;
}
if (genlevel == 2)
{
Space = c;
}
if (genlevel == 3)
{
Space = e;
}
}
/// <summary>
/// Generate Left
/// </summary>
public static void LeftGen()
{
// Randomize
genlevel = randy.Next(1, 4);
// 3 Spot picker
if (genlevel == 1)
{
Space = a;
}
if (genlevel == 2)
{
Space = b;
}
if (genlevel == 3)
{
Space = f;
}
}
/// <summary>
/// Generate Up
/// </summary>
public static void UpGen()
{
// Randomize
genlevel = randy.Next(1, 4);
// 3 Spot picker
if (genlevel == 1)
{
Space = a;
}
if (genlevel == 2)
{
Space = c;
}
if (genlevel == 3)
{
Space = d;
}
}
/// <summary>
/// Generate Down
/// </summary>
public static void DownGen()
{
// Randomize
genlevel = randy.Next(1, 4);
// 3 Spot picker
if (genlevel == 1)
{
Space = d;
}
if (genlevel == 2)
{
Space = e;
}
if (genlevel == 3)
{
Space = f;
}
}
/// <summary>
/// Generate Blank space, used for a starter
/// </summary>
public static void SpaceGen()
{
// Randomize
genlevel = randy.Next(1, 8);
// 9 Spot picker
if (genlevel == 1)
{
Space = a;
}
if (genlevel == 2)
{
Space = b;
}
if (genlevel == 3)
{
Space = c;
}
if (genlevel == 4)
{
Space = d;
}
if (genlevel == 5)
{
Space = e;
}
if (genlevel == 6)
{
Space = f;
}
if (genlevel == 7)
{
Space = g;
}
}
}
}
All it does is scan the previously generated spots, I suppose I could fix it up a little bit and make a make type of thing i'm SURE there's gotta be an easier way for this, I'll update as I find more information out.
Edit2:
http://nrkn.com/1kRl/v3/Roguelike c# under 1kb

.
This post has been edited by frostyraver: 28 Jun, 2009 - 09:59 AM