Projekt/snake_main.c
void check_collision(){
  //helper that returns whether or not the pixel we are checking is outside the screen
  bool check_outside_screen(uint16_t x, uint16_t y){
    return (x>= SCREEN_WIDTH || x<= 0 || y>=SCREEN_HEIGHT || y<=0);
  }
  /*helper that returns whether or not we collided with our tail*/
  bool check_tail(uint16_t x, uint16_t y){
    int i;
    //iterate through each block and see if x0,y0 are the same as those of the head - in that case we collided
    for (i = 1; i < snake.num_blocks; i++){
      if(x == snake.blocks_array[i].x0 && y == snake.blocks_array[i].y0){
        return true;
      }
    }
    return false;
    
  }
  /*returns whether or not the head is on an apple*/
  bool is_apple(uint16_t x, uint16_t y){
    return  x >= apple.x0 &&  x< (apple.x0+BLOCK_SIZE) && y >= apple.y0 && y < (apple.y0 + BLOCK_SIZE);
  }
  uint16_t i,j,x,y,k,m;
  for(i = 0; i< BLOCK_SIZE+1; i++){
    for(j = 0; j<BLOCK_SIZE+1; j++){
      x = snake.blocks_array[0].x0 + i;
      y = snake.blocks_array[0].y0 - j;

      bool head_is_outside_screen = check_outside_screen(x,y);
      bool head_collided_with_tail = check_tail(x,y);
      if(is_apple(x,y)){
          eat_apple();
          return;
      }
    }
  }
    for(k = 0; k< BLOCK_SIZE; k++){
    for(m = 0; m<BLOCK_SIZE; m++){
      x = snake.blocks_array[0].x0 + k;
      y = snake.blocks_array[0].y0 - m;

      bool head_is_outside_screen = check_outside_screen(x,y);
      bool head_collided_with_tail = check_tail(x,y);
      if(head_is_outside_screen || head_collided_with_tail){
        game_over();
      }
    }
  }
      

  
}
/*checks if the head of the snake has collided with anything, such as an apple, the wall or its own tail*/
checks if the head of the snake has collided with anything, such as an apple, the wall or its own tail
checks if the head of the snake has collided with anything such as an apple the wall or its own tail
void check_collision(){
  bool check_outside_screen(uint16_t x, uint16_t y){
    return (x>= SCREEN_WIDTH || x<= 0 || y>=SCREEN_HEIGHT || y<=0);
  }
  bool check_tail(uint16_t x, uint16_t y){
    int i;
    for (i = 1; i < snake.num_blocks; i++){
      if(x == snake.blocks_array[i].x0 && y == snake.blocks_array[i].y0){
        return true;
      }
    }
    return false;
  }
  bool is_apple(uint16_t x, uint16_t y){
    return  x >= apple.x0 &&  x< (apple.x0+BLOCK_SIZE) && y >= apple.y0 && y < (apple.y0 + BLOCK_SIZE);
  }
  uint16_t i,j,x,y,k,m;
  for(i = 0; i< BLOCK_SIZE+1; i++){
    for(j = 0; j<BLOCK_SIZE+1; j++){
      x = snake.blocks_array[0].x0 + i;
      y = snake.blocks_array[0].y0 - j;
      bool head_is_outside_screen = check_outside_screen(x,y);
      bool head_collided_with_tail = check_tail(x,y);
      if(is_apple(x,y)){
          eat_apple();
          return;
      }
    }
  }
    for(k = 0; k< BLOCK_SIZE; k++){
    for(m = 0; m<BLOCK_SIZE; m++){
      x = snake.blocks_array[0].x0 + k;
      y = snake.blocks_array[0].y0 - m;
      bool head_is_outside_screen = check_outside_screen(x,y);
      bool head_collided_with_tail = check_tail(x,y);
      if(head_is_outside_screen || head_collided_with_tail){
        game_over();
      }
    }
  }
}
void check_collision ( ) { bool check_outside_screen ( uint16_t x , uint16_t y ) { return ( x >= SCREEN_WIDTH || x <= 0 || y >= SCREEN_HEIGHT || y <= 0 ) ; } bool check_tail ( uint16_t x , uint16_t y ) { int i ; for ( i = 1 ; i < snake . num_blocks ; i ++ ) { if ( x == snake . blocks_array [ i ] . x0 && y == snake . blocks_array [ i ] . y0 ) { return true ; } } return false ; } bool is_apple ( uint16_t x , uint16_t y ) { return x >= apple . x0 && x < ( apple . x0 + BLOCK_SIZE ) && y >= apple . y0 && y < ( apple . y0 + BLOCK_SIZE ) ; } uint16_t i , j , x , y , k , m ; for ( i = 0 ; i < BLOCK_SIZE + 1 ; i ++ ) { for ( j = 0 ; j < BLOCK_SIZE + 1 ; j ++ ) { x = snake . blocks_array [ 0 ] . x0 + i ; y = snake . blocks_array [ 0 ] . y0 - j ; bool head_is_outside_screen = check_outside_screen ( x , y ) ; bool head_collided_with_tail = check_tail ( x , y ) ; if ( is_apple ( x , y ) ) { eat_apple ( ) ; return ; } } } for ( k = 0 ; k < BLOCK_SIZE ; k ++ ) { for ( m = 0 ; m < BLOCK_SIZE ; m ++ ) { x = snake . blocks_array [ 0 ] . x0 + k ; y = snake . blocks_array [ 0 ] . y0 - m ; bool head_is_outside_screen = check_outside_screen ( x , y ) ; bool head_collided_with_tail = check_tail ( x , y ) ; if ( head_is_outside_screen || head_collided_with_tail ) { game_over ( ) ; } } } }
checks if the head of the snake has collided with anything, such as an apple, the wall or its own tail
checks if the head of the snake has collided with anything such as an apple the wall or its own tail
//helper that returns whether or not the pixel we are checking is outside the screen /*helper that returns whether or not we collided with our tail*/ //iterate through each block and see if x0,y0 are the same as those of the head - in that case we collided /*returns whether or not the head is on an apple*/