Comparing Array data with Multi-Array data

Is anything similar to the following possible?

if(mapArray[fx] == krx[] && mapArray[fy] == krx[])
{
then do something;
}

Basically, I want to do what the below 'if' statement does, but checking a multi with a non-multi array.
if(mapArray[fx][fy] == mapArray[rx][ry])


I've tried this a number of ways, but I'm not having much luck. Is it even possible to check if one dimension of a multi-array matches with data from a non-multi array?

How can I match up a multi array to a regular array? Related code is below. If thats not enough..here all of it - http://rafb.net/p/pzylVF44.html

Thanks much!

int collision_chk(int fx,int fy, int rx, int ry, int krx[], int kry[]);

char Rider = 'R';
int krx[3]={3,4,5}; //Arrays for additional Riders
int kry[3]={3,4,5}; //...

int main()
{
int fx = 0, fy = 0, rx = 8, ry = 8;
char cur = '@';
mapArray[fx][fy] = Frodo;
mapArray[rx][ry] = Rider;
for(int i=0; i<3; i++) //Creates multiple riders
{
int tempx = krx[i];
int tempy = kry[i];
mapArray[tempx][tempy] = Rider;
}
mapArray[9][11] = Exit;
SetColor(YELLOW);
draw_map();
while(1) {
if( cur == 'q') exit;
frodo_movement(cur,fx,fy);
turn_counter(); // This function updates move counter after frodo moves
collision_chk(fx, fy, rx, ry, krx, kry);
for(int i=0; i<3; i++) //
{
int tempx = krx[i];
int tempy = kry[i];
rider_movement(tempx,tempy);
krx[i]=tempx;
kry[i]=tempy;
}
rider_movement(rx,ry);
collision_chk(fx, fy, rx, ry, krx, kry);
draw_map();
cur = getch();
system ("cls");
}
}



int collision_chk(int fx, int fy, int rx, int ry, int krx[], int kry[])
{
if(mapArray[fx][fy] == mapArray[rx][ry])//Checks each loop to see if Rider and Frodo meet
{
system("cls");
SetColor(WHITE);
cout << "Frodo has been killed by a Rider." << endl;
cout << endl;
game_over();
}

if(mapArray[fx][fy] == mapArray[9][11])
{
level_complete();
}
return 0;
}
You can compare arrays by comparing all the values, so you can compare arrays with different numbers of dimensions

eg:
1
2
3
4
5
for ( unsigned y = 0; y<height; y++ )
    for ( unsigned x = 0; x<width; x++ )
        if ( _2Darray[y][x] != _1Darray[y*width+x])
            //arrays have different contents
//If the loops had end without getting in the if block the arrays have the same values 
Last edited on
Topic archived. No new replies allowed.