rand() in attempted roguelike?

I've been trying to create a roguelike, and I was trying to create randomly generated rooms like in Rogue. I'm seperating my map array into sections and giving it a 50% chance of spawning a room, but right now it doesn't do anything but spawn solid rock. What am I doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
int MapSizeX = 100;
int MapSizeY = 100;
char map[100][100] = {};
char wall = 178;
int ViewDistance = 10;
int x = 25;
int y = 25;
int Groom = 1;
int RoomArea = 10;

void Init()
{
     map[MapSizeY][MapSizeX];
     for(int a = 0; a < MapSizeY; a++)
     {
             for(int b = 0; b < MapSizeX; b++)
             {
                     map[b][a] = wall;
             }
     } 
     for(int c = 0; c < MapSizeX; c = c + RoomArea)
     {
            for(int d = 0; d < MapSizeY; d = d + RoomArea)
            {
                  int Groom = (rand() % 2) + 1;
                  if(Groom == 2)
                  {
                           for(int a = 0; a < RoomArea; a++)
                           {
                                   for(int b = 0; b < RoomArea; b++)
                                   {
                                         map[a][b] = ' ';  
                                   }
                           }        
                  }
            }
     }
     
}
Looks fine to me. Have you tried setting a breakpoint and stepping through that part?
The problem is your innermost loop:

1
2
3
4
for(int b = 0; b < RoomArea; b++)
{
    map[a][b] = ' ';  
}


You are only ever setting the upper-left (or maybe lower-left) corner of the map. You want to do this:

1
2
3
4
for(int b = 0; b < RoomArea; b++)
{
    map[a + c][b + d] = ' ';  
}


You just haven't seen the carved area because you are initializing x and y to 25 with a view distance of 10.
Oh, I get it! Thanks!
Topic archived. No new replies allowed.