Right, well i'm making a simple game in c++
The grid
You move the mouse (the '@') around the grid and the idea is that you have to 'push' the 'apples' ('o's) into the 'store' (+ area)
The mouse and apple positions are stored in two arrays -
Then the following is used to 'move' the mouse, and soon apples -
now, can anyone suggest a simple way of adding a case of APPLE to get the apple character to move with the mouse?
thanks
The grid
You move the mouse (the '@') around the grid and the idea is that you have to 'push' the 'apples' ('o's) into the 'store' (+ area)
The mouse and apple positions are stored in two arrays -
Code:
void setInitialAppleCoordinates( int apple[6][2])
{
int matrix[6][2] = {{8, 3},
{3, 6},
{5, 6},
{8, 6},
{4, 8},
{5, 8} };
for ( int row( 0); row <= 5; ++row) //for each row (vertically)
for ( int col( 0); col <= 1; ++col) //for each column (horizontally)
apple[row][col] = matrix[row][col];
}
void setInitialMouseCoordinates( int mouse[])
{ //calculate mouse's coordinates at beginning of game
mouse[0] = 9; //y-coordinate: vertically
mouse[1] = 15; //x-coordinate: horizontally
}
Then the following is used to 'move' the mouse, and soon apples -
Code:
void moveMouse( const char grid[][ SIZEX+1], int mouse[], int key, string& mess, int& moves)
{ //move mouse in required direction
bool setKeyDirection( int key, int& DX, int& DY);
int DX( 0), DY( 0);
//find direction indicated by key
bool isArrowKey = setKeyDirection( key, DX, DY);
if ( ! isArrowKey) //key is not an arrow
mess = "INVALID KEY!";
//check new target position in grid & update mouse coordinates if move possible
switch( grid[mouse[0]+DY][mouse[1]+DX])
{ //...depending on what's on the target position in grid...
case TUNNEL: //can move
mouse[0] += DY; //go in that Y direction
mouse[1] += DX; //go in that X direction
moves++;
break;
case STORE: //can move
mouse[0] += DY; //go in that Y direction
mouse[1] += DX; //go in that X direction
moves++;
break;
case WALL: //can't move //hit a wall & stay there
cout << '\a'; //beep the alarm
mess = "CANNOT GO THERE!";
break;
}
}
now, can anyone suggest a simple way of adding a case of APPLE to get the apple character to move with the mouse?
thanks