• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

### #ActualBehemyth

Posted 14 April 2012 - 06:10 PM

Using the console, being the noob I am, i've created an array that is 24 by 80 filling the entire console screen excluding the line on the bottom for information. The perimeter of this grid is composed of X's, otherwise thought of as a block.
A random starting point and ending point is created that are not next to each other or fall on the same collumn or row. These points are also on the perimeter blocks. The purpose of the following code is create the first block inside the area.
This is part of the code for a procedural "ice maze" so when you move in one direction you can't move again until you hit a block. The funny thing is, when I run this code, the random block for traveling east is one line underneath the intended line. Also, the parts for travelling north and west don't evan work. If you could help me I'd be much obliged!

void procedure (char create[][80] ) {
int i=0;
int random_value=0;
int index_x_p=index_x_s; //current point
int index_y_p=index_y_s;
int index_x_t=index_x_s; //counting point
int index_y_t=index_y_s;
if(index_x_p==0){ //if going east
for(i=0; index_x_t+1 != 'X';i++){ //finds the distance to the block.
index_x_t=index_x_t+1;
}
random_value=(rand()%i)+1; //creates a random value based of the distance
index_x_p=index_x_p+random_value; // the current point changes
create[index_y_p][index_x_p+1]='X';// a block is placed on the opposite side of the point
int index_x_t=index_x_p; //resets test to current point
int index_y_t=index_y_p;
}
else if(index_x_p==79){ //if going west
for(i=0; index_x_t-1 != 'X';i++){
index_x_t=index_x_t-1;
}
random_value=(rand()%i)+1;
index_x_p=index_x_p-random_value;
create[index_y_p][index_x_p-1]='X';
int index_x_t=index_x_p;
int index_y_t=index_y_p;
}
else if(index_y_p==0){ //if going south
for(i=0; index_y_t+1 != 'X';i++){
index_y_t=index_y_t+1;
}
random_value=(rand()%i)+1;
index_y_p=index_y_p+random_value;
create[index_y_p+1][index_x_p]='X';
int index_x_t=index_x_p;
int index_y_t=index_y_p;
}
else if(index_y_p==23){ //if going north
for(i=0; index_y_t-1 != 'X';i++){
index_y_t=index_y_t-1;
}
random_value=(rand()%i)+1;
index_y_p=index_y_p-random_value;
create[index_y_p-1][index_x_p]='X';
int index_x_t=index_x_p;
int index_y_t=index_y_p;
}
}


Behemyth

### #2Behemyth

Posted 14 April 2012 - 06:09 PM

Using the console, being the noob I am, i've created an array that is 24 by 80 filling the entire console screen excluding the line on the bottom for information. The perimeter of this grid is composed of X's, otherwise thought of as a block.
A random starting point and ending point is created that are not next to each other or fall on the same collumn or row. These points are also on the perimeter blocks. The purpose of the following code is create the first block inside the area.
This is part of the code for a procedural "ice maze" so when you move in one direction you can't move again until you hit a block. The funny thing is, when I run this code, the random block for traveling east is one line underneath the intended line. Also, the parts for travelling north and west don't evan work. If you could help me I'd be much obliged!

void procedure (char create[][80] ) {
int i=0;
int random_value=0;
int index_x_p=index_x_s; //current point
int index_y_p=index_y_s;
int index_x_t=index_x_s; //counting point
int index_y_t=index_y_s;
if(index_x_p==0){ //if going east
for(i=0; index_x_t+1 != 'X';i++){ //finds the distance to the block.
index_x_t=index_x_t+1;
}
random_value=(rand()%i)+1; //creates a random value based of the distance
index_x_p=index_x_p+random_value; // the current point changes
create[index_y_p][index_x_p+1]='X';// a block is placed on the opposite side of the point
int index_x_t=index_x_p; //resets test to current point
int index_y_t=index_y_p;
}
else if(index_x_p==79){ //if going west
for(i=0; index_x_t-1 != 'X';i++){
index_x_t=index_x_t-1;
}
random_value=(rand()%i)+1;
index_x_p=index_x_p-random_value;
create[index_y_p][index_x_p-1]='X';
int index_x_t=index_x_p;
int index_y_t=index_y_p;
}
else if(index_y_p==0){ //if going south
for(i=0; index_y_t+1 != 'X';i++){
index_y_t=index_y_t+1;
}
random_value=(rand()%i)+1;
index_y_p=index_y_p+random_value;
create[index_y_p+1][index_x_p]='X';
int index_x_t=index_x_p;
int index_y_t=index_y_p;
}
else if(index_y_p==23){ //if going north
for(i=0; index_y_t-1 != 'X';i++){
index_y_t=index_y_t-1;
}
random_value=(rand()%i)+1;
index_y_p=index_y_p-random_value;
create[index_y_p-1][index_x_p]='X';
int index_x_t=index_x_p;
int index_y_t=index_y_p;
}
}


EDIT: If you prefer some easier to read text...

void procedure (char create[][80] ) {
int i=0;
int random_value=0;
int index_x_p=index_x_s; //current point
int index_y_p=index_y_s;
int index_x_t=index_x_s; //counting point
int index_y_t=index_y_s;
if(index_x_p==0){ //if going east
for(i=0; index_x_t+1 != 'X';i++){ //finds the distance to the block.
index_x_t=index_x_t+1;
}
random_value=(rand()%i)+1; //creates a random value based of the distance
index_x_p=index_x_p+random_value; // the current point changes
create[index_y_p][index_x_p+1]='X';// a block is placed on the opposite side of the point
int index_x_t=index_x_p; //resets test to current point
int index_y_t=index_y_p;
}
else if(index_x_p==79){ //if going west
for(i=0; index_x_t-1 != 'X';i++){
index_x_t=index_x_t-1;
}
random_value=(rand()%i)+1;
index_x_p=index_x_p-random_value;
create[index_y_p][index_x_p-1]='X';
int index_x_t=index_x_p;
int index_y_t=index_y_p;
}
else if(index_y_p==0){ //if going south
for(i=0; index_y_t+1 != 'X';i++){
index_y_t=index_y_t+1;
}
random_value=(rand()%i)+1;
index_y_p=index_y_p+random_value;
create[index_y_p+1][index_x_p]='X';
int index_x_t=index_x_p;
int index_y_t=index_y_p;
}
else if(index_y_p==23){ //if going north
for(i=0; index_y_t-1 != 'X';i++){
index_y_t=index_y_t-1;
}
random_value=(rand()%i)+1;
index_y_p=index_y_p-random_value;
create[index_y_p-1][index_x_p]='X';
int index_x_t=index_x_p;
int index_y_t=index_y_p;
}
}

Behemyth

### #1Behemyth

Posted 14 April 2012 - 06:07 PM

Using the console, being the noob I am, i've created an array that is 24 by 80 filling the entire console screen excluding the line on the bottom for information. The perimeter of this grid is composed of X's, otherwise thought of as a block.
A random starting point and ending point is created that are not next to each other or fall on the same collumn or row. These points are also on the perimeter blocks. The purpose of the following code is create the first block inside the area.
This is part of the code for a procedural "ice maze" so when you move in one direction you can't move again until you hit a block. The funny thing is, when I run this code, the random block for traveling east is one line underneath the intended line. Also, the parts for travelling north and west don't evan work. If you could help me I'd be much obliged!

void procedure (char create[][80] ) {
int i=0;
int random_value=0;
int index_x_p=index_x_s; //current point
int index_y_p=index_y_s;
int index_x_t=index_x_s; //counting point
int index_y_t=index_y_s;
if(index_x_p==0){ //if going east
for(i=0; index_x_t+1 != 'X';i++){ //finds the distance to the block.
index_x_t=index_x_t+1;
}
random_value=(rand()%i)+1; //creates a random value based of the distance
index_x_p=index_x_p+random_value; // the current point changes
create[index_y_p][index_x_p+1]='X';// a block is placed on the opposite side of the point
int index_x_t=index_x_p; //resets test to current point
int index_y_t=index_y_p;
}
else if(index_x_p==79){ //if going west
for(i=0; index_x_t-1 != 'X';i++){
index_x_t=index_x_t-1;
}
random_value=(rand()%i)+1;
index_x_p=index_x_p-random_value;
create[index_y_p][index_x_p-1]='X';
int index_x_t=index_x_p;
int index_y_t=index_y_p;
}
else if(index_y_p==0){ //if going south
for(i=0; index_y_t+1 != 'X';i++){
index_y_t=index_y_t+1;
}
random_value=(rand()%i)+1;
index_y_p=index_y_p+random_value;
create[index_y_p+1][index_x_p]='X';
int index_x_t=index_x_p;
int index_y_t=index_y_p;
}
else if(index_y_p==23){ //if going north
for(i=0; index_y_t-1 != 'X';i++){
index_y_t=index_y_t-1;
}
random_value=(rand()%i)+1;
index_y_p=index_y_p-random_value;
create[index_y_p-1][index_x_p]='X';
int index_x_t=index_x_p;
int index_y_t=index_y_p;
}
}


Behemyth

PARTNERS