Jump to content
  • Advertisement
Sign in to follow this  
Behemyth

Help: Grid Based Anomolies

This topic is 2379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!