I am attempting to initialise an array to store segments of a snake for a snake game
the structure of the type ‘segment’ is defined here
typedef struct snakeSegment {
int x,y;
}segment
Then I declare the structure of the snake (made up by segments)
struct snakeSegment snake[200];
The following code is the initialisation of the snake array
/*****************************************/
/* Create snake array of length snake_length */
void initSnake(segment snake[], int snake_length)
{
int x = 50;
int y = 50;
snake[0].x= x;
snake[0].y= y;
for (int i = 1; i < 21; i++ )
{
snake[i].x= snake[i-1].x;
snake[i].y= snake[i-1].y;
x++;
}
}
It reaches a problem whenever it gets to the main method and trys to run the initSnake() function
here is the main function
int main() {
initDevices();
remainingSnakes = initGame();
while ( remainingSnakes ) {
// waitForStart();
snakeInPlay= 1;
currentDirection= 'N';
initSnake(snake_length, snake );
renderSnake(snake_length);
}}
On the initSnake() line of code, it produces this error upon compiling:
of type “int” is incompatible with parameter of type “segment *”
I’ve asked around my peers and some seem to be having this issue. We would look for an alternative soloution but we were provided with a main function that was not to be greatly altered.
Any feedback would be greatly appreciated as I have no idea why I’m recieving this error. Thanks!
here is the main function we are meant to use to model against:
initialiseDevices();
remainingSnakes= initialiseGame();
while ( remainingSnakes ) {
waitForStart();
snakeInPlay= 1;
currentDirection= N;
snakeLength= 10;
initialiseSnake( snake, snakeLength );
renderSnake( snake, snakeLength );
while ( snakeInPlay ) {
newDirection= ReadBoardAngle();
currentDirection= moveSnake ( snake, newDirection, snakeLength );
snakeInPlay= testSnakeCollision( snake, snakeLength );
delay();
}
}
This aren’t the parameters your function takes:
initSnake(snake_length, snake );You probably meant
initSnake(snake, snake_length);