Ahhh, that seems to have fixed it! Thanks for your help!
Revised code:
Code:
char movedir;
field[charx][chary]='1';
while ((movedir = getch()) != EOF
&& movedir != 'q') { //'q' for quit
if (movedir == '8'){ chary--;
return 0;} //These return 0s make the character instantly move
else if (movedir == '4'){ charx--;
return 0;}
else if (movedir == '6'){ charx ++;
return 0;}
else if (movedir == '2'){ chary ++;
return 0;}
else return 0;} //Hopefully more commands later!
The only problem is that it redraws the entire map every time the character moves.... which is not going to be helpful in the long run. Currently, my mapdrawing code is as follows
Code:
int x(0);
int y(0);
int x1(0); // initialise the map displayers's x location to allow for the screen display to be half of the map
int y1(0); // initialise the map displayer's y location
x1 = mapx/2 - 50; // sets the map display to halfway width
y1 = mapy/2 - 15; //sets the map display to halfway height
objects(); //Check for object spaces - currently limited to the '@' character
while (y < 30) { //This may seem odd, but not all of the map is being displayed.
while (x < 100) { //This way, items/monsters/whatevers can be offscreen
if (field[x1][y1] == 1){ //checks for terrain type - empty space terrain
textcolor (7);
cout<<".";}
else if (field[x1][y1] == 99){ //character
textcolor (15);
cout<<"@";}
else
cout<<" "; //no terrain displayed at all in this space.
x++;
x1++;
}
x = 0;
x1 = mapx/2 - 50; //resets the map width display
y++;
y1++;
}
return 0;
Ultimately, I'd like to have a way of the map remaining static or semi-static while objects move around on top of this... But I'm not sure how to achieve this, since I'm using the array to display x and y positions, which is really inefficient - if one thing changes, the entire map has to be redrawn. Is there any way of positioning the print cursor so I can reprint only the objects that are moving rather than the entire screen?