Projekt/snake_main.c
void eat_apple(){

  //increment apples eaten
  snake.num_apples_eaten++;
  //move apple
    size_t i,j;
  uint8_t x,y;
  uint8_t apple_new_x,apple_new_y;
  generate_random:
  apple_new_x = BLOCK_SIZE + rand() % (SCREEN_WIDTH-BLOCK_SIZE); //scaled_rand(SCREEN_WIDTH-BLOCK_SIZE);
  apple_new_y = BLOCK_SIZE + rand() % (SCREEN_HEIGHT-BLOCK_SIZE);//scaled_rand(SCREEN_HEIGHT-BLOCK_SIZE);
  
  //make sure new apple position isn't on something

  for (i = 0; i < BLOCK_SIZE; i++){
    for (j = 0; j < BLOCK_SIZE; j++){
      //loop through the pixels of the new apple and check if they are activated
      x = apple_new_x + i;
      y = apple_new_y - j;
      if(*pixel_to_frame_buffer_position(x,y)){ //Checks all pixels in apple 
        goto generate_random;
      }
    }
    
  }
  

  apple.x0 = apple_new_x;
  apple.y0 = apple_new_y;
  //apple->block = (Block) {apple_new_x,apple_new_y};
  //apple.*block = (Block) {apple_new_x,apple_new_y};
  //apple.*block.y0 = apple_new_y;
  
  

  snake.num_blocks++;
  snake.blocks_array[snake.num_blocks-1] = snake.prev_tail;
}
/*function that "eats" the apple - moving the apple looks the same as creating a new one
also makes snake longer and increments snake.num_apples_eaten*/
function that "eats" the apple - moving the apple looks the same as creating a new one
also makes snake longer and increments snake.num_apples_eaten
function that " eats " the apple - moving the apple looks the same as creating a new one also makes snake longer and increments snake . num_apples_eaten
void eat_apple(){
  snake.num_apples_eaten++;
    size_t i,j;
  uint8_t x,y;
  uint8_t apple_new_x,apple_new_y;
  generate_random:
  apple_new_x = BLOCK_SIZE + rand() % (SCREEN_WIDTH-BLOCK_SIZE); 
  apple_new_y = BLOCK_SIZE + rand() % (SCREEN_HEIGHT-BLOCK_SIZE);
  for (i = 0; i < BLOCK_SIZE; i++){
    for (j = 0; j < BLOCK_SIZE; j++){
      x = apple_new_x + i;
      y = apple_new_y - j;
      if(*pixel_to_frame_buffer_position(x,y)){ 
        goto generate_random;
      }
    }
  }
  apple.x0 = apple_new_x;
  apple.y0 = apple_new_y;
  snake.num_blocks++;
  snake.blocks_array[snake.num_blocks-1] = snake.prev_tail;
}
void eat_apple ( ) { snake . num_apples_eaten ++ ; size_t i , j ; uint8_t x , y ; uint8_t apple_new_x , apple_new_y ; generate_random : apple_new_x = BLOCK_SIZE + rand ( ) % ( SCREEN_WIDTH - BLOCK_SIZE ) ; apple_new_y = BLOCK_SIZE + rand ( ) % ( SCREEN_HEIGHT - BLOCK_SIZE ) ; for ( i = 0 ; i < BLOCK_SIZE ; i ++ ) { for ( j = 0 ; j < BLOCK_SIZE ; j ++ ) { x = apple_new_x + i ; y = apple_new_y - j ; if ( * pixel_to_frame_buffer_position ( x , y ) ) { goto generate_random ; } } } apple . x0 = apple_new_x ; apple . y0 = apple_new_y ; snake . num_blocks ++ ; snake . blocks_array [ snake . num_blocks - 1 ] = snake . prev_tail ; }
function that "eats" the apple - moving the apple looks the same as creating a new one
also makes snake longer and increments snake.num_apples_eaten
function that " eats " the apple - moving the apple looks the same as creating a new one also makes snake longer and increments snake . num_apples_eaten
//increment apples eaten //move apple //scaled_rand(SCREEN_WIDTH-BLOCK_SIZE); //scaled_rand(SCREEN_HEIGHT-BLOCK_SIZE); //make sure new apple position isn't on something //loop through the pixels of the new apple and check if they are activated //Checks all pixels in apple  //apple->block = (Block) {apple_new_x,apple_new_y}; //apple.*block = (Block) {apple_new_x,apple_new_y}; //apple.*block.y0 = apple_new_y;